[Bf-blender-cvs] [81b37f5] master: CMake: use functions instead of macros
Campbell Barton
noreply at git.blender.org
Wed Jun 17 01:44:07 CEST 2015
Commit: 81b37f5e92340cae8df118315b1ba6ac0cc02b0b
Author: Campbell Barton
Date: Wed Jun 17 09:16:17 2015 +1000
Branches: master
https://developer.blender.org/rB81b37f5e92340cae8df118315b1ba6ac0cc02b0b
CMake: use functions instead of macros
Reduces issues with vars leaking into the parent scope.
===================================================================
M CMakeLists.txt
M GNUmakefile
M build_files/cmake/macros.cmake
M source/creator/CMakeLists.txt
===================================================================
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1f0be6c..38a9a58 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,7 +53,9 @@ if(NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
endif()
if(NOT EXECUTABLE_OUTPUT_PATH)
- set(FIRST_RUN "TRUE")
+ set(FIRST_RUN TRUE)
+else()
+ set(FIRST_RUN FALSE)
endif()
# this starts out unset
@@ -129,7 +131,7 @@ macro(option_defaults_init)
set(${_var} ON)
list(APPEND _init_vars "${_var}")
endforeach()
- unset(_INC)
+ unset(_var)
endmacro()
# remove from namespace
@@ -2760,25 +2762,29 @@ include(build_files/cmake/packaging.cmake)
# Print Final Configuration
if(FIRST_RUN)
- set(_config_msg "\n* Blender Configuration *")
- macro(info_cfg_option
- _setting)
- set(_msg " * ${_setting}")
+
+ set(_config_msg "\nBlender Configuration\n=====================")
+
+ function(info_cfg_option
+ _setting
+ )
+
+ set(_msg " - ${_setting}")
string(LENGTH "${_msg}" _len)
while("32" GREATER "${_len}")
set(_msg "${_msg} ")
math(EXPR _len "${_len} + 1")
endwhile()
- set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
- endmacro()
-
- macro(info_cfg_text
- _text)
- set(_config_msg "${_config_msg}\n\n ${_text}")
+ set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
+ endfunction()
+ function(info_cfg_text
+ _text
+ )
- endmacro()
+ set(_config_msg "${_config_msg}\n\n ${_text}" PARENT_SCOPE)
+ endfunction()
message(STATUS "C Compiler: \"${CMAKE_C_COMPILER_ID}\"")
message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
diff --git a/GNUmakefile b/GNUmakefile
index 8d251cb..3c2ab9d 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -124,12 +124,12 @@ all: FORCE
@echo
@echo Configuring Blender ...
- # if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
- # $(CMAKE_CONFIG); \
- # fi
+# # if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
+# # $(CMAKE_CONFIG); \
+# # fi
- # do this always incase of failed initial build, could be smarter here...
- $(CMAKE_CONFIG)
+# # do this always incase of failed initial build, could be smarter here...
+ @$(CMAKE_CONFIG)
@echo
@echo Building Blender ...
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 7de2b25..2cc57f6 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -104,21 +104,31 @@ macro(file_list_suffix
endmacro()
-macro(target_link_libraries_optimized TARGET LIBS)
+function(target_link_libraries_optimized
+ TARGET
+ LIBS
+ )
+
foreach(_LIB ${LIBS})
target_link_libraries(${TARGET} optimized "${_LIB}")
endforeach()
- unset(_LIB)
-endmacro()
+endfunction()
+
+function(target_link_libraries_debug
+ TARGET
+ LIBS
+ )
-macro(target_link_libraries_debug TARGET LIBS)
foreach(_LIB ${LIBS})
target_link_libraries(${TARGET} debug "${_LIB}")
endforeach()
- unset(_LIB)
-endmacro()
+endfunction()
+
+function(target_link_libraries_decoupled
+ target
+ libraries_var
+ )
-macro(target_link_libraries_decoupled target libraries_var)
if(NOT MSVC)
target_link_libraries(${target} ${${libraries_var}})
else()
@@ -127,14 +137,15 @@ macro(target_link_libraries_decoupled target libraries_var)
file_list_suffix(_libraries_debug "${${libraries_var}}" "_d")
target_link_libraries_debug(${target} "${_libraries_debug}")
target_link_libraries_optimized(${target} "${${libraries_var}}")
- unset(_libraries_debug)
endif()
-endmacro()
+endfunction()
# Nicer makefiles with -I/1/foo/ instead of -I/1/2/3/../../foo/
# use it instead of include_directories()
-macro(blender_include_dirs
- includes)
+function(blender_include_dirs
+ includes
+ )
+
set(_ALL_INCS "")
foreach(_INC ${ARGV})
get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
@@ -145,13 +156,12 @@ macro(blender_include_dirs
##endif()
endforeach()
include_directories(${_ALL_INCS})
- unset(_INC)
- unset(_ABS_INC)
- unset(_ALL_INCS)
-endmacro()
+endfunction()
+
+function(blender_include_dirs_sys
+ includes
+ )
-macro(blender_include_dirs_sys
- includes)
set(_ALL_INCS "")
foreach(_INC ${ARGV})
get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
@@ -161,13 +171,11 @@ macro(blender_include_dirs_sys
##endif()
endforeach()
include_directories(SYSTEM ${_ALL_INCS})
- unset(_INC)
- unset(_ABS_INC)
- unset(_ALL_INCS)
-endmacro()
+endfunction()
-macro(blender_source_group
- sources)
+function(blender_source_group
+ sources
+ )
# Group by location on disk
source_group("Source Files" FILES CMakeLists.txt)
@@ -177,23 +185,23 @@ macro(blender_source_group
if((${_SRC_EXT} MATCHES ".h") OR
(${_SRC_EXT} MATCHES ".hpp") OR
(${_SRC_EXT} MATCHES ".hh"))
- source_group("Header Files" FILES ${_SRC})
+
+ set(GROUP_ID "Header Files")
else()
- source_group("Source Files" FILES ${_SRC})
+ set(GROUP_ID "Source Files")
endif()
+ source_group("${GROUP_ID}" FILES ${_SRC})
endforeach()
-
- unset(_SRC)
- unset(_SRC_EXT)
-endmacro()
+endfunction()
# only MSVC uses SOURCE_GROUP
-macro(blender_add_lib_nolist
+function(blender_add_lib_nolist
name
sources
includes
- includes_sys)
+ includes_sys
+ )
# message(STATUS "Configuring library ${name}")
@@ -213,22 +221,24 @@ macro(blender_add_lib_nolist
# Not for system includes because they can resolve to the same path
# list_assert_duplicates("${includes_sys}")
-endmacro()
+endfunction()
-macro(blender_add_lib
+function(blender_add_lib
name
sources
includes
- includes_sys)
+ includes_sys
+ )
blender_add_lib_nolist(${name} "${sources}" "${includes}" "${includes_sys}")
set_property(GLOBAL APPEND PROPERTY BLENDER_LINK_LIBS ${name})
-endmacro()
+endfunction()
+
+function(SETUP_LIBDIRS)
-macro(SETUP_LIBDIRS)
link_directories(${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${FREETYPE_LIBPATH})
if(WITH_PYTHON) # AND NOT WITH_PYTHON_MODULE # WIN32 needs
@@ -288,10 +298,11 @@ macro(SETUP_LIBDIRS)
if(WIN32 AND NOT UNIX)
link_directories(${PTHREADS_LIBPATH})
endif()
-endmacro()
+endfunction()
-macro(setup_liblinks
- target)
+function(setup_liblinks
+ target
+ )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}")
@@ -302,10 +313,12 @@ macro(setup_liblinks
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}")
- target_link_libraries(${target}
- ${PNG_LIBRARIES}
- ${ZLIB_LIBRARIES}
- ${FREETYPE_LIBRARY})
+ target_link_libraries(
+ ${target}
+ ${PNG_LIBRARIES}
+ ${ZLIB_LIBRARIES}
+ ${FREETYPE_LIBRARY}
+ )
# since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions
if(WITH_PYTHON) # AND NOT WITH_PYTHON_MODULE # WIN32 needs
@@ -402,11 +415,13 @@ macro(setup_liblinks
unset(EXPAT_LIB_DEBUG)
endif()
else()
- target_link_libraries(${target}
- ${OPENCOLLADA_LIBRARIES}
- ${PCRE_LIBRARIES}
- ${XML2_LIBRARIES}
- ${EXPAT_LIB})
+ target_link_libraries(
+ ${target}
+ ${OPENCOLLADA_LIBRARIES}
+ ${PCRE_LIBRARIES}
+ ${XML2_LIBRARIES}
+ ${EXPAT_LIB}
+ )
endif()
endif()
if(WITH_MEM_JEMALLOC)
@@ -436,9 +451,11 @@ macro(setup_liblinks
${BLENDER_GL_LIBRARIES})
target_link_libraries(${target} ${PLATFORM_LINKLIBS} ${CMAKE_DL_LIBS})
-endmacro()
+endfunction()
+
+
+function(SETUP_BLENDER_SORTED_LIBS)
-macro(SETUP_BLENDER_SORTED_LIBS)
get_property(BLENDER_LINK_LIBS GLOBAL PROPERTY BLENDER_LINK_LIBS)
list(APPEND BLENDER_LINK_LIBS
@@ -674,14 +691,12 @@ macro(SETUP_BLENDER_SORTED_LIBS)
message(STATUS "Blender Skipping: (${REM_MSG})")
endif()
- unset(SEARCHLIB)
- unset(SORTLIB)
- unset(REMLIB)
- unset(REM_MSG)
+
+ set(BLENDER_SORTED_LIBS ${BLENDER_SORTED_LIBS} PARENT_SCOPE)
# for top-level tests
set_property(GLOBAL PROPERTY BLENDER_SORTED_LIBS_PROP ${BLENDER_SORTED_LIBS})
-endmacro()
+endfunction()
macro(TEST_SSE_SUPPORT
_sse_flags
@@ -1004,37 +1019,39 @@ macro(remove_strict_flags_file
endmacro()
-macro(ADD_CHECK_C_COMPILER_FLAG
+function(ADD_CHECK_C_COMPILER_FLAG
_CFLAGS
_CACHE_VAR
- _FLAG)
+ _FLAG
+ )
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
if(${_CACHE_VAR})
# message(STATUS "Using CFLAG: ${_FLAG}")
- set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}")
+ set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}" PARENT_SCOPE)
else()
message(STATUS "Unsupported CFLAG: ${_FLAG}")
endif()
-endmacro()
+endfunction()
-macro(ADD_CHECK_CXX_COMPILER_FLAG
+function(ADD_CHECK_CXX_COMPILER_FLAG
_CXXFLAGS
_CACHE_VAR
- _FLAG)
+ _FLAG
+ )
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
if(${_CACHE_VAR})
# message(STATUS "Using CXXFLAG: ${_FLAG}")
- set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}")
+ set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}" PARENT_SCOPE)
else()
message(STATUS "Unsupported CXXFLAG: ${_FLAG}")
endif()
-endmacro()
+endfunction()
function(get_blender_version)
# extracts header vars and defines them in the parent scope:
@@ -1184,7 +1201,7 @@ endmacro()
# pair of macros to allow libraries to be specify files to install, but to
# only install them at the end so the directories don't get cleared with
# the files in them. used by cycles to install addon.
-macro(delayed_install
+function(delayed_install
base
files
destination)
@@ -1197,8 +1214,7 @@ macro(delayed_install
endif()
set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_DESTINATIONS ${destination})
endforeach()
- unset(f)
-endmacro()
+endfunction()
# note this is a function instead of a macro so that ${BUILD_TYPE} in targetdir
# does not get expanded in calling but is preserved
@@ -1217,16 +1233,17 @@ function(delayed_do_install
list(GET destinations ${i} d)
install(FILES ${f} DESTINATION ${targetdir}/${d})
endforeach()
- unset(f)
endif()
endfunction()
-macro(data_to_c
- file_from file_to
- list_to_add)
+function(data_to_c
+ file_from file_to
+ list_to_add
+ )
list(APPEND ${list_to_add} ${file_to})
+ set(${list_to_add} ${${list_to_add}} PAREN
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list