Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'build_files/cmake/macros.cmake')
-rw-r--r--build_files/cmake/macros.cmake121
1 files changed, 84 insertions, 37 deletions
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index dcab6d58870..202b44f611c 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -60,6 +60,19 @@ function(list_assert_duplicates
unset(_len_after)
endfunction()
+# Adds a native path separator to the end of the path:
+#
+# - 'example' -> 'example/'
+# - '/example///' -> '/example/'
+#
+macro(path_ensure_trailing_slash
+ path_new path_input
+ )
+ file(TO_NATIVE_PATH "/" _path_sep)
+ string(REGEX REPLACE "[${_path_sep}]+$" "" ${path_new} ${path_input})
+ set(${path_new} "${${path_new}}${_path_sep}")
+ unset(_path_sep)
+endmacro()
# foo_bar.spam --> foo_barMySuffix.spam
macro(file_suffix
@@ -183,7 +196,7 @@ function(blender_user_header_search_paths
foreach(_INC ${includes})
get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
# _ALL_INCS is a space-separated string of file paths in quotes.
- set(_ALL_INCS "${_ALL_INCS} \"${_ABS_INC}\"")
+ string(APPEND _ALL_INCS " \"${_ABS_INC}\"")
endforeach()
set_target_properties(${name} PROPERTIES XCODE_ATTRIBUTE_USER_HEADER_SEARCH_PATHS "${_ALL_INCS}")
endif()
@@ -250,11 +263,11 @@ macro(add_cc_flags_custom_test
string(TOUPPER ${name} _name_upper)
if(DEFINED CMAKE_C_FLAGS_${_name_upper})
message(STATUS "Using custom CFLAGS: CMAKE_C_FLAGS_${_name_upper} in \"${CMAKE_CURRENT_SOURCE_DIR}\"")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${_name_upper}}" ${ARGV1})
+ string(APPEND CMAKE_C_FLAGS " ${CMAKE_C_FLAGS_${_name_upper}}" ${ARGV1})
endif()
if(DEFINED CMAKE_CXX_FLAGS_${_name_upper})
message(STATUS "Using custom CXXFLAGS: CMAKE_CXX_FLAGS_${_name_upper} in \"${CMAKE_CURRENT_SOURCE_DIR}\"")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_name_upper}}" ${ARGV1})
+ string(APPEND CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS_${_name_upper}}" ${ARGV1})
endif()
unset(_name_upper)
@@ -302,14 +315,14 @@ function(blender_add_lib__impl
#
# What this code does it traverses library_deps and extracts information about whether
# library is to provided as general, debug or optimized. This is a little state machine which
- # keeps track of whiuch build type library is to provided for:
+ # keeps track of which build type library is to provided for:
#
# - If "debug" or "optimized" word is found, the next element in the list is expected to be
# a library which will be passed to target_link_libraries() under corresponding build type.
#
# - If there is no "debug" or "optimized" used library is specified for all build types.
#
- # NOTE: If separated libraries for debug and release ar eneeded 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.
#
# Use: "optimized libfoo optimized libbar debug libfoo_d debug libbar_d"
@@ -375,9 +388,8 @@ function(blender_add_lib
set_property(GLOBAL APPEND PROPERTY BLENDER_LINK_LIBS ${name})
endfunction()
-# blender_add_test_lib() is used to define a test library. It is intended to be
-# called in tandem with blender_add_lib(). The test library will be linked into
-# the bf_gtest_runner_test executable (see tests/gtests/CMakeLists.txt).
+# Add tests for a Blender library, to be called in tandem with blender_add_lib().
+# The tests will be part of the blender_test executable (see tests/gtests/runner).
function(blender_add_test_lib
name
sources
@@ -411,6 +423,48 @@ function(blender_add_test_lib
set_property(GLOBAL APPEND PROPERTY BLENDER_TEST_LIBS ${name})
endfunction()
+
+# Add tests for a Blender library, to be called in tandem with blender_add_lib().
+# Test will be compiled into a ${name}_test executable.
+#
+# 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
+# very large executable, blender_add_test_lib() should be used instead.
+function(blender_add_test_executable
+ name
+ sources
+ includes
+ includes_sys
+ library_deps
+ )
+
+ add_cc_flags_custom_test(${name} PARENT_SCOPE)
+
+ ## Otherwise external projects will produce warnings that we cannot fix.
+ remove_strict_flags()
+
+ include_directories(${includes})
+ include_directories(${includes_sys})
+ setup_libdirs()
+
+ BLENDER_SRC_GTEST_EX(
+ NAME ${name}
+ SRC "${sources}"
+ EXTRA_LIBS "${library_deps}"
+ SKIP_ADD_TEST
+ )
+
+ include(GTest)
+ set(_GOOGLETEST_DISCOVER_TESTS_SCRIPT
+ ${CMAKE_SOURCE_DIR}/build_files/cmake/Modules/GTestAddTests.cmake
+ )
+
+ gtest_discover_tests(${name}_test
+ DISCOVERY_MODE PRE_TEST
+ WORKING_DIRECTORY "${TEST_INSTALL_DIR}"
+ )
+endfunction()
+
# Ninja only: assign 'heavy pool' to some targets that are especially RAM-consuming to build.
function(setup_heavy_lib_pool)
if(WITH_NINJA_POOL_JOBS AND NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS)
@@ -436,8 +490,8 @@ function(SETUP_LIBDIRS)
# NOTE: For all new libraries, use absolute library paths.
# This should eventually be phased out.
-
- if(NOT MSVC)
+ # APPLE plaform uses full paths for linking libraries, and avoids link_directories.
+ if(NOT MSVC AND NOT APPLE)
link_directories(${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${FREETYPE_LIBPATH})
if(WITH_PYTHON) # AND NOT WITH_PYTHON_MODULE # WIN32 needs
@@ -514,33 +568,18 @@ function(SETUP_LIBDIRS)
endif()
endfunction()
-macro(setup_platform_linker_flags)
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}")
- set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${PLATFORM_LINKFLAGS_RELEASE}")
- set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}")
-endmacro()
+# Platform specific linker flags for targets.
+function(setup_platform_linker_flags
+ target)
+ 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}")
+endfunction()
-function(setup_liblinks
+# Platform specific libraries for targets.
+function(setup_platform_linker_libs
target
)
-
- # NOTE: This might look like it affects global scope, accumulating linker flags on every call
- # to setup_liblinks, but this isn't how CMake works. These flags will only affect current
- # directory from where the function is called.
- # This means that setup_liblinks() called for ffmpeg_test will not affect blender, and each
- # of thsoe targets will have single set of linker flags.
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
- set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
- set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${PLATFORM_LINKFLAGS_RELEASE}" PARENT_SCOPE)
-
- set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
- set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
- set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${PLATFORM_LINKFLAGS_RELEASE}" PARENT_SCOPE)
-
- set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
- set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
- set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} ${PLATFORM_LINKFLAGS_RELEASE}" PARENT_SCOPE)
-
# jemalloc must be early in the list, to be before pthread (see T57998)
if(WITH_MEM_JEMALLOC)
target_link_libraries(${target} ${JEMALLOC_LIBRARIES})
@@ -649,14 +688,14 @@ endmacro()
macro(add_c_flag
flag)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
+ string(APPEND CMAKE_C_FLAGS " ${flag}")
+ string(APPEND CMAKE_CXX_FLAGS " ${flag}")
endmacro()
macro(add_cxx_flag
flag)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
+ string(APPEND CMAKE_CXX_FLAGS " ${flag}")
endmacro()
macro(remove_strict_flags)
@@ -1215,8 +1254,16 @@ endmacro()
macro(without_system_libs_begin)
set(CMAKE_IGNORE_PATH "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES};${CMAKE_SYSTEM_INCLUDE_PATH};${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES};${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}")
+ if(APPLE)
+ # Avoid searching for headers in frameworks (like Mono), and libraries in LIBDIR.
+ set(CMAKE_FIND_FRAMEWORK NEVER)
+ endif()
endmacro()
macro(without_system_libs_end)
unset(CMAKE_IGNORE_PATH)
+ if(APPLE)
+ # FIRST is the default.
+ set(CMAKE_FIND_FRAMEWORK FIRST)
+ endif()
endmacro()