Changeset View
Changeset View
Standalone View
Standalone View
build_files/cmake/macros.cmake
| Show First 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | function(target_link_libraries_debug | ||||
| LIBS | LIBS | ||||
| ) | ) | ||||
| foreach(_LIB ${LIBS}) | foreach(_LIB ${LIBS}) | ||||
| target_link_libraries(${TARGET} INTERFACE debug "${_LIB}") | target_link_libraries(${TARGET} INTERFACE debug "${_LIB}") | ||||
| endforeach() | endforeach() | ||||
| endfunction() | endfunction() | ||||
| function(blender_target_include_dirs_impl | |||||
| target | |||||
| system | |||||
| includes | |||||
| ) | |||||
| set(next_interface_mode "PRIVATE") | |||||
| foreach(_INC ${includes}) | |||||
| if(("${_INC}" STREQUAL "PUBLIC") OR | |||||
| ("${_INC}" STREQUAL "PRIVATE") OR | |||||
| ("${_INC}" STREQUAL "INTERFACE")) | |||||
| set(next_interface_mode "${_INC}") | |||||
| else() | |||||
| get_filename_component(_ABS_INC ${_INC} ABSOLUTE) | |||||
| if(system) | |||||
| target_include_directories(${target} SYSTEM ${next_interface_mode} ${_ABS_INC}) | |||||
| else() | |||||
| target_include_directories(${target} ${next_interface_mode} ${_ABS_INC}) | |||||
| endif() | |||||
| # for checking for invalid includes, disable for regular use | |||||
| #if(NOT EXISTS "${_ABS_INC}/") | |||||
| # message(FATAL_ERROR "Include not found: ${_ABS_INC}/") | |||||
| #endif() | |||||
| set(next_interface_mode "PRIVATE") | |||||
| endif() | |||||
| endforeach() | |||||
| endfunction() | |||||
| # Nicer makefiles with -I/1/foo/ instead of -I/1/2/3/../../foo/ | |||||
| # use it instead of target_include_directories() | |||||
| function(blender_target_include_dirs | |||||
| target | |||||
| includes | |||||
| ) | |||||
| blender_target_include_dirs_impl(${target} FALSE "${includes}") | |||||
| endfunction() | |||||
| function(blender_target_sys_include_dirs | |||||
| target | |||||
| includes | |||||
| ) | |||||
| blender_target_include_dirs_impl(${target} TRUE "${includes}") | |||||
| endfunction() | |||||
| # Nicer makefiles with -I/1/foo/ instead of -I/1/2/3/../../foo/ | # Nicer makefiles with -I/1/foo/ instead of -I/1/2/3/../../foo/ | ||||
| # use it instead of include_directories() | # use it instead of include_directories() | ||||
| function(blender_include_dirs | function(blender_include_dirs | ||||
| includes | includes | ||||
| ) | ) | ||||
| set(_ALL_INCS "") | set(_ALL_INCS "") | ||||
| foreach(_INC ${ARGV}) | foreach(_INC ${ARGV}) | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | if(DEFINED CMAKE_CXX_FLAGS_${_name_upper}) | ||||
| message(STATUS "Using custom CXXFLAGS: CMAKE_CXX_FLAGS_${_name_upper} in \"${CMAKE_CURRENT_SOURCE_DIR}\"") | message(STATUS "Using custom CXXFLAGS: CMAKE_CXX_FLAGS_${_name_upper} in \"${CMAKE_CURRENT_SOURCE_DIR}\"") | ||||
| string(APPEND CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS_${_name_upper}}" ${ARGV1}) | string(APPEND CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS_${_name_upper}}" ${ARGV1}) | ||||
| endif() | endif() | ||||
| unset(_name_upper) | unset(_name_upper) | ||||
| endmacro() | endmacro() | ||||
| # only MSVC uses SOURCE_GROUP | function(blender_link_libraries | ||||
| function(blender_add_lib__impl | target | ||||
| name | |||||
| sources | |||||
| includes | |||||
| includes_sys | |||||
| library_deps | library_deps | ||||
| ) | ) | ||||
| # 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}) | |||||
| # On Windows certain libraries have two sets of binaries: one for debug builds and one for | # 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 | # release builds. The root of this requirement goes into ABI, I believe, but that's outside | ||||
| # of a scope of this comment. | # of a scope of this comment. | ||||
| # | # | ||||
| # CMake have a native way of dealing with this, which is specifying what build type the | # CMake have a native way of dealing with this, which is specifying what build type the | ||||
| # libraries are provided for: | # libraries are provided for: | ||||
| # | # | ||||
| # target_link_libraries(tagret optimized|debug|general <libraries>) | # target_link_libraries(tagret optimized|debug|general <libraries>) | ||||
| Show All 21 Lines | ) | ||||
| # | # | ||||
| # NOTE: If separated libraries for debug and release are needed every library is the list are | # NOTE: If separated libraries for debug and release are needed every library is the list are | ||||
| # to be prefixed explicitly. | # to be prefixed explicitly. | ||||
| # | # | ||||
| # Use: "optimized libfoo optimized libbar debug libfoo_d debug libbar_d" | # Use: "optimized libfoo optimized libbar debug libfoo_d debug libbar_d" | ||||
| # NOT: "optimized libfoo libbar debug libfoo_d libbar_d" | # NOT: "optimized libfoo libbar debug libfoo_d libbar_d" | ||||
| if(NOT "${library_deps}" STREQUAL "") | if(NOT "${library_deps}" STREQUAL "") | ||||
| set(next_library_mode "") | set(next_library_mode "") | ||||
| set(next_interface_mode "PRIVATE") | |||||
| foreach(library ${library_deps}) | foreach(library ${library_deps}) | ||||
| string(TOLOWER "${library}" library_lower) | string(TOLOWER "${library}" library_lower) | ||||
| if(("${library_lower}" STREQUAL "optimized") OR | if(("${library_lower}" STREQUAL "optimized") OR | ||||
| ("${library_lower}" STREQUAL "debug")) | ("${library_lower}" STREQUAL "debug")) | ||||
| set(next_library_mode "${library_lower}") | set(next_library_mode "${library_lower}") | ||||
| elseif(("${library}" STREQUAL "PUBLIC") OR | |||||
| ("${library}" STREQUAL "PRIVATE") OR | |||||
| ("${library}" STREQUAL "INTERFACE")) | |||||
| set(next_interface_mode "${library}") | |||||
| else() | else() | ||||
| if("${next_library_mode}" STREQUAL "optimized") | if("${next_library_mode}" STREQUAL "optimized") | ||||
| target_link_libraries(${name} INTERFACE optimized ${library}) | target_link_libraries(${target} ${next_interface_mode} optimized ${library}) | ||||
| elseif("${next_library_mode}" STREQUAL "debug") | elseif("${next_library_mode}" STREQUAL "debug") | ||||
| target_link_libraries(${name} INTERFACE debug ${library}) | target_link_libraries(${target} ${next_interface_mode} debug ${library}) | ||||
| else() | else() | ||||
| target_link_libraries(${name} INTERFACE ${library}) | target_link_libraries(${target} ${next_interface_mode} ${library}) | ||||
| endif() | endif() | ||||
| set(next_library_mode "") | set(next_library_mode "") | ||||
| endif() | endif() | ||||
| endforeach() | endforeach() | ||||
| endif() | endif() | ||||
| endfunction() | |||||
| # only MSVC uses SOURCE_GROUP | |||||
| function(blender_add_lib__impl | |||||
| name | |||||
| sources | |||||
| includes | |||||
| includes_sys | |||||
| library_deps | |||||
| ) | |||||
| # message(STATUS "Configuring library ${name}") | |||||
| add_library(${name} ${sources}) | |||||
| blender_link_libraries("${name}" "${library_deps}") | |||||
| # works fine without having the includes | # works fine without having the includes | ||||
| # listed is helpful for IDE's (QtCreator/MSVC) | # listed is helpful for IDE's (QtCreator/MSVC) | ||||
| blender_source_group("${name}" "${sources}") | blender_source_group("${name}" "${sources}") | ||||
| blender_user_header_search_paths("${name}" "${includes}") | blender_user_header_search_paths("${name}" "${includes}") | ||||
| list_assert_duplicates("${sources}") | list_assert_duplicates("${sources}") | ||||
| list_assert_duplicates("${includes}") | |||||
| blender_target_include_dirs(${name} "${includes}") | |||||
| blender_target_sys_include_dirs(${name} "${includes_sys}") | |||||
| # Not for system includes because they can resolve to the same path | # Not for system includes because they can resolve to the same path | ||||
| # list_assert_duplicates("${includes_sys}") | # list_assert_duplicates("${includes_sys}") | ||||
| endfunction() | endfunction() | ||||
| function(blender_add_lib_nolist | function(blender_add_lib_nolist | ||||
| name | name | ||||
| ▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | |||||
| # Add tests for a Blender library, to be called in tandem with blender_add_lib(). | # Add tests for a Blender library, to be called in tandem with blender_add_lib(). | ||||
| # Test will be compiled into a ${name}_test executable. | # Test will be compiled into a ${name}_test executable. | ||||
| # | # | ||||
| # To be used for smaller isolated libraries, that do not have many dependencies. | # To be used for smaller isolated libraries, that do not have many dependencies. | ||||
| # For libraries that do drag in many other Blender libraries and would create a | # For libraries that do drag in many other Blender libraries and would create a | ||||
| # very large executable, blender_add_test_lib() should be used instead. | # very large executable, blender_add_test_lib() should be used instead. | ||||
| function(blender_add_test_executable | function(blender_add_test_executable_impl | ||||
| name | name | ||||
| add_test_suite | |||||
| sources | sources | ||||
| includes | includes | ||||
| includes_sys | includes_sys | ||||
| library_deps | library_deps | ||||
| ) | ) | ||||
| add_cc_flags_custom_test(${name} PARENT_SCOPE) | add_cc_flags_custom_test(${name} PARENT_SCOPE) | ||||
| ## Otherwise external projects will produce warnings that we cannot fix. | ## Otherwise external projects will produce warnings that we cannot fix. | ||||
| remove_strict_flags() | remove_strict_flags() | ||||
| include_directories(${includes}) | |||||
| include_directories(${includes_sys}) | |||||
| BLENDER_SRC_GTEST_EX( | BLENDER_SRC_GTEST_EX( | ||||
| NAME ${name} | NAME ${name} | ||||
| SRC "${sources}" | SRC "${sources}" | ||||
| EXTRA_LIBS "${library_deps}" | EXTRA_LIBS "${library_deps}" | ||||
| SKIP_ADD_TEST | SKIP_ADD_TEST | ||||
| ) | ) | ||||
| if(add_test_suite) | |||||
| blender_add_test_suite( | blender_add_test_suite( | ||||
| TARGET ${name}_test | TARGET ${name}_test | ||||
| SUITE_NAME ${name} | SUITE_NAME ${name} | ||||
| SOURCES "${sources}" | SOURCES "${sources}" | ||||
| ) | ) | ||||
| endif() | |||||
| blender_target_include_dirs(${name}_test "${includes}") | |||||
| blender_target_sys_include_dirs(${name}_test "${includes_sys}") | |||||
| endfunction() | endfunction() | ||||
| function(blender_add_test_executable | |||||
| name | |||||
| sources | |||||
| includes | |||||
| includes_sys | |||||
| library_deps | |||||
| ) | |||||
| blender_add_test_executable_impl( | |||||
| "${name}" | |||||
| True | |||||
| "${sources}" | |||||
| "${includes}" | |||||
| "${includes_sys}" | |||||
| "${library_deps}" | |||||
| ) | |||||
| endfunction() | |||||
| function(blender_add_performancetest_executable | |||||
| name | |||||
| sources | |||||
| includes | |||||
| includes_sys | |||||
| library_deps | |||||
| ) | |||||
| blender_add_test_executable_impl( | |||||
| "${name}" | |||||
| False | |||||
| "${sources}" | |||||
| "${includes}" | |||||
| "${includes_sys}" | |||||
| "${library_deps}" | |||||
| ) | |||||
| endfunction() | |||||
| # Ninja only: assign 'heavy pool' to some targets that are especially RAM-consuming to build. | # Ninja only: assign 'heavy pool' to some targets that are especially RAM-consuming to build. | ||||
| function(setup_heavy_lib_pool) | function(setup_heavy_lib_pool) | ||||
| if(WITH_NINJA_POOL_JOBS AND NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS) | if(WITH_NINJA_POOL_JOBS AND NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS) | ||||
| if(WITH_CYCLES) | if(WITH_CYCLES) | ||||
| list(APPEND _HEAVY_LIBS "cycles_device" "cycles_kernel") | list(APPEND _HEAVY_LIBS "cycles_device" "cycles_kernel") | ||||
| endif() | endif() | ||||
| if(WITH_LIBMV) | if(WITH_LIBMV) | ||||
| list(APPEND _HEAVY_LIBS "extern_ceres" "bf_intern_libmv") | list(APPEND _HEAVY_LIBS "extern_ceres" "bf_intern_libmv") | ||||
| Show All 19 Lines | |||||
| endfunction() | endfunction() | ||||
| # Platform specific libraries for targets. | # Platform specific libraries for targets. | ||||
| function(setup_platform_linker_libs | function(setup_platform_linker_libs | ||||
| target | target | ||||
| ) | ) | ||||
| # jemalloc must be early in the list, to be before pthread (see T57998) | # jemalloc must be early in the list, to be before pthread (see T57998) | ||||
| if(WITH_MEM_JEMALLOC) | if(WITH_MEM_JEMALLOC) | ||||
| target_link_libraries(${target} ${JEMALLOC_LIBRARIES}) | target_link_libraries(${target} PRIVATE ${JEMALLOC_LIBRARIES}) | ||||
| endif() | endif() | ||||
| if(WIN32 AND NOT UNIX) | if(WIN32 AND NOT UNIX) | ||||
| target_link_libraries(${target} ${PTHREADS_LIBRARIES}) | target_link_libraries(${target} PRIVATE ${PTHREADS_LIBRARIES}) | ||||
| endif() | endif() | ||||
| # target_link_libraries(${target} ${PLATFORM_LINKLIBS} ${CMAKE_DL_LIBS}) | # target_link_libraries(${target} ${PLATFORM_LINKLIBS} ${CMAKE_DL_LIBS}) | ||||
| target_link_libraries(${target} ${PLATFORM_LINKLIBS}) | target_link_libraries(${target} PRIVATE ${PLATFORM_LINKLIBS}) | ||||
| endfunction() | endfunction() | ||||
| macro(TEST_SSE_SUPPORT | macro(TEST_SSE_SUPPORT | ||||
| _sse_flags | _sse_flags | ||||
| _sse2_flags) | _sse2_flags) | ||||
| include(CheckCSourceRuns) | include(CheckCSourceRuns) | ||||
| ▲ Show 20 Lines • Show All 683 Lines • Show Last 20 Lines | |||||