Commit: ebff39d5bb3697a767eb3f6c662e29cef326e2ae Author: Brecht Van Lommel Date: Mon Dec 5 23:05:25 2022 +0100 Branches: master https://developer.blender.org/rBebff39d5bb3697a767eb3f6c662e29cef326e2ae
Build: make running executables as part of build/tests work with shared libs Ensure the environment is set up for blender_test, idiff and oslc so that they can find the required shared libraries. Also deduplicate add_bundled_libraries() between Linux and macOS. Includes contributions by Ray Molenkamp and Brecht Van Lommel. Ref T99618 =================================================================== M build_files/cmake/Modules/GTestTesting.cmake M build_files/cmake/macros.cmake M build_files/cmake/platform/platform_apple.cmake M build_files/cmake/platform/platform_unix.cmake M build_files/cmake/platform/platform_win32.cmake M intern/cycles/kernel/osl/shaders/CMakeLists.txt M tests/python/CMakeLists.txt =================================================================== diff --git a/build_files/cmake/Modules/GTestTesting.cmake b/build_files/cmake/Modules/GTestTesting.cmake index 5ffd158361e..d6f5b2a5cd6 100644 --- a/build_files/cmake/Modules/GTestTesting.cmake +++ b/build_files/cmake/Modules/GTestTesting.cmake @@ -95,6 +95,9 @@ macro(BLENDER_SRC_GTEST_EX) set_tests_properties(${TARGET_NAME} PROPERTIES ENVIRONMENT LSAN_OPTIONS=exitcode=0:$ENV{LSAN_OPTIONS} ) + if(WIN32) + set_tests_properties(${TARGET_NAME} PROPERTIES ENVIRONMENT "PATH=${CMAKE_INSTALL_PREFIX_WITH_CONFIG}/blender.shared/;$ENV{PATH}") + endif() endif() if(WIN32) set_target_properties(${TARGET_NAME} PROPERTIES VS_GLOBAL_VcpkgEnabled "false") diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index 824c587c86e..eadf9273e26 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -422,7 +422,9 @@ function(blender_add_test_suite) --test-assets-dir "${CMAKE_SOURCE_DIR}/../lib/tests" --test-release-dir "${_test_release_dir}" ) - + if(WIN32) + set_tests_properties(${ARGS_SUITE_NAME} PROPERTIES ENVIRONMENT "PATH=${CMAKE_INSTALL_PREFIX_WITH_CONFIG}/blender.shared/;$ENV{PATH}") + endif() unset(_test_release_dir) endfunction() @@ -1257,3 +1259,21 @@ endmacro() macro(without_system_libs_end) unset(CMAKE_IGNORE_PATH) endmacro() + +# Utility to gather and install precompiled shared libraries. +macro(add_bundled_libraries library_dir) + if(EXISTS ${LIBDIR}) + set(_library_dir ${LIBDIR}/${library_dir}) + if(WIN32) + file(GLOB _all_library_versions ${_library_dir}/*\.dll) + elseif(APPLE) + file(GLOB _all_library_versions ${_library_dir}/*\.dylib*) + else() + file(GLOB _all_library_versions ${_library_dir}/*\.so*) + endif() + list(APPEND PLATFORM_BUNDLED_LIBRARIES ${_all_library_versions}) + list(APPEND PLATFORM_BUNDLED_LIBRARY_DIRS ${_library_dir}) + unset(_all_library_versions) + unset(_library_dir) + endif() +endmacro() diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake index 31171d083c1..cc13749a5ad 100644 --- a/build_files/cmake/platform/platform_apple.cmake +++ b/build_files/cmake/platform/platform_apple.cmake @@ -21,18 +21,6 @@ function(print_found_status endif() endfunction() -# Utility to install precompiled shared libraries. -macro(add_bundled_libraries library) - if(EXISTS ${LIBDIR}) - set(_library_dir ${LIBDIR}/${library}/lib) - file(GLOB _all_library_versions ${_library_dir}/*\.dylib*) - list(APPEND PLATFORM_BUNDLED_LIBRARIES ${_all_library_versions}) - list(APPEND PLATFORM_BUNDLED_LIBRARY_DIRS ${_library_dir}) - unset(_all_library_versions) - unset(_library_dir) - endif() -endmacro() - # ------------------------------------------------------------------------ # Find system provided libraries. @@ -364,7 +352,7 @@ if(WITH_OPENMP) set(OpenMP_LIBRARY_DIR "${LIBDIR}/openmp/lib/") set(OpenMP_LINKER_FLAGS "-L'${OpenMP_LIBRARY_DIR}' -lomp") set(OpenMP_LIBRARY "${OpenMP_LIBRARY_DIR}/libomp.dylib") - add_bundled_libraries(openmp) + add_bundled_libraries(openmp/lib) endif() endif() @@ -480,6 +468,12 @@ if(PLATFORM_BUNDLED_LIBRARIES) # different. set(CMAKE_SKIP_BUILD_RPATH FALSE) list(APPEND CMAKE_BUILD_RPATH ${PLATFORM_BUNDLED_LIBRARY_DIRS}) + + # Environment variables to run precompiled executables that needed libraries. + list(JOIN PLATFORM_BUNDLED_LIBRARY_DIRS ":" _library_paths) + set(PLATFORM_ENV_BUILD "DYLD_LIBRARY_PATH=\"${_library_paths};${DYLD_LIBRARY_PATH}\"") + set(PLATFORM_ENV_INSTALL "DYLD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX_WITH_CONFIG}Blender.app/Contents/Resources/lib/;$DYLD_LIBRARY_PATH") + unset(_library_paths) endif() # Same as `CFBundleIdentifier` in Info.plist. diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake index 6f23b55d78d..d27d3e04dbc 100644 --- a/build_files/cmake/platform/platform_unix.cmake +++ b/build_files/cmake/platform/platform_unix.cmake @@ -83,15 +83,6 @@ macro(find_package_wrapper) endif() endmacro() -# Utility to install precompiled shared libraries. -macro(add_bundled_libraries library) - if(EXISTS ${LIBDIR}) - file(GLOB _all_library_versions ${LIBDIR}/${library}/lib/*\.so*) - list(APPEND PLATFORM_BUNDLED_LIBRARIES ${_all_library_versions}) - unset(_all_library_versions) - endif() -endmacro() - # ---------------------------------------------------------------------------- # Precompiled Libraries # @@ -1005,4 +996,10 @@ if(PLATFORM_BUNDLED_LIBRARIES) # and because the build and install folder may be different. set(CMAKE_SKIP_BUILD_RPATH FALSE) list(APPEND CMAKE_BUILD_RPATH $ORIGIN/lib ${CMAKE_INSTALL_PREFIX_WITH_CONFIG}/lib) + + # Environment variables to run precompiled executables that needed libraries. + list(JOIN PLATFORM_BUNDLED_LIBRARY_DIRS ":" _library_paths) + set(PLATFORM_ENV_BUILD "LD_LIBRARY_PATH=\"${_library_paths};${LD_LIBRARY_PATH}\"") + set(PLATFORM_ENV_INSTALL "LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX_WITH_CONFIG}/lib/;$LD_LIBRARY_PATH") + unset(_library_paths) endif() diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake index 9bad8045946..28685671c33 100644 --- a/build_files/cmake/platform/platform_win32.cmake +++ b/build_files/cmake/platform/platform_win32.cmake @@ -982,3 +982,12 @@ if(WITH_CYCLES AND WITH_CYCLES_DEVICE_ONEAPI) list(APPEND PLATFORM_BUNDLED_LIBRARIES ${_sycl_runtime_libraries}) unset(_sycl_runtime_libraries) endif() + + +# Environment variables to run precompiled executables that needed libraries. +list(JOIN PLATFORM_BUNDLED_LIBRARY_DIRS ";" _library_paths) +set(PLATFORM_ENV_BUILD_DIRS "${LIBDIR}/OpenImageIO/bin\;${LIBDIR}/boost/lib\;${LIBDIR}/openexr/bin\;${LIBDIR}/imath/bin\;${PATH}") +set(PLATFORM_ENV_BUILD "PATH=${PLATFORM_ENV_BUILD_DIRS}") +# Install needs the additional folders from PLATFORM_ENV_BUILD_DIRS as well, as tools like idiff and abcls use the release mode dlls +set(PLATFORM_ENV_INSTALL "PATH=${CMAKE_INSTALL_PREFIX_WITH_CONFIG}/blender.shared/\;${PLATFORM_ENV_BUILD_DIRS}\;$ENV{PATH}") +unset(_library_paths) diff --git a/intern/cycles/kernel/osl/shaders/CMakeLists.txt b/intern/cycles/kernel/osl/shaders/CMakeLists.txt index c79af3f6112..bfd203416cb 100644 --- a/intern/cycles/kernel/osl/shaders/CMakeLists.txt +++ b/intern/cycles/kernel/osl/shaders/CMakeLists.txt @@ -135,8 +135,9 @@ foreach(_file ${SRC_OSL}) string(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} _OSO_FILE ${_OSO_FILE}) add_custom_command( OUTPUT ${_OSO_FILE} - COMMAND ${OSL_COMPILER} -q -O2 -I"${CMAKE_CURRENT_SOURCE_DIR}" -I"${OSL_SHADER_DIR}" -o ${_OSO_FILE} ${_OSL_FILE} - DEPENDS ${_OSL_FILE} ${SRC_OSL_HEADERS} ${OSL_COMPILER}) + COMMAND ${CMAKE_COMMAND} -E env ${PLATFORM_ENV_BUILD} ${OSL_COMPILER} -q -O2 -I"${CMAKE_CURRENT_SOURCE_DIR}" -I"${OSL_SHADER_DIR}" -o ${_OSO_FILE} ${_OSL_FILE} + DEPENDS ${_OSL_FILE} ${SRC_OSL_HEADERS} ${OSL_COMPILER} + ) list(APPEND SRC_OSO ${_OSO_FILE} ) diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt index 90ea5d57065..e4916bb3ff5 100644 --- a/tests/python/CMakeLists.txt +++ b/tests/python/CMakeLists.txt @@ -31,6 +31,9 @@ function(add_blender_test testname) set_tests_properties(${testname} PROPERTIES ENVIRONMENT LSAN_OPTIONS=exitcode=0:$ENV{LSAN_OPTIONS} ) + if(PLATFORM_ENV_INSTALL) + set_tests_properties(${testname} PROPERTIES ENVIRONMENT "${PLATFORM_ENV_INSTALL}") + endif() endfunction() # Run Python script outside Blender. @@ -42,10 +45,14 @@ function(add_python_test testname testscript) add_test( NAME ${testname} COMMAND ${TEST_PYTHON_EXE} ${TEST_PYTHON_EXE_EXTRA_ARGS} ${testscript} ${ARGN} + WORKING_DIRECTORY $<TARGET_FILE_DIR:blender> ) set_tests_properties(${testname} PROPERTIES ENVIRONMENT LSAN_OPTIONS=exitcode=0:$ENV{LSAN_OPTIONS} ) + if(PLATFORM_ENV_INSTALL) + set_tests_properties(${testname} PROPERTIES ENVIRONMENT "${PLATFORM_ENV_INSTALL}") + endif() endfunction() # ------------------------------------------------------------------------------ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs