diff options
author | Brecht Van Lommel <brecht@blender.org> | 2022-04-19 19:09:05 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-04-20 17:42:16 +0300 |
commit | 604c33e694375828b0f322010e8e4ac17b4b02f3 (patch) | |
tree | d3a362fd590e8c27a34dc58ad729bc93300969d1 /build_files/cmake/platform | |
parent | b9c37608a9e959a896f5358d4ab3d3d001a70833 (diff) |
Build: updates for Blender to build against new 3.2 libraries
Building against the existing 3.1 libraries should continue to work, until
the precompiled libraries are committed for all platforms.
* Enable WebP by default.
* Update Windows for new library file names.
* Automatically clear outdated CMake cache variables when upgrading to new
libraries.
* Fix static library linking order issues on Linux for OpenEXR and OpenVDB.
Implemented by Ray Molenkamp, Sybren Stüvel and Brecht Van Lommel.
Ref T95206
Diffstat (limited to 'build_files/cmake/platform')
-rw-r--r-- | build_files/cmake/platform/platform_apple.cmake | 1 | ||||
-rw-r--r-- | build_files/cmake/platform/platform_old_libs_update.cmake | 37 | ||||
-rw-r--r-- | build_files/cmake/platform/platform_unix.cmake | 7 | ||||
-rw-r--r-- | build_files/cmake/platform/platform_win32.cmake | 130 |
4 files changed, 142 insertions, 33 deletions
diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake index cdc9aa91a53..91d0b54e426 100644 --- a/build_files/cmake/platform/platform_apple.cmake +++ b/build_files/cmake/platform/platform_apple.cmake @@ -71,6 +71,7 @@ set(CMAKE_PREFIX_PATH ${LIB_SUBDIRS}) # Find precompiled libraries, and avoid system or user-installed ones. if(EXISTS ${LIBDIR}) + include(platform_old_libs_update) without_system_libs_begin() endif() diff --git a/build_files/cmake/platform/platform_old_libs_update.cmake b/build_files/cmake/platform/platform_old_libs_update.cmake new file mode 100644 index 00000000000..014aa198caf --- /dev/null +++ b/build_files/cmake/platform/platform_old_libs_update.cmake @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright 2022 Blender Foundation. All rights reserved. + +# Auto update existing CMake caches for new libraries + +function(unset_cache_variables pattern) + get_cmake_property(_cache_variables CACHE_VARIABLES) + foreach (_cache_variable ${_cache_variables}) + if("${_cache_variable}" MATCHES "${pattern}") + unset(${_cache_variable} CACHE) + endif() + endforeach() +endfunction() + +# Detect update from 3.1 to 3.2 libs. +if(UNIX AND + DEFINED OPENEXR_VERSION AND + OPENEXR_VERSION VERSION_LESS "3.0.0" AND + EXISTS ${LIBDIR}/imath) + message(STATUS "Auto updating CMake configuration for Blender 3.2 libraries") + + unset_cache_variables("^OPENIMAGEIO") + unset_cache_variables("^OPENEXR") + unset_cache_variables("^IMATH") + unset_cache_variables("^PNG") + unset_cache_variables("^USD") + unset_cache_variables("^WEBP") +endif() + +# Automatically set WebP on/off depending if libraries are available. +if(EXISTS ${LIBDIR}/webp) + if(WITH_OPENIMAGEIO) + set(WITH_IMAGE_WEBP ON CACHE BOOL "" FORCE) + endif() +else() + set(WITH_IMAGE_WEBP OFF) +endif() diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake index cc168476d5d..6750c23d548 100644 --- a/build_files/cmake/platform/platform_unix.cmake +++ b/build_files/cmake/platform/platform_unix.cmake @@ -45,6 +45,9 @@ if(EXISTS ${LIBDIR}) # which is a part of OpenCollada. They have different ABI, and we # do need to use the official one. set(CMAKE_PREFIX_PATH ${LIBDIR}/zlib ${LIB_SUBDIRS}) + + include(platform_old_libs_update) + set(WITH_STATIC_LIBS ON) # OpenMP usually can't be statically linked into shared libraries, # due to not being compiled with position independent code. @@ -373,6 +376,7 @@ if(WITH_IMAGE_WEBP) find_package_wrapper(WebP) if(NOT WEBP_FOUND) set(WITH_IMAGE_WEBP OFF) + message(WARNING "WebP not found, disabling WITH_IMAGE_WEBP") endif() endif() @@ -394,6 +398,9 @@ if(WITH_OPENIMAGEIO) if(WITH_IMAGE_OPENEXR) list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}") endif() + if(WITH_IMAGE_WEBP) + list(APPEND OPENIMAGEIO_LIBRARIES "${WEBP_LIBRARIES}") + endif() if(NOT OPENIMAGEIO_FOUND) set(WITH_OPENIMAGEIO OFF) diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake index b0dbc0d3264..c5d2049b292 100644 --- a/build_files/cmake/platform/platform_win32.cmake +++ b/build_files/cmake/platform/platform_win32.cmake @@ -262,6 +262,8 @@ if(NOT EXISTS "${LIBDIR}/") message(FATAL_ERROR "\n\nWindows requires pre-compiled libs at: '${LIBDIR}'. Please run `make update` in the blender source folder to obtain them.") endif() +include(platform_old_libs_update) + if(CMAKE_GENERATOR MATCHES "^Visual Studio.+" AND # Only supported in the VS IDE MSVC_VERSION GREATER_EQUAL 1924 AND # Supported for 16.4+ WITH_CLANG_TIDY # And Clang Tidy needs to be on @@ -343,13 +345,18 @@ if(WITH_FFTW3) set(FFTW3_LIBPATH ${FFTW3}/lib) endif() -windows_find_package(WebP) -if(NOT WEBP_FOUND) - if(EXISTS ${LIBDIR}/webp) - set(WEBP_INCLUDE_DIRS ${LIBDIR}/webp/include) - set(WEBP_ROOT_DIR ${LIBDIR}/webp) - set(WEBP_LIBRARIES ${LIBDIR}/webp/lib/webp.lib ${LIBDIR}/webp/lib/webpdemux.lib ${LIBDIR}/webp/lib/webpmux.lib) - set(WEBP_FOUND ON) +if(WITH_IMAGE_WEBP) + windows_find_package(WebP) + if(NOT WEBP_FOUND) + if(EXISTS ${LIBDIR}/webp) + set(WEBP_INCLUDE_DIRS ${LIBDIR}/webp/include) + set(WEBP_ROOT_DIR ${LIBDIR}/webp) + set(WEBP_LIBRARIES ${LIBDIR}/webp/lib/webp.lib ${LIBDIR}/webp/lib/webpdemux.lib ${LIBDIR}/webp/lib/webpmux.lib) + set(WEBP_FOUND ON) + else() + message(STATUS "WITH_IMAGE_WEBP is ON but WEBP libraries are not found, setting WITH_IMAGE_WEBP=OFF") + set(WITH_IMAGE_WEBP OFF) + endif() endif() endif() @@ -414,27 +421,60 @@ if(WITH_CODEC_FFMPEG) endif() if(WITH_IMAGE_OPENEXR) - windows_find_package(OpenEXR REQUIRED) + # Imath and OpenEXR have a single combined build option and include and library variables + # used by the rest of the build system. + set(IMATH_ROOT_DIR ${LIBDIR}/imath) + set(IMATH_VERSION "3.14") + windows_find_package(IMATH REQUIRED) + if(NOT IMATH_FOUND) + set(IMATH ${LIBDIR}/imath) + set(IMATH_INCLUDE_DIR ${IMATH}/include) + set(IMATH_INCLUDE_DIRS ${IMATH_INCLUDE_DIR} ${IMATH}/include/Imath) + set(IMATH_LIBPATH ${IMATH}/lib) + set(IMATH_LIBRARIES + optimized ${IMATH_LIBPATH}/Imath_s.lib + debug ${IMATH_LIBPATH}/Imath_s_d.lib + ) + endif() + set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr) + set(OPENEXR_VERSION "3.14") + windows_find_package(OPENEXR REQUIRED) if(NOT OpenEXR_FOUND) - set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr) - set(OPENEXR_VERSION "2.1") warn_hardcoded_paths(OpenEXR) set(OPENEXR ${LIBDIR}/openexr) set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include) - set(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR}/include/OpenEXR) + set(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${IMATH_INCLUDE_DIRS} ${OPENEXR}/include/OpenEXR) set(OPENEXR_LIBPATH ${OPENEXR}/lib) - set(OPENEXR_LIBRARIES - optimized ${OPENEXR_LIBPATH}/Iex_s.lib - optimized ${OPENEXR_LIBPATH}/Half_s.lib - optimized ${OPENEXR_LIBPATH}/IlmImf_s.lib - optimized ${OPENEXR_LIBPATH}/Imath_s.lib - optimized ${OPENEXR_LIBPATH}/IlmThread_s.lib - debug ${OPENEXR_LIBPATH}/Iex_s_d.lib - debug ${OPENEXR_LIBPATH}/Half_s_d.lib - debug ${OPENEXR_LIBPATH}/IlmImf_s_d.lib - debug ${OPENEXR_LIBPATH}/Imath_s_d.lib - debug ${OPENEXR_LIBPATH}/IlmThread_s_d.lib - ) + # Check if the 3.x library name exists + # if not assume this is a 2.x library folder + if(EXISTS "${OPENEXR_LIBPATH}/OpenEXR_s.lib") + set(OPENEXR_LIBRARIES + optimized ${OPENEXR_LIBPATH}/Iex_s.lib + optimized ${OPENEXR_LIBPATH}/IlmThread_s.lib + optimized ${OPENEXR_LIBPATH}/OpenEXR_s.lib + optimized ${OPENEXR_LIBPATH}/OpenEXRCore_s.lib + optimized ${OPENEXR_LIBPATH}/OpenEXRUtil_s.lib + debug ${OPENEXR_LIBPATH}/Iex_s_d.lib + debug ${OPENEXR_LIBPATH}/IlmThread_s_d.lib + debug ${OPENEXR_LIBPATH}/OpenEXR_s_d.lib + debug ${OPENEXR_LIBPATH}/OpenEXRCore_s_d.lib + debug ${OPENEXR_LIBPATH}/OpenEXRUtil_s_d.lib + ${IMATH_LIBRARIES} + ) + else() + set(OPENEXR_LIBRARIES + optimized ${OPENEXR_LIBPATH}/Iex_s.lib + optimized ${OPENEXR_LIBPATH}/Half_s.lib + optimized ${OPENEXR_LIBPATH}/IlmImf_s.lib + optimized ${OPENEXR_LIBPATH}/Imath_s.lib + optimized ${OPENEXR_LIBPATH}/IlmThread_s.lib + debug ${OPENEXR_LIBPATH}/Iex_s_d.lib + debug ${OPENEXR_LIBPATH}/Half_s_d.lib + debug ${OPENEXR_LIBPATH}/IlmImf_s_d.lib + debug ${OPENEXR_LIBPATH}/Imath_s_d.lib + debug ${OPENEXR_LIBPATH}/IlmThread_s_d.lib + ) + endif() endif() endif() @@ -500,8 +540,14 @@ if(WITH_BOOST) if(NOT BOOST_VERSION) message(FATAL_ERROR "Unable to determine Boost version") endif() - set(BOOST_POSTFIX "vc141-mt-x64-${BOOST_VERSION}.lib") - set(BOOST_DEBUG_POSTFIX "vc141-mt-gd-x64-${BOOST_VERSION}.lib") + set(BOOST_POSTFIX "vc142-mt-x64-${BOOST_VERSION}.lib") + set(BOOST_DEBUG_POSTFIX "vc142-mt-gd-x64-${BOOST_VERSION}.lib") + if(NOT EXISTS ${BOOST_LIBPATH}/libboost_date_time-${BOOST_POSTFIX}) + # If the new library names do not exist fall back to the old ones + # to ease the transition period between the libs. + set(BOOST_POSTFIX "vc141-mt-x64-${BOOST_VERSION}.lib") + set(BOOST_DEBUG_POSTFIX "vc141-mt-gd-x64-${BOOST_VERSION}.lib") + endif() set(BOOST_LIBRARIES optimized ${BOOST_LIBPATH}/libboost_date_time-${BOOST_POSTFIX} optimized ${BOOST_LIBPATH}/libboost_filesystem-${BOOST_POSTFIX} @@ -545,7 +591,6 @@ if(WITH_OPENIMAGEIO) set(OIIO_DEBUG debug ${OPENIMAGEIO_LIBPATH}/OpenImageIO_d.lib debug ${OPENIMAGEIO_LIBPATH}/OpenImageIO_Util_d.lib) set(OPENIMAGEIO_LIBRARIES ${OIIO_OPTIMIZED} ${OIIO_DEBUG}) endif() - set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0") set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe") add_definitions(-DOIIO_STATIC_DEFINE) @@ -575,6 +620,7 @@ if(WITH_LLVM) message(WARNING "LLVM debug libs not present on this system. Using release libs for debug builds.") set(LLVM_LIBRARY ${LLVM_LIBRARY_OPTIMIZED}) endif() + endif() if(WITH_OPENCOLORIO) @@ -594,7 +640,6 @@ if(WITH_OPENCOLORIO) debug ${OPENCOLORIO_LIBPATH}/pystring_d.lib ) endif() - set(OPENCOLORIO_DEFINITIONS "-DOpenColorIO_SKIP_IMPORTS") endif() @@ -604,17 +649,24 @@ if(WITH_OPENVDB) set(OPENVDB ${LIBDIR}/openVDB) set(OPENVDB_LIBPATH ${OPENVDB}/lib) set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include) - set(OPENVDB_LIBRARIES optimized ${OPENVDB_LIBPATH}/openvdb.lib debug ${OPENVDB_LIBPATH}/openvdb_d.lib) + set(OPENVDB_LIBRARIES optimized ${OPENVDB_LIBPATH}/openvdb.lib debug ${OPENVDB_LIBPATH}/openvdb_d.lib ) endif() - set(OPENVDB_DEFINITIONS -DNOMINMAX -D_USE_MATH_DEFINES) endif() if(WITH_NANOVDB) - set(NANOVDB ${LIBDIR}/nanoVDB) + set(NANOVDB ${LIBDIR}/openvdb) set(NANOVDB_INCLUDE_DIR ${NANOVDB}/include) + if(NOT EXISTS "${NANOVDB_INCLUDE_DIR}/nanovdb") + # When not found, could be an older lib folder with where nanovdb + # had its own lib folder, to ease the transition period, fall back + # to that copy if the copy in openvdb is not found. + set(NANOVDB ${LIBDIR}/nanoVDB) + set(NANOVDB_INCLUDE_DIR ${NANOVDB}/include) + endif() endif() + if(WITH_OPENIMAGEDENOISE) set(OPENIMAGEDENOISE ${LIBDIR}/OpenImageDenoise) set(OPENIMAGEDENOISE_LIBPATH ${LIBDIR}/OpenImageDenoise/lib) @@ -640,7 +692,12 @@ endif() if(WITH_IMAGE_OPENJPEG) set(OPENJPEG ${LIBDIR}/openjpeg) - set(OPENJPEG_INCLUDE_DIRS ${OPENJPEG}/include/openjpeg-2.3) + set(OPENJPEG_INCLUDE_DIRS ${OPENJPEG}/include/openjpeg-2.4) + if(NOT EXISTS "${OPENJPEG_INCLUDE_DIRS}") + # when not found, could be an older lib folder with openjpeg 2.3 + # to ease the transition period, fall back if 2.4 is not found. + set(OPENJPEG_INCLUDE_DIRS ${OPENJPEG}/include/openjpeg-2.3) + endif() set(OPENJPEG_LIBRARIES ${OPENJPEG}/lib/openjp2.lib) endif() @@ -783,9 +840,16 @@ if(WITH_USD) windows_find_package(USD) if(NOT USD_FOUND) set(USD_INCLUDE_DIRS ${LIBDIR}/usd/include) - set(USD_RELEASE_LIB ${LIBDIR}/usd/lib/libusd_m.lib) - set(USD_DEBUG_LIB ${LIBDIR}/usd/lib/libusd_m_d.lib) + set(USD_RELEASE_LIB ${LIBDIR}/usd/lib/usd_usd_m.lib) + set(USD_DEBUG_LIB ${LIBDIR}/usd/lib/usd_usd_m_d.lib) set(USD_LIBRARY_DIR ${LIBDIR}/usd/lib) + # Older USD had different filenames, if the new ones are + # not found see if the older ones exist, to ease the + # transition period while landing libs. + if(NOT EXISTS "${USD_RELEASE_LIB}") + set(USD_RELEASE_LIB ${LIBDIR}/usd/lib/libusd_m.lib) + set(USD_DEBUG_LIB ${LIBDIR}/usd/lib/libusd_m_d.lib) + endif() set(USD_LIBRARIES debug ${USD_DEBUG_LIB} optimized ${USD_RELEASE_LIB} |