From 0ffd288fab5686f55d68d0d39baf59568f4389e7 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sun, 18 Sep 2022 07:41:13 +0200 Subject: Build: fix gtest build flags affecting actual library Switch to target_ functions to avoid this. --- build_files/cmake/Modules/GTestTesting.cmake | 6 +-- build_files/cmake/macros.cmake | 58 +++++++++++++------------ build_files/cmake/platform/platform_apple.cmake | 7 ++- build_files/cmake/platform/platform_win32.cmake | 2 +- 4 files changed, 37 insertions(+), 36 deletions(-) (limited to 'build_files/cmake') diff --git a/build_files/cmake/Modules/GTestTesting.cmake b/build_files/cmake/Modules/GTestTesting.cmake index 92ce403d5f3..5ffd158361e 100644 --- a/build_files/cmake/Modules/GTestTesting.cmake +++ b/build_files/cmake/Modules/GTestTesting.cmake @@ -40,12 +40,10 @@ macro(BLENDER_SRC_GTEST_EX) set(MANIFEST "${CMAKE_BINARY_DIR}/tests.exe.manifest") endif() - add_definitions(-DBLENDER_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) - add_definitions(${GFLAGS_DEFINES}) - add_definitions(${GLOG_DEFINES}) - add_executable(${TARGET_NAME} ${ARG_SRC} ${MANIFEST}) setup_platform_linker_flags(${TARGET_NAME}) + target_compile_definitions(${TARGET_NAME} PRIVATE ${GFLAGS_DEFINES}) + target_compile_definitions(${TARGET_NAME} PRIVATE ${GLOG_DEFINES}) target_include_directories(${TARGET_NAME} PUBLIC "${TEST_INC}") target_include_directories(${TARGET_NAME} SYSTEM PUBLIC "${TEST_INC_SYS}") target_link_libraries(${TARGET_NAME} ${ARG_EXTRA_LIBS} ${PLATFORM_LINKLIBS}) diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index d271d8f216f..b197cd01bbb 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -134,12 +134,11 @@ endfunction() # Nicer makefiles with -I/1/foo/ instead of -I/1/2/3/../../foo/ # use it instead of include_directories() -function(blender_include_dirs - includes - ) +function(absolute_include_dirs + includes_absolute) set(_ALL_INCS "") - foreach(_INC ${ARGV}) + foreach(_INC ${ARGN}) get_filename_component(_ABS_INC ${_INC} ABSOLUTE) list(APPEND _ALL_INCS ${_ABS_INC}) # for checking for invalid includes, disable for regular use @@ -147,22 +146,24 @@ function(blender_include_dirs # message(FATAL_ERROR "Include not found: ${_ABS_INC}/") # endif() endforeach() - include_directories(${_ALL_INCS}) + + set(${includes_absolute} ${_ALL_INCS} PARENT_SCOPE) endfunction() -function(blender_include_dirs_sys - includes +function(blender_target_include_dirs + name ) - set(_ALL_INCS "") - foreach(_INC ${ARGV}) - get_filename_component(_ABS_INC ${_INC} ABSOLUTE) - list(APPEND _ALL_INCS ${_ABS_INC}) - # if(NOT EXISTS "${_ABS_INC}/") - # message(FATAL_ERROR "Include not found: ${_ABS_INC}/") - # endif() - endforeach() - include_directories(SYSTEM ${_ALL_INCS}) + absolute_include_dirs(_ALL_INCS ${ARGN}) + target_include_directories(${name} PRIVATE ${_ALL_INCS}) +endfunction() + +function(blender_target_include_dirs_sys + name + ) + + absolute_include_dirs(_ALL_INCS ${ARGN}) + target_include_directories(${name} SYSTEM PRIVATE ${_ALL_INCS}) endfunction() # Set include paths for header files included with "*.h" syntax. @@ -268,13 +269,11 @@ function(blender_add_lib__impl # message(STATUS "Configuring library ${name}") - # include_directories(${includes}) - # include_directories(SYSTEM ${includes_sys}) - blender_include_dirs("${includes}") - blender_include_dirs_sys("${includes_sys}") - add_library(${name} ${sources}) + blender_target_include_dirs(${name} ${includes}) + blender_target_include_dirs_sys(${name} ${includes_sys}) + # On Windows certain libraries have two sets of binaries: one for debug builds and one for # release builds. The root of this requirement goes into ABI, I believe, but that's outside # of a scope of this comment. @@ -434,12 +433,12 @@ function(blender_add_test_lib ${CMAKE_SOURCE_DIR}/extern/gtest/include ${CMAKE_SOURCE_DIR}/extern/gmock/include ) - add_definitions(-DBLENDER_GFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}) - add_definitions(${GFLAGS_DEFINES}) - add_definitions(${GLOG_DEFINES}) blender_add_lib__impl(${name} "${sources}" "${includes}" "${includes_sys}" "${library_deps}") + target_compile_definitions(${name} PRIVATE ${GFLAGS_DEFINES}) + target_compile_definitions(${name} PRIVATE ${GLOG_DEFINES}) + set_property(GLOBAL APPEND PROPERTY BLENDER_TEST_LIBS ${name}) blender_add_test_suite( @@ -469,9 +468,6 @@ function(blender_add_test_executable ## Otherwise external projects will produce warnings that we cannot fix. remove_strict_flags() - include_directories(${includes}) - include_directories(${includes_sys}) - BLENDER_SRC_GTEST_EX( NAME ${name} SRC "${sources}" @@ -479,6 +475,9 @@ function(blender_add_test_executable SKIP_ADD_TEST ) + blender_target_include_dirs(${name}_test ${includes}) + blender_target_include_dirs_sys(${name}_test ${includes_sys}) + blender_add_test_suite( TARGET ${name}_test SUITE_NAME ${name} @@ -513,6 +512,11 @@ function(setup_platform_linker_flags set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " ${PLATFORM_LINKFLAGS}") set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " ${PLATFORM_LINKFLAGS_RELEASE}") set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS_DEBUG " ${PLATFORM_LINKFLAGS_DEBUG}") + + get_target_property(target_type ${target} TYPE) + if (target_type STREQUAL "EXECUTABLE") + set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " ${PLATFORM_LINKFLAGS_EXECUTABLE}") + endif() endfunction() # Platform specific libraries for targets. diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake index f2a8bd42a3e..27fcaf823e8 100644 --- a/build_files/cmake/platform/platform_apple.cmake +++ b/build_files/cmake/platform/platform_apple.cmake @@ -352,10 +352,6 @@ endif() if(WITH_CYCLES AND WITH_CYCLES_EMBREE) find_package(Embree 3.8.0 REQUIRED) - # Increase stack size for Embree, only works for executables. - if(NOT WITH_PYTHON_MODULE) - string(APPEND PLATFORM_LINKFLAGS " -Wl,-stack_size,0x100000") - endif() # Embree static library linking can mix up SSE and AVX symbols, causing # crashes on macOS systems with older CPUs that don't have AVX. Using @@ -475,6 +471,9 @@ string(APPEND PLATFORM_LINKFLAGS string(APPEND CMAKE_CXX_FLAGS " -stdlib=libc++") string(APPEND PLATFORM_LINKFLAGS " -stdlib=libc++") +# Make stack size more similar to Embree, required for Embree. +string(APPEND PLATFORM_LINKFLAGS_EXECUTABLE " -Wl,-stack_size,0x100000") + # Suppress ranlib "has no symbols" warnings (workaround for T48250) set(CMAKE_C_ARCHIVE_CREATE " Scr ") set(CMAKE_CXX_ARCHIVE_CREATE " Scr ") diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake index dd5d04d7c92..7d7efb83b8e 100644 --- a/build_files/cmake/platform/platform_win32.cmake +++ b/build_files/cmake/platform/platform_win32.cmake @@ -767,7 +767,7 @@ if(WITH_TBB) endif() # used in many places so include globally, like OpenGL -blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}") +include_directories(SYSTEM "${PTHREADS_INCLUDE_DIRS}") set(WINTAB_INC ${LIBDIR}/wintab/include) -- cgit v1.2.3