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:
authorCampbell Barton <ideasman42@gmail.com>2016-07-14 12:11:33 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-07-14 12:17:34 +0300
commit103a51504372129975e60f57fbf3c983527037eb (patch)
tree248f862f8df37012fabbf87582251a4882e828bf /build_files/cmake
parent036c006cefe471a774b837acf0325282e3ad15d0 (diff)
CMake: per-target CFLAG & CXXFLAG support
Applying cflags globally can be problematic especially with extern, intern libs. Now flags from target named will be used when defined, allowing for developers to define flags for modules they maintain. Convention is CMAKE_CFLAGS_${UPPERCASE_TARGET_NAME}, (CXXFLAGS for C++). eg: CMAKE_CFLAGS_BF_BLENDER, CMAKE_CFLAGS_MAKESDNA, CMAKE_CXXFLAGS_CYCLES_KERNEL On Linux run `make help` for full list of names, MSVC shows these in the solution.
Diffstat (limited to 'build_files/cmake')
-rw-r--r--build_files/cmake/macros.cmake43
1 files changed, 41 insertions, 2 deletions
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index d29f086069a..5ffd6c4e7f4 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -196,8 +196,33 @@ function(blender_source_group
endfunction()
+# Support per-target CMake flags
+# Read from: CMAKE_C_FLAGS_**** (made upper case) when set.
+#
+# 'name' should alway match the target name,
+# use this macro before add_library or add_executable.
+#
+# Optionally takes an arg passed to set(), eg PARENT_SCOPE.
+macro(add_cc_flags_custom_test
+ name
+ )
+
+ 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})
+ 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})
+ endif()
+ unset(_name_upper)
+
+endmacro()
+
+
# only MSVC uses SOURCE_GROUP
-function(blender_add_lib_nolist
+function(blender_add_lib__impl
name
sources
includes
@@ -225,6 +250,18 @@ function(blender_add_lib_nolist
endfunction()
+function(blender_add_lib_nolist
+ name
+ sources
+ includes
+ includes_sys
+ )
+
+ add_cc_flags_custom_test(${name} PARENT_SCOPE)
+
+ blender_add_lib__impl(${name} "${sources}" "${includes}" "${includes_sys}")
+endfunction()
+
function(blender_add_lib
name
sources
@@ -232,7 +269,9 @@ function(blender_add_lib
includes_sys
)
- blender_add_lib_nolist(${name} "${sources}" "${includes}" "${includes_sys}")
+ add_cc_flags_custom_test(${name} PARENT_SCOPE)
+
+ blender_add_lib__impl(${name} "${sources}" "${includes}" "${includes_sys}")
set_property(GLOBAL APPEND PROPERTY BLENDER_LINK_LIBS ${name})
endfunction()