2022-02-10 22:07:11 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
# Copyright 2006 Blender Foundation. All rights reserved.
|
2011-06-19 06:57:56 +00:00
|
|
|
|
2012-07-16 08:26:42 +00:00
|
|
|
macro(list_insert_after
|
|
|
|
list_id item_check item_add
|
|
|
|
)
|
|
|
|
set(_index)
|
2012-09-13 01:52:58 +00:00
|
|
|
list(FIND "${list_id}" "${item_check}" _index)
|
|
|
|
if("${_index}" MATCHES "-1")
|
|
|
|
message(FATAL_ERROR "'${list_id}' doesn't contain '${item_check}'")
|
|
|
|
endif()
|
2012-07-16 08:26:42 +00:00
|
|
|
math(EXPR _index "${_index} + 1")
|
|
|
|
list(INSERT ${list_id} "${_index}" ${item_add})
|
|
|
|
unset(_index)
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(list_insert_before
|
|
|
|
list_id item_check item_add
|
|
|
|
)
|
|
|
|
set(_index)
|
2012-09-13 01:52:58 +00:00
|
|
|
list(FIND "${list_id}" "${item_check}" _index)
|
|
|
|
if("${_index}" MATCHES "-1")
|
|
|
|
message(FATAL_ERROR "'${list_id}' doesn't contain '${item_check}'")
|
|
|
|
endif()
|
2012-07-16 08:26:42 +00:00
|
|
|
list(INSERT ${list_id} "${_index}" ${item_add})
|
|
|
|
unset(_index)
|
|
|
|
endmacro()
|
|
|
|
|
2015-06-30 12:44:27 +00:00
|
|
|
function(list_assert_duplicates
|
2013-10-25 06:21:38 +00:00
|
|
|
list_id
|
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2013-10-25 06:21:38 +00:00
|
|
|
# message(STATUS "list data: ${list_id}")
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2013-10-25 06:21:38 +00:00
|
|
|
list(LENGTH list_id _len_before)
|
|
|
|
list(REMOVE_DUPLICATES list_id)
|
|
|
|
list(LENGTH list_id _len_after)
|
|
|
|
# message(STATUS "list size ${_len_before} -> ${_len_after}")
|
|
|
|
if(NOT _len_before EQUAL _len_after)
|
|
|
|
message(FATAL_ERROR "duplicate found in list which should not contain duplicates: ${list_id}")
|
|
|
|
endif()
|
|
|
|
unset(_len_before)
|
|
|
|
unset(_len_after)
|
|
|
|
endfunction()
|
|
|
|
|
2020-11-04 04:59:55 +00:00
|
|
|
# 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()
|
2013-10-25 06:21:38 +00:00
|
|
|
|
2011-06-19 06:57:56 +00:00
|
|
|
# foo_bar.spam --> foo_barMySuffix.spam
|
|
|
|
macro(file_suffix
|
|
|
|
file_name_new file_name file_suffix
|
|
|
|
)
|
|
|
|
|
|
|
|
get_filename_component(_file_name_PATH ${file_name} PATH)
|
|
|
|
get_filename_component(_file_name_NAME_WE ${file_name} NAME_WE)
|
|
|
|
get_filename_component(_file_name_EXT ${file_name} EXT)
|
|
|
|
set(${file_name_new} "${_file_name_PATH}/${_file_name_NAME_WE}${file_suffix}${_file_name_EXT}")
|
|
|
|
|
|
|
|
unset(_file_name_PATH)
|
|
|
|
unset(_file_name_NAME_WE)
|
|
|
|
unset(_file_name_EXT)
|
|
|
|
endmacro()
|
|
|
|
|
2011-10-23 17:52:20 +00:00
|
|
|
# useful for adding debug suffix to library lists:
|
2011-06-19 06:57:56 +00:00
|
|
|
# /somepath/foo.lib --> /somepath/foo_d.lib
|
|
|
|
macro(file_list_suffix
|
|
|
|
fp_list_new fp_list fn_suffix
|
|
|
|
)
|
|
|
|
|
|
|
|
# incase of empty list
|
|
|
|
set(_fp)
|
|
|
|
set(_fp_suffixed)
|
|
|
|
|
|
|
|
set(fp_list_new)
|
|
|
|
|
|
|
|
foreach(_fp ${fp_list})
|
|
|
|
file_suffix(_fp_suffixed "${_fp}" "${fn_suffix}")
|
|
|
|
list(APPEND "${fp_list_new}" "${_fp_suffixed}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
unset(_fp)
|
|
|
|
unset(_fp_suffixed)
|
|
|
|
|
|
|
|
endmacro()
|
|
|
|
|
2015-12-02 13:09:06 +00:00
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
macro(find_package_static)
|
|
|
|
set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
|
|
|
find_package(${ARGV})
|
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
|
|
|
|
unset(_cmake_find_library_suffixes_back)
|
|
|
|
endmacro()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2015-12-02 13:09:06 +00:00
|
|
|
macro(find_library_static)
|
|
|
|
set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
|
|
|
find_library(${ARGV})
|
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
|
|
|
|
unset(_cmake_find_library_suffixes_back)
|
|
|
|
endmacro()
|
|
|
|
endif()
|
2011-06-26 17:18:37 +00:00
|
|
|
|
2015-06-16 23:16:17 +00:00
|
|
|
function(target_link_libraries_optimized
|
|
|
|
TARGET
|
|
|
|
LIBS
|
|
|
|
)
|
|
|
|
|
2011-06-26 17:18:37 +00:00
|
|
|
foreach(_LIB ${LIBS})
|
2020-03-02 19:42:01 +00:00
|
|
|
target_link_libraries(${TARGET} INTERFACE optimized "${_LIB}")
|
2011-06-26 17:18:37 +00:00
|
|
|
endforeach()
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(target_link_libraries_debug
|
|
|
|
TARGET
|
|
|
|
LIBS
|
|
|
|
)
|
2011-06-26 17:18:37 +00:00
|
|
|
|
|
|
|
foreach(_LIB ${LIBS})
|
2020-03-02 19:42:01 +00:00
|
|
|
target_link_libraries(${TARGET} INTERFACE debug "${_LIB}")
|
2011-06-26 17:18:37 +00:00
|
|
|
endforeach()
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
|
|
|
|
2010-12-22 22:15:20 +00:00
|
|
|
# Nicer makefiles with -I/1/foo/ instead of -I/1/2/3/../../foo/
|
|
|
|
# use it instead of include_directories()
|
2015-06-16 23:16:17 +00:00
|
|
|
function(blender_include_dirs
|
|
|
|
includes
|
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-06-11 06:00:28 +00:00
|
|
|
set(_ALL_INCS "")
|
|
|
|
foreach(_INC ${ARGV})
|
|
|
|
get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
|
|
|
|
list(APPEND _ALL_INCS ${_ABS_INC})
|
2011-08-08 05:43:04 +00:00
|
|
|
# for checking for invalid includes, disable for regular use
|
2019-10-28 14:32:33 +00:00
|
|
|
# if(NOT EXISTS "${_ABS_INC}/")
|
|
|
|
# message(FATAL_ERROR "Include not found: ${_ABS_INC}/")
|
|
|
|
# endif()
|
2010-12-22 22:15:20 +00:00
|
|
|
endforeach()
|
2011-06-11 06:00:28 +00:00
|
|
|
include_directories(${_ALL_INCS})
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(blender_include_dirs_sys
|
|
|
|
includes
|
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-06-11 06:00:28 +00:00
|
|
|
set(_ALL_INCS "")
|
|
|
|
foreach(_INC ${ARGV})
|
|
|
|
get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
|
|
|
|
list(APPEND _ALL_INCS ${_ABS_INC})
|
2019-10-28 14:32:33 +00:00
|
|
|
# if(NOT EXISTS "${_ABS_INC}/")
|
|
|
|
# message(FATAL_ERROR "Include not found: ${_ABS_INC}/")
|
|
|
|
# endif()
|
2011-05-31 01:15:44 +00:00
|
|
|
endforeach()
|
2011-06-11 06:00:28 +00:00
|
|
|
include_directories(SYSTEM ${_ALL_INCS})
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2010-11-05 04:18:53 +00:00
|
|
|
|
2020-07-30 15:43:26 +00:00
|
|
|
# Set include paths for header files included with "*.h" syntax.
|
|
|
|
# This enables auto-complete suggestions for user header files on Xcode.
|
|
|
|
# Build process is not affected since the include paths are the same
|
|
|
|
# as in HEADER_SEARCH_PATHS.
|
|
|
|
function(blender_user_header_search_paths
|
|
|
|
name
|
|
|
|
includes
|
|
|
|
)
|
|
|
|
|
|
|
|
if(XCODE)
|
|
|
|
set(_ALL_INCS "")
|
|
|
|
foreach(_INC ${includes})
|
|
|
|
get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
|
|
|
|
# _ALL_INCS is a space-separated string of file paths in quotes.
|
2020-11-05 23:29:04 +00:00
|
|
|
string(APPEND _ALL_INCS " \"${_ABS_INC}\"")
|
2020-07-30 15:43:26 +00:00
|
|
|
endforeach()
|
|
|
|
set_target_properties(${name} PROPERTIES XCODE_ATTRIBUTE_USER_HEADER_SEARCH_PATHS "${_ALL_INCS}")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2015-06-16 23:16:17 +00:00
|
|
|
function(blender_source_group
|
2020-03-01 15:16:54 +00:00
|
|
|
name
|
2015-06-16 23:16:17 +00:00
|
|
|
sources
|
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2019-10-28 14:32:33 +00:00
|
|
|
# if enabled, use the sources directories as filters.
|
2021-08-05 15:49:55 +00:00
|
|
|
if(IDE_GROUP_SOURCES_IN_FOLDERS)
|
2019-06-15 18:44:47 +00:00
|
|
|
foreach(_SRC ${sources})
|
|
|
|
# remove ../'s
|
|
|
|
get_filename_component(_SRC_DIR ${_SRC} REALPATH)
|
|
|
|
get_filename_component(_SRC_DIR ${_SRC_DIR} DIRECTORY)
|
2019-06-18 21:12:16 +00:00
|
|
|
string(FIND ${_SRC_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/" _pos)
|
|
|
|
if(NOT _pos EQUAL -1)
|
2019-06-15 18:44:47 +00:00
|
|
|
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" GROUP_ID ${_SRC_DIR})
|
|
|
|
string(REPLACE "/" "\\" GROUP_ID ${GROUP_ID})
|
|
|
|
source_group("${GROUP_ID}" FILES ${_SRC})
|
|
|
|
endif()
|
2019-06-18 21:12:16 +00:00
|
|
|
unset(_pos)
|
2019-06-15 18:44:47 +00:00
|
|
|
endforeach()
|
|
|
|
else()
|
|
|
|
# Group by location on disk
|
|
|
|
source_group("Source Files" FILES CMakeLists.txt)
|
|
|
|
foreach(_SRC ${sources})
|
2019-06-15 22:16:04 +00:00
|
|
|
get_filename_component(_SRC_EXT ${_SRC} EXT)
|
2019-06-15 18:44:47 +00:00
|
|
|
if((${_SRC_EXT} MATCHES ".h") OR
|
|
|
|
(${_SRC_EXT} MATCHES ".hpp") OR
|
|
|
|
(${_SRC_EXT} MATCHES ".hh"))
|
|
|
|
|
|
|
|
set(GROUP_ID "Header Files")
|
2019-06-15 22:16:04 +00:00
|
|
|
elseif(${_SRC_EXT} MATCHES ".glsl$")
|
2019-06-15 18:44:47 +00:00
|
|
|
set(GROUP_ID "Shaders")
|
|
|
|
else()
|
|
|
|
set(GROUP_ID "Source Files")
|
|
|
|
endif()
|
|
|
|
source_group("${GROUP_ID}" FILES ${_SRC})
|
|
|
|
endforeach()
|
|
|
|
endif()
|
2020-03-01 15:16:54 +00:00
|
|
|
|
2021-08-05 15:49:55 +00:00
|
|
|
# if enabled, set the FOLDER property for the projects
|
|
|
|
if(IDE_GROUP_PROJECTS_IN_FOLDERS)
|
2020-03-01 15:16:54 +00:00
|
|
|
get_filename_component(FolderDir ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
|
|
|
|
string(REPLACE ${CMAKE_SOURCE_DIR} "" FolderDir ${FolderDir})
|
|
|
|
set_target_properties(${name} PROPERTIES FOLDER ${FolderDir})
|
|
|
|
endif()
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2010-11-05 04:18:53 +00:00
|
|
|
|
2011-05-28 04:53:17 +00:00
|
|
|
|
2016-07-14 09:11:33 +00:00
|
|
|
# Support per-target CMake flags
|
|
|
|
# Read from: CMAKE_C_FLAGS_**** (made upper case) when set.
|
|
|
|
#
|
2018-09-19 15:48:11 +00:00
|
|
|
# 'name' should always match the target name,
|
2016-07-14 09:11:33 +00:00
|
|
|
# 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
|
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2016-07-14 09:11:33 +00:00
|
|
|
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}\"")
|
2020-11-05 23:29:04 +00:00
|
|
|
string(APPEND CMAKE_C_FLAGS " ${CMAKE_C_FLAGS_${_name_upper}}" ${ARGV1})
|
2016-07-14 09:11:33 +00:00
|
|
|
endif()
|
|
|
|
if(DEFINED CMAKE_CXX_FLAGS_${_name_upper})
|
|
|
|
message(STATUS "Using custom CXXFLAGS: CMAKE_CXX_FLAGS_${_name_upper} in \"${CMAKE_CURRENT_SOURCE_DIR}\"")
|
2020-11-05 23:29:04 +00:00
|
|
|
string(APPEND CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS_${_name_upper}}" ${ARGV1})
|
2016-07-14 09:11:33 +00:00
|
|
|
endif()
|
|
|
|
unset(_name_upper)
|
|
|
|
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
|
2011-05-28 04:53:17 +00:00
|
|
|
# only MSVC uses SOURCE_GROUP
|
2016-07-14 09:11:33 +00:00
|
|
|
function(blender_add_lib__impl
|
2011-05-28 04:53:17 +00:00
|
|
|
name
|
|
|
|
sources
|
2011-05-31 01:15:44 +00:00
|
|
|
includes
|
2015-06-16 23:16:17 +00:00
|
|
|
includes_sys
|
2019-04-16 04:11:27 +00:00
|
|
|
library_deps
|
2015-06-16 23:16:17 +00:00
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-05-28 04:53:17 +00:00
|
|
|
# message(STATUS "Configuring library ${name}")
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-05-28 04:53:17 +00:00
|
|
|
# include_directories(${includes})
|
2011-05-31 01:15:44 +00:00
|
|
|
# include_directories(SYSTEM ${includes_sys})
|
2011-05-28 04:53:17 +00:00
|
|
|
blender_include_dirs("${includes}")
|
2011-05-31 01:15:44 +00:00
|
|
|
blender_include_dirs_sys("${includes_sys}")
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-05-28 04:53:17 +00:00
|
|
|
add_library(${name} ${sources})
|
2019-04-17 04:35:54 +00:00
|
|
|
|
CMake: Refactor external dependencies handling
This is a more correct fix to the issue Brecht was fixing in D6600.
While the fix in that patch worked fine for linking it broke ASAN
runtime under some circumstances.
For example, `make full debug developer` would compile, but trying
to start blender will cause assert failure in ASAN (related on check
that ASAN is not running already).
Top-level idea: leave it to CMake to keep track of dependency graph.
The root of the issue comes to the fact that target like "blender" is
configured to use a lot of static libraries coming from Blender sources
and to use external static libraries. There is nothing which ensures
order between blender's and external libraries. Only order of blender
libraries is guaranteed.
It was possible that due to a cycle or other circumstances some of
blender libraries would have been passed to linker after libraries
it uses, causing linker errors.
For example, this order will likely fail:
libbf_blenfont.a libfreetype6.a libbf_blenfont.a
This change makes it so blender libraries are explicitly provided
their dependencies to an external libraries, which allows CMake to
ensure they are always linked against them.
General rule here: if bf_foo depends on an external library it is
to be provided to LIBS for bf_foo.
For example, if bf_blenkernel depends on opensubdiv then LIBS in
blenkernel's CMakeLists.txt is to include OPENSUBDIB_LIBRARIES.
The change is made based on searching for used include folders
such as OPENSUBDIV_INCLUDE_DIRS and adding corresponding libraries
to LIBS ion that CMakeLists.txt. Transitive dependencies are not
simplified by this approach, but I am not aware of any downside of
this: CMake should be smart enough to simplify them on its side.
And even if not, this shouldn't affect linking time.
Benefit of not relying on transitive dependencies is that build
system is more robust towards future changes. For example, if
bf_intern_opensubiv is no longer depends on OPENSUBDIV_LIBRARIES
and all such code is moved to bf_blenkernel this will not break
linking.
The not-so-trivial part is change to blender_add_lib (and its
version in Cycles). The complexity is caused by libraries being
provided as a single list argument which doesn't allow to use
different release and debug libraries on Windows. The idea is:
- Have every library prefixed as "optimized" or "debug" if
separation is needed (non-prefixed libraries will be considered
"generic").
- Loop through libraries passed to function and do simple parsing
which will look for "optimized" and "debug" words and specify
following library to corresponding category.
This isn't something particularly great. Alternative would be to
use target_link_libraries() directly, which sounds like more code
but which is more explicit and allows to have more flexibility
and control comparing to wrapper approach.
Tested the following configurations on Linux, macOS and Windows:
- make full debug developer
- make full release developer
- make lite debug developer
- make lite release developer
NOTE: Linux libraries needs to be compiled with D6641 applied,
otherwise, depending on configuration, it's possible to run into
duplicated zlib symbols error.
Differential Revision: https://developer.blender.org/D6642
2020-01-20 17:36:19 +00:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# CMake have a native way of dealing with this, which is specifying what build type the
|
|
|
|
# libraries are provided for:
|
|
|
|
#
|
|
|
|
# target_link_libraries(tagret optimized|debug|general <libraries>)
|
|
|
|
#
|
|
|
|
# The build type is to be provided as a separate argument to the function.
|
|
|
|
#
|
|
|
|
# CMake's variables for libraries will contain build type in such cases. For example:
|
|
|
|
#
|
|
|
|
# set(FOO_LIBRARIES optimized libfoo.lib debug libfoo_d.lib)
|
|
|
|
#
|
|
|
|
# Complications starts with a single argument for library_deps: all the elements are being
|
|
|
|
# put to a list: "${FOO_LIBRARIES}" will become "optimized;libfoo.lib;debug;libfoo_d.lib".
|
|
|
|
# This makes it impossible to pass it as-is to target_link_libraries sine it will treat
|
|
|
|
# this argument as a list of libraries to be linked against, causing missing libraries
|
|
|
|
# for optimized.lib.
|
|
|
|
#
|
|
|
|
# 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
|
2020-10-09 07:08:38 +00:00
|
|
|
# keeps track of which build type library is to provided for:
|
CMake: Refactor external dependencies handling
This is a more correct fix to the issue Brecht was fixing in D6600.
While the fix in that patch worked fine for linking it broke ASAN
runtime under some circumstances.
For example, `make full debug developer` would compile, but trying
to start blender will cause assert failure in ASAN (related on check
that ASAN is not running already).
Top-level idea: leave it to CMake to keep track of dependency graph.
The root of the issue comes to the fact that target like "blender" is
configured to use a lot of static libraries coming from Blender sources
and to use external static libraries. There is nothing which ensures
order between blender's and external libraries. Only order of blender
libraries is guaranteed.
It was possible that due to a cycle or other circumstances some of
blender libraries would have been passed to linker after libraries
it uses, causing linker errors.
For example, this order will likely fail:
libbf_blenfont.a libfreetype6.a libbf_blenfont.a
This change makes it so blender libraries are explicitly provided
their dependencies to an external libraries, which allows CMake to
ensure they are always linked against them.
General rule here: if bf_foo depends on an external library it is
to be provided to LIBS for bf_foo.
For example, if bf_blenkernel depends on opensubdiv then LIBS in
blenkernel's CMakeLists.txt is to include OPENSUBDIB_LIBRARIES.
The change is made based on searching for used include folders
such as OPENSUBDIV_INCLUDE_DIRS and adding corresponding libraries
to LIBS ion that CMakeLists.txt. Transitive dependencies are not
simplified by this approach, but I am not aware of any downside of
this: CMake should be smart enough to simplify them on its side.
And even if not, this shouldn't affect linking time.
Benefit of not relying on transitive dependencies is that build
system is more robust towards future changes. For example, if
bf_intern_opensubiv is no longer depends on OPENSUBDIV_LIBRARIES
and all such code is moved to bf_blenkernel this will not break
linking.
The not-so-trivial part is change to blender_add_lib (and its
version in Cycles). The complexity is caused by libraries being
provided as a single list argument which doesn't allow to use
different release and debug libraries on Windows. The idea is:
- Have every library prefixed as "optimized" or "debug" if
separation is needed (non-prefixed libraries will be considered
"generic").
- Loop through libraries passed to function and do simple parsing
which will look for "optimized" and "debug" words and specify
following library to corresponding category.
This isn't something particularly great. Alternative would be to
use target_link_libraries() directly, which sounds like more code
but which is more explicit and allows to have more flexibility
and control comparing to wrapper approach.
Tested the following configurations on Linux, macOS and Windows:
- make full debug developer
- make full release developer
- make lite debug developer
- make lite release developer
NOTE: Linux libraries needs to be compiled with D6641 applied,
otherwise, depending on configuration, it's possible to run into
duplicated zlib symbols error.
Differential Revision: https://developer.blender.org/D6642
2020-01-20 17:36:19 +00:00
|
|
|
#
|
|
|
|
# - 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.
|
|
|
|
#
|
2020-10-09 07:08:38 +00:00
|
|
|
# NOTE: If separated libraries for debug and release are needed every library is the list are
|
CMake: Refactor external dependencies handling
This is a more correct fix to the issue Brecht was fixing in D6600.
While the fix in that patch worked fine for linking it broke ASAN
runtime under some circumstances.
For example, `make full debug developer` would compile, but trying
to start blender will cause assert failure in ASAN (related on check
that ASAN is not running already).
Top-level idea: leave it to CMake to keep track of dependency graph.
The root of the issue comes to the fact that target like "blender" is
configured to use a lot of static libraries coming from Blender sources
and to use external static libraries. There is nothing which ensures
order between blender's and external libraries. Only order of blender
libraries is guaranteed.
It was possible that due to a cycle or other circumstances some of
blender libraries would have been passed to linker after libraries
it uses, causing linker errors.
For example, this order will likely fail:
libbf_blenfont.a libfreetype6.a libbf_blenfont.a
This change makes it so blender libraries are explicitly provided
their dependencies to an external libraries, which allows CMake to
ensure they are always linked against them.
General rule here: if bf_foo depends on an external library it is
to be provided to LIBS for bf_foo.
For example, if bf_blenkernel depends on opensubdiv then LIBS in
blenkernel's CMakeLists.txt is to include OPENSUBDIB_LIBRARIES.
The change is made based on searching for used include folders
such as OPENSUBDIV_INCLUDE_DIRS and adding corresponding libraries
to LIBS ion that CMakeLists.txt. Transitive dependencies are not
simplified by this approach, but I am not aware of any downside of
this: CMake should be smart enough to simplify them on its side.
And even if not, this shouldn't affect linking time.
Benefit of not relying on transitive dependencies is that build
system is more robust towards future changes. For example, if
bf_intern_opensubiv is no longer depends on OPENSUBDIV_LIBRARIES
and all such code is moved to bf_blenkernel this will not break
linking.
The not-so-trivial part is change to blender_add_lib (and its
version in Cycles). The complexity is caused by libraries being
provided as a single list argument which doesn't allow to use
different release and debug libraries on Windows. The idea is:
- Have every library prefixed as "optimized" or "debug" if
separation is needed (non-prefixed libraries will be considered
"generic").
- Loop through libraries passed to function and do simple parsing
which will look for "optimized" and "debug" words and specify
following library to corresponding category.
This isn't something particularly great. Alternative would be to
use target_link_libraries() directly, which sounds like more code
but which is more explicit and allows to have more flexibility
and control comparing to wrapper approach.
Tested the following configurations on Linux, macOS and Windows:
- make full debug developer
- make full release developer
- make lite debug developer
- make lite release developer
NOTE: Linux libraries needs to be compiled with D6641 applied,
otherwise, depending on configuration, it's possible to run into
duplicated zlib symbols error.
Differential Revision: https://developer.blender.org/D6642
2020-01-20 17:36:19 +00:00
|
|
|
# to be prefixed explicitly.
|
|
|
|
#
|
|
|
|
# Use: "optimized libfoo optimized libbar debug libfoo_d debug libbar_d"
|
|
|
|
# NOT: "optimized libfoo libbar debug libfoo_d libbar_d"
|
2019-06-18 21:24:55 +00:00
|
|
|
if(NOT "${library_deps}" STREQUAL "")
|
CMake: Refactor external dependencies handling
This is a more correct fix to the issue Brecht was fixing in D6600.
While the fix in that patch worked fine for linking it broke ASAN
runtime under some circumstances.
For example, `make full debug developer` would compile, but trying
to start blender will cause assert failure in ASAN (related on check
that ASAN is not running already).
Top-level idea: leave it to CMake to keep track of dependency graph.
The root of the issue comes to the fact that target like "blender" is
configured to use a lot of static libraries coming from Blender sources
and to use external static libraries. There is nothing which ensures
order between blender's and external libraries. Only order of blender
libraries is guaranteed.
It was possible that due to a cycle or other circumstances some of
blender libraries would have been passed to linker after libraries
it uses, causing linker errors.
For example, this order will likely fail:
libbf_blenfont.a libfreetype6.a libbf_blenfont.a
This change makes it so blender libraries are explicitly provided
their dependencies to an external libraries, which allows CMake to
ensure they are always linked against them.
General rule here: if bf_foo depends on an external library it is
to be provided to LIBS for bf_foo.
For example, if bf_blenkernel depends on opensubdiv then LIBS in
blenkernel's CMakeLists.txt is to include OPENSUBDIB_LIBRARIES.
The change is made based on searching for used include folders
such as OPENSUBDIV_INCLUDE_DIRS and adding corresponding libraries
to LIBS ion that CMakeLists.txt. Transitive dependencies are not
simplified by this approach, but I am not aware of any downside of
this: CMake should be smart enough to simplify them on its side.
And even if not, this shouldn't affect linking time.
Benefit of not relying on transitive dependencies is that build
system is more robust towards future changes. For example, if
bf_intern_opensubiv is no longer depends on OPENSUBDIV_LIBRARIES
and all such code is moved to bf_blenkernel this will not break
linking.
The not-so-trivial part is change to blender_add_lib (and its
version in Cycles). The complexity is caused by libraries being
provided as a single list argument which doesn't allow to use
different release and debug libraries on Windows. The idea is:
- Have every library prefixed as "optimized" or "debug" if
separation is needed (non-prefixed libraries will be considered
"generic").
- Loop through libraries passed to function and do simple parsing
which will look for "optimized" and "debug" words and specify
following library to corresponding category.
This isn't something particularly great. Alternative would be to
use target_link_libraries() directly, which sounds like more code
but which is more explicit and allows to have more flexibility
and control comparing to wrapper approach.
Tested the following configurations on Linux, macOS and Windows:
- make full debug developer
- make full release developer
- make lite debug developer
- make lite release developer
NOTE: Linux libraries needs to be compiled with D6641 applied,
otherwise, depending on configuration, it's possible to run into
duplicated zlib symbols error.
Differential Revision: https://developer.blender.org/D6642
2020-01-20 17:36:19 +00:00
|
|
|
set(next_library_mode "")
|
|
|
|
foreach(library ${library_deps})
|
|
|
|
string(TOLOWER "${library}" library_lower)
|
|
|
|
if(("${library_lower}" STREQUAL "optimized") OR
|
|
|
|
("${library_lower}" STREQUAL "debug"))
|
|
|
|
set(next_library_mode "${library_lower}")
|
|
|
|
else()
|
|
|
|
if("${next_library_mode}" STREQUAL "optimized")
|
2020-03-02 19:42:01 +00:00
|
|
|
target_link_libraries(${name} INTERFACE optimized ${library})
|
CMake: Refactor external dependencies handling
This is a more correct fix to the issue Brecht was fixing in D6600.
While the fix in that patch worked fine for linking it broke ASAN
runtime under some circumstances.
For example, `make full debug developer` would compile, but trying
to start blender will cause assert failure in ASAN (related on check
that ASAN is not running already).
Top-level idea: leave it to CMake to keep track of dependency graph.
The root of the issue comes to the fact that target like "blender" is
configured to use a lot of static libraries coming from Blender sources
and to use external static libraries. There is nothing which ensures
order between blender's and external libraries. Only order of blender
libraries is guaranteed.
It was possible that due to a cycle or other circumstances some of
blender libraries would have been passed to linker after libraries
it uses, causing linker errors.
For example, this order will likely fail:
libbf_blenfont.a libfreetype6.a libbf_blenfont.a
This change makes it so blender libraries are explicitly provided
their dependencies to an external libraries, which allows CMake to
ensure they are always linked against them.
General rule here: if bf_foo depends on an external library it is
to be provided to LIBS for bf_foo.
For example, if bf_blenkernel depends on opensubdiv then LIBS in
blenkernel's CMakeLists.txt is to include OPENSUBDIB_LIBRARIES.
The change is made based on searching for used include folders
such as OPENSUBDIV_INCLUDE_DIRS and adding corresponding libraries
to LIBS ion that CMakeLists.txt. Transitive dependencies are not
simplified by this approach, but I am not aware of any downside of
this: CMake should be smart enough to simplify them on its side.
And even if not, this shouldn't affect linking time.
Benefit of not relying on transitive dependencies is that build
system is more robust towards future changes. For example, if
bf_intern_opensubiv is no longer depends on OPENSUBDIV_LIBRARIES
and all such code is moved to bf_blenkernel this will not break
linking.
The not-so-trivial part is change to blender_add_lib (and its
version in Cycles). The complexity is caused by libraries being
provided as a single list argument which doesn't allow to use
different release and debug libraries on Windows. The idea is:
- Have every library prefixed as "optimized" or "debug" if
separation is needed (non-prefixed libraries will be considered
"generic").
- Loop through libraries passed to function and do simple parsing
which will look for "optimized" and "debug" words and specify
following library to corresponding category.
This isn't something particularly great. Alternative would be to
use target_link_libraries() directly, which sounds like more code
but which is more explicit and allows to have more flexibility
and control comparing to wrapper approach.
Tested the following configurations on Linux, macOS and Windows:
- make full debug developer
- make full release developer
- make lite debug developer
- make lite release developer
NOTE: Linux libraries needs to be compiled with D6641 applied,
otherwise, depending on configuration, it's possible to run into
duplicated zlib symbols error.
Differential Revision: https://developer.blender.org/D6642
2020-01-20 17:36:19 +00:00
|
|
|
elseif("${next_library_mode}" STREQUAL "debug")
|
2020-03-02 19:42:01 +00:00
|
|
|
target_link_libraries(${name} INTERFACE debug ${library})
|
CMake: Refactor external dependencies handling
This is a more correct fix to the issue Brecht was fixing in D6600.
While the fix in that patch worked fine for linking it broke ASAN
runtime under some circumstances.
For example, `make full debug developer` would compile, but trying
to start blender will cause assert failure in ASAN (related on check
that ASAN is not running already).
Top-level idea: leave it to CMake to keep track of dependency graph.
The root of the issue comes to the fact that target like "blender" is
configured to use a lot of static libraries coming from Blender sources
and to use external static libraries. There is nothing which ensures
order between blender's and external libraries. Only order of blender
libraries is guaranteed.
It was possible that due to a cycle or other circumstances some of
blender libraries would have been passed to linker after libraries
it uses, causing linker errors.
For example, this order will likely fail:
libbf_blenfont.a libfreetype6.a libbf_blenfont.a
This change makes it so blender libraries are explicitly provided
their dependencies to an external libraries, which allows CMake to
ensure they are always linked against them.
General rule here: if bf_foo depends on an external library it is
to be provided to LIBS for bf_foo.
For example, if bf_blenkernel depends on opensubdiv then LIBS in
blenkernel's CMakeLists.txt is to include OPENSUBDIB_LIBRARIES.
The change is made based on searching for used include folders
such as OPENSUBDIV_INCLUDE_DIRS and adding corresponding libraries
to LIBS ion that CMakeLists.txt. Transitive dependencies are not
simplified by this approach, but I am not aware of any downside of
this: CMake should be smart enough to simplify them on its side.
And even if not, this shouldn't affect linking time.
Benefit of not relying on transitive dependencies is that build
system is more robust towards future changes. For example, if
bf_intern_opensubiv is no longer depends on OPENSUBDIV_LIBRARIES
and all such code is moved to bf_blenkernel this will not break
linking.
The not-so-trivial part is change to blender_add_lib (and its
version in Cycles). The complexity is caused by libraries being
provided as a single list argument which doesn't allow to use
different release and debug libraries on Windows. The idea is:
- Have every library prefixed as "optimized" or "debug" if
separation is needed (non-prefixed libraries will be considered
"generic").
- Loop through libraries passed to function and do simple parsing
which will look for "optimized" and "debug" words and specify
following library to corresponding category.
This isn't something particularly great. Alternative would be to
use target_link_libraries() directly, which sounds like more code
but which is more explicit and allows to have more flexibility
and control comparing to wrapper approach.
Tested the following configurations on Linux, macOS and Windows:
- make full debug developer
- make full release developer
- make lite debug developer
- make lite release developer
NOTE: Linux libraries needs to be compiled with D6641 applied,
otherwise, depending on configuration, it's possible to run into
duplicated zlib symbols error.
Differential Revision: https://developer.blender.org/D6642
2020-01-20 17:36:19 +00:00
|
|
|
else()
|
2020-03-02 19:42:01 +00:00
|
|
|
target_link_libraries(${name} INTERFACE ${library})
|
CMake: Refactor external dependencies handling
This is a more correct fix to the issue Brecht was fixing in D6600.
While the fix in that patch worked fine for linking it broke ASAN
runtime under some circumstances.
For example, `make full debug developer` would compile, but trying
to start blender will cause assert failure in ASAN (related on check
that ASAN is not running already).
Top-level idea: leave it to CMake to keep track of dependency graph.
The root of the issue comes to the fact that target like "blender" is
configured to use a lot of static libraries coming from Blender sources
and to use external static libraries. There is nothing which ensures
order between blender's and external libraries. Only order of blender
libraries is guaranteed.
It was possible that due to a cycle or other circumstances some of
blender libraries would have been passed to linker after libraries
it uses, causing linker errors.
For example, this order will likely fail:
libbf_blenfont.a libfreetype6.a libbf_blenfont.a
This change makes it so blender libraries are explicitly provided
their dependencies to an external libraries, which allows CMake to
ensure they are always linked against them.
General rule here: if bf_foo depends on an external library it is
to be provided to LIBS for bf_foo.
For example, if bf_blenkernel depends on opensubdiv then LIBS in
blenkernel's CMakeLists.txt is to include OPENSUBDIB_LIBRARIES.
The change is made based on searching for used include folders
such as OPENSUBDIV_INCLUDE_DIRS and adding corresponding libraries
to LIBS ion that CMakeLists.txt. Transitive dependencies are not
simplified by this approach, but I am not aware of any downside of
this: CMake should be smart enough to simplify them on its side.
And even if not, this shouldn't affect linking time.
Benefit of not relying on transitive dependencies is that build
system is more robust towards future changes. For example, if
bf_intern_opensubiv is no longer depends on OPENSUBDIV_LIBRARIES
and all such code is moved to bf_blenkernel this will not break
linking.
The not-so-trivial part is change to blender_add_lib (and its
version in Cycles). The complexity is caused by libraries being
provided as a single list argument which doesn't allow to use
different release and debug libraries on Windows. The idea is:
- Have every library prefixed as "optimized" or "debug" if
separation is needed (non-prefixed libraries will be considered
"generic").
- Loop through libraries passed to function and do simple parsing
which will look for "optimized" and "debug" words and specify
following library to corresponding category.
This isn't something particularly great. Alternative would be to
use target_link_libraries() directly, which sounds like more code
but which is more explicit and allows to have more flexibility
and control comparing to wrapper approach.
Tested the following configurations on Linux, macOS and Windows:
- make full debug developer
- make full release developer
- make lite debug developer
- make lite release developer
NOTE: Linux libraries needs to be compiled with D6641 applied,
otherwise, depending on configuration, it's possible to run into
duplicated zlib symbols error.
Differential Revision: https://developer.blender.org/D6642
2020-01-20 17:36:19 +00:00
|
|
|
endif()
|
|
|
|
set(next_library_mode "")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-04-14 13:18:44 +00:00
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-05-28 04:53:17 +00:00
|
|
|
# works fine without having the includes
|
|
|
|
# listed is helpful for IDE's (QtCreator/MSVC)
|
2020-03-01 15:16:54 +00:00
|
|
|
blender_source_group("${name}" "${sources}")
|
2020-07-30 15:43:26 +00:00
|
|
|
blender_user_header_search_paths("${name}" "${includes}")
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2013-10-25 06:21:38 +00:00
|
|
|
list_assert_duplicates("${sources}")
|
|
|
|
list_assert_duplicates("${includes}")
|
|
|
|
# Not for system includes because they can resolve to the same path
|
|
|
|
# list_assert_duplicates("${includes_sys}")
|
|
|
|
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2011-05-28 04:53:17 +00:00
|
|
|
|
2010-11-05 04:18:53 +00:00
|
|
|
|
2016-07-14 09:11:33 +00:00
|
|
|
function(blender_add_lib_nolist
|
|
|
|
name
|
|
|
|
sources
|
|
|
|
includes
|
|
|
|
includes_sys
|
2019-04-16 04:11:27 +00:00
|
|
|
library_deps
|
2016-07-14 09:11:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
add_cc_flags_custom_test(${name} PARENT_SCOPE)
|
|
|
|
|
2019-04-16 04:11:27 +00:00
|
|
|
blender_add_lib__impl(${name} "${sources}" "${includes}" "${includes_sys}" "${library_deps}")
|
2016-07-14 09:11:33 +00:00
|
|
|
endfunction()
|
|
|
|
|
2015-06-16 23:16:17 +00:00
|
|
|
function(blender_add_lib
|
2010-06-06 13:32:58 +00:00
|
|
|
name
|
|
|
|
sources
|
2011-05-31 01:15:44 +00:00
|
|
|
includes
|
2015-06-16 23:16:17 +00:00
|
|
|
includes_sys
|
2019-04-16 04:11:27 +00:00
|
|
|
library_deps
|
2015-06-16 23:16:17 +00:00
|
|
|
)
|
2006-11-17 02:27:12 +00:00
|
|
|
|
2016-07-14 09:11:33 +00:00
|
|
|
add_cc_flags_custom_test(${name} PARENT_SCOPE)
|
|
|
|
|
2019-04-16 04:11:27 +00:00
|
|
|
blender_add_lib__impl(${name} "${sources}" "${includes}" "${includes_sys}" "${library_deps}")
|
2006-11-17 02:27:12 +00:00
|
|
|
|
2010-12-06 10:56:37 +00:00
|
|
|
set_property(GLOBAL APPEND PROPERTY BLENDER_LINK_LIBS ${name})
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
|
|
|
|
2021-01-11 10:29:30 +00:00
|
|
|
function(blender_add_test_suite)
|
2021-02-04 22:45:16 +00:00
|
|
|
if(ARGC LESS 1)
|
2021-01-11 10:29:30 +00:00
|
|
|
message(FATAL_ERROR "No arguments supplied to blender_add_test_suite()")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Parse the arguments
|
|
|
|
set(oneValueArgs TARGET SUITE_NAME)
|
|
|
|
set(multiValueArgs SOURCES)
|
|
|
|
cmake_parse_arguments(ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
|
|
|
|
# Figure out the release dir, as some tests need files from there.
|
|
|
|
GET_BLENDER_TEST_INSTALL_DIR(TEST_INSTALL_DIR)
|
|
|
|
if(APPLE)
|
|
|
|
set(_test_release_dir ${TEST_INSTALL_DIR}/Blender.app/Contents/Resources/${BLENDER_VERSION})
|
|
|
|
else()
|
|
|
|
if(WIN32 OR WITH_INSTALL_PORTABLE)
|
|
|
|
set(_test_release_dir ${TEST_INSTALL_DIR}/${BLENDER_VERSION})
|
|
|
|
else()
|
|
|
|
set(_test_release_dir ${TEST_INSTALL_DIR}/share/blender/${BLENDER_VERSION})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Define a test case with our custom gtest_add_tests() command.
|
|
|
|
include(GTest)
|
|
|
|
gtest_add_tests(
|
|
|
|
TARGET ${ARGS_TARGET}
|
|
|
|
SOURCES "${ARGS_SOURCES}"
|
|
|
|
TEST_PREFIX ${ARGS_SUITE_NAME}
|
|
|
|
WORKING_DIRECTORY "${TEST_INSTALL_DIR}"
|
|
|
|
EXTRA_ARGS
|
|
|
|
--test-assets-dir "${CMAKE_SOURCE_DIR}/../lib/tests"
|
|
|
|
--test-release-dir "${_test_release_dir}"
|
|
|
|
)
|
|
|
|
|
|
|
|
unset(_test_release_dir)
|
|
|
|
endfunction()
|
|
|
|
|
2020-09-15 09:16:35 +00:00
|
|
|
# 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).
|
2020-07-16 10:58:49 +00:00
|
|
|
function(blender_add_test_lib
|
|
|
|
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()
|
|
|
|
|
|
|
|
# This duplicates logic that's also in GTestTesting.cmake, macro BLENDER_SRC_GTEST_EX.
|
|
|
|
# TODO(Sybren): deduplicate after the general approach in D7649 has been approved.
|
|
|
|
LIST(APPEND includes
|
|
|
|
${CMAKE_SOURCE_DIR}/tests/gtests
|
|
|
|
)
|
|
|
|
LIST(APPEND includes_sys
|
|
|
|
${GLOG_INCLUDE_DIRS}
|
|
|
|
${GFLAGS_INCLUDE_DIRS}
|
|
|
|
${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}")
|
|
|
|
|
|
|
|
set_property(GLOBAL APPEND PROPERTY BLENDER_TEST_LIBS ${name})
|
2021-01-11 10:29:30 +00:00
|
|
|
|
|
|
|
blender_add_test_suite(
|
|
|
|
TARGET blender_test
|
|
|
|
SUITE_NAME ${name}
|
|
|
|
SOURCES "${sources}"
|
|
|
|
)
|
2020-07-16 10:58:49 +00:00
|
|
|
endfunction()
|
|
|
|
|
2020-09-15 09:16:35 +00:00
|
|
|
|
|
|
|
# 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})
|
|
|
|
|
|
|
|
BLENDER_SRC_GTEST_EX(
|
|
|
|
NAME ${name}
|
|
|
|
SRC "${sources}"
|
|
|
|
EXTRA_LIBS "${library_deps}"
|
|
|
|
SKIP_ADD_TEST
|
|
|
|
)
|
|
|
|
|
2021-01-11 10:29:30 +00:00
|
|
|
blender_add_test_suite(
|
|
|
|
TARGET ${name}_test
|
|
|
|
SUITE_NAME ${name}
|
|
|
|
SOURCES "${sources}"
|
2020-09-15 09:16:35 +00:00
|
|
|
)
|
|
|
|
endfunction()
|
|
|
|
|
CMake: Add support of Ninja's pools to ease building on limited amount of RAM.
Many modern computers support a lot of threads (parrallel building
jobs), but are somewhat restricted in memory, when some building jobs
can require several GB each.
Ninja builder has pools, which extend the usual `-j X` make
parallelizing option, by allowing to specify different numbers of
parallel jobs for different targets.
This commit defines three pools, one for linking, one for usual compile,
and one for compiling some 'heavy' cpp libs, when a single file can
require GB of RAM in full debug builds.
Simply enabling WITH_NINJA_POOL_JOBS will try to set default sensible
values for those three pools based on your machine specifications, you
can then tweak further the values of NINJA_MAX_NUM_PARALLEL_ settings,
if you like.
On my system (8 cores, 16GB RAM), it allows to build a full debug with
all ASAN options build with roughly 7GB of RAM used at most, pretty much
as quickly as without that option (which would require up to 11GB of
available RAM at some points).
Review task: D4780.
2019-05-07 18:32:14 +00:00
|
|
|
# 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)
|
|
|
|
if(WITH_CYCLES)
|
|
|
|
list(APPEND _HEAVY_LIBS "cycles_device" "cycles_kernel")
|
|
|
|
endif()
|
|
|
|
if(WITH_LIBMV)
|
2020-08-03 08:29:13 +00:00
|
|
|
list(APPEND _HEAVY_LIBS "extern_ceres" "bf_intern_libmv")
|
CMake: Add support of Ninja's pools to ease building on limited amount of RAM.
Many modern computers support a lot of threads (parrallel building
jobs), but are somewhat restricted in memory, when some building jobs
can require several GB each.
Ninja builder has pools, which extend the usual `-j X` make
parallelizing option, by allowing to specify different numbers of
parallel jobs for different targets.
This commit defines three pools, one for linking, one for usual compile,
and one for compiling some 'heavy' cpp libs, when a single file can
require GB of RAM in full debug builds.
Simply enabling WITH_NINJA_POOL_JOBS will try to set default sensible
values for those three pools based on your machine specifications, you
can then tweak further the values of NINJA_MAX_NUM_PARALLEL_ settings,
if you like.
On my system (8 cores, 16GB RAM), it allows to build a full debug with
all ASAN options build with roughly 7GB of RAM used at most, pretty much
as quickly as without that option (which would require up to 11GB of
available RAM at some points).
Review task: D4780.
2019-05-07 18:32:14 +00:00
|
|
|
endif()
|
|
|
|
if(WITH_OPENVDB)
|
|
|
|
list(APPEND _HEAVY_LIBS "bf_intern_openvdb")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
foreach(TARGET ${_HEAVY_LIBS})
|
|
|
|
if(TARGET ${TARGET})
|
|
|
|
set_property(TARGET ${TARGET} PROPERTY JOB_POOL_COMPILE compile_heavy_job_pool)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2006-11-17 02:27:12 +00:00
|
|
|
|
2020-09-15 14:00:15 +00:00
|
|
|
# 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()
|
2018-05-31 17:50:30 +00:00
|
|
|
|
2020-09-15 14:00:15 +00:00
|
|
|
# Platform specific libraries for targets.
|
|
|
|
function(setup_platform_linker_libs
|
2015-06-16 23:16:17 +00:00
|
|
|
target
|
|
|
|
)
|
2018-11-23 10:24:04 +00:00
|
|
|
# jemalloc must be early in the list, to be before pthread (see T57998)
|
|
|
|
if(WITH_MEM_JEMALLOC)
|
|
|
|
target_link_libraries(${target} ${JEMALLOC_LIBRARIES})
|
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2010-11-21 13:41:43 +00:00
|
|
|
if(WIN32 AND NOT UNIX)
|
2011-06-18 14:12:54 +00:00
|
|
|
target_link_libraries(${target} ${PTHREADS_LIBRARIES})
|
2010-11-21 13:41:43 +00:00
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2019-10-28 14:32:33 +00:00
|
|
|
# target_link_libraries(${target} ${PLATFORM_LINKLIBS} ${CMAKE_DL_LIBS})
|
2016-10-25 08:22:03 +00:00
|
|
|
target_link_libraries(${target} ${PLATFORM_LINKLIBS})
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
|
|
|
|
2011-10-01 18:29:40 +00:00
|
|
|
macro(TEST_SSE_SUPPORT
|
|
|
|
_sse_flags
|
|
|
|
_sse2_flags)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2010-08-11 08:23:48 +00:00
|
|
|
include(CheckCSourceRuns)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2010-12-16 12:48:30 +00:00
|
|
|
# message(STATUS "Detecting SSE support")
|
2011-10-02 16:43:39 +00:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang"))
|
2011-10-01 18:29:40 +00:00
|
|
|
set(${_sse_flags} "-msse")
|
|
|
|
set(${_sse2_flags} "-msse2")
|
2010-07-04 18:40:59 +00:00
|
|
|
elseif(MSVC)
|
2013-06-21 12:33:19 +00:00
|
|
|
# x86_64 has this auto enabled
|
|
|
|
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
|
|
|
|
set(${_sse_flags} "")
|
|
|
|
set(${_sse2_flags} "")
|
|
|
|
else()
|
|
|
|
set(${_sse_flags} "/arch:SSE")
|
|
|
|
set(${_sse2_flags} "/arch:SSE2")
|
|
|
|
endif()
|
2011-09-30 16:37:46 +00:00
|
|
|
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
|
2011-10-02 17:16:28 +00:00
|
|
|
set(${_sse_flags} "") # icc defaults to -msse
|
2018-04-02 14:11:11 +00:00
|
|
|
set(${_sse2_flags} "") # icc defaults to -msse2
|
2011-09-30 16:37:46 +00:00
|
|
|
else()
|
2011-10-01 18:29:40 +00:00
|
|
|
message(WARNING "SSE flags for this compiler: '${CMAKE_C_COMPILER_ID}' not known")
|
2011-10-01 19:52:33 +00:00
|
|
|
set(${_sse_flags})
|
|
|
|
set(${_sse2_flags})
|
2011-10-01 18:29:40 +00:00
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-10-01 19:52:33 +00:00
|
|
|
set(CMAKE_REQUIRED_FLAGS "${${_sse_flags}} ${${_sse2_flags}}")
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-10-01 19:52:33 +00:00
|
|
|
if(NOT DEFINED SUPPORT_SSE_BUILD)
|
|
|
|
# result cached
|
2010-12-21 03:32:51 +00:00
|
|
|
check_c_source_runs("
|
|
|
|
#include <xmmintrin.h>
|
2011-10-01 19:52:33 +00:00
|
|
|
int main(void) { __m128 v = _mm_setzero_ps(); return 0; }"
|
2010-12-21 03:32:51 +00:00
|
|
|
SUPPORT_SSE_BUILD)
|
2011-09-30 15:51:58 +00:00
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-10-01 19:52:33 +00:00
|
|
|
if(NOT DEFINED SUPPORT_SSE2_BUILD)
|
|
|
|
# result cached
|
2010-12-21 03:32:51 +00:00
|
|
|
check_c_source_runs("
|
|
|
|
#include <emmintrin.h>
|
2011-10-01 19:52:33 +00:00
|
|
|
int main(void) { __m128d v = _mm_setzero_pd(); return 0; }"
|
2010-12-21 03:32:51 +00:00
|
|
|
SUPPORT_SSE2_BUILD)
|
2010-08-11 08:23:48 +00:00
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-10-01 19:52:33 +00:00
|
|
|
unset(CMAKE_REQUIRED_FLAGS)
|
2010-07-04 18:40:59 +00:00
|
|
|
endmacro()
|
|
|
|
|
2021-02-14 03:16:39 +00:00
|
|
|
macro(TEST_NEON_SUPPORT)
|
2021-03-01 18:15:29 +00:00
|
|
|
if(NOT DEFINED SUPPORT_NEON_BUILD)
|
|
|
|
include(CheckCXXSourceCompiles)
|
|
|
|
check_cxx_source_compiles(
|
|
|
|
"#include <arm_neon.h>
|
|
|
|
int main() {return vaddvq_s32(vdupq_n_s32(1));}"
|
|
|
|
SUPPORT_NEON_BUILD)
|
|
|
|
endif()
|
2021-02-14 03:16:39 +00:00
|
|
|
endmacro()
|
|
|
|
|
2016-01-14 07:57:58 +00:00
|
|
|
# Only print message if running CMake first time
|
|
|
|
macro(message_first_run)
|
|
|
|
if(FIRST_RUN)
|
|
|
|
message(${ARGV})
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2010-10-24 03:57:07 +00:00
|
|
|
# when we have warnings as errors applied globally this
|
2021-06-22 17:42:32 +00:00
|
|
|
# needs to be removed for some external libs which we don't maintain.
|
2010-10-24 03:57:07 +00:00
|
|
|
|
|
|
|
# utility macro
|
2011-10-27 07:26:41 +00:00
|
|
|
macro(remove_cc_flag
|
2015-06-23 04:25:24 +00:00
|
|
|
_flag)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2015-06-23 04:25:24 +00:00
|
|
|
foreach(flag ${ARGV})
|
|
|
|
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
|
|
|
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
|
|
|
|
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
|
|
|
|
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
|
|
|
|
string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2015-06-23 04:25:24 +00:00
|
|
|
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
|
|
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
|
|
|
|
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
|
|
|
|
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
|
|
|
|
string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
|
|
|
|
endforeach()
|
|
|
|
unset(flag)
|
2010-12-08 08:43:06 +00:00
|
|
|
|
2010-10-24 03:57:07 +00:00
|
|
|
endmacro()
|
2010-12-08 08:43:06 +00:00
|
|
|
|
2018-06-22 12:29:13 +00:00
|
|
|
macro(add_c_flag
|
2011-10-27 07:26:41 +00:00
|
|
|
flag)
|
|
|
|
|
2020-11-05 23:29:04 +00:00
|
|
|
string(APPEND CMAKE_C_FLAGS " ${flag}")
|
|
|
|
string(APPEND CMAKE_CXX_FLAGS " ${flag}")
|
2011-10-27 07:26:41 +00:00
|
|
|
endmacro()
|
|
|
|
|
2018-06-22 12:07:55 +00:00
|
|
|
macro(add_cxx_flag
|
|
|
|
flag)
|
|
|
|
|
2020-11-05 23:29:04 +00:00
|
|
|
string(APPEND CMAKE_CXX_FLAGS " ${flag}")
|
2018-06-22 12:07:55 +00:00
|
|
|
endmacro()
|
|
|
|
|
2010-10-24 03:57:07 +00:00
|
|
|
macro(remove_strict_flags)
|
2010-12-08 08:43:06 +00:00
|
|
|
|
2010-10-24 03:57:07 +00:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC)
|
2015-06-23 04:25:24 +00:00
|
|
|
remove_cc_flag(
|
|
|
|
"-Wstrict-prototypes"
|
|
|
|
"-Wmissing-prototypes"
|
2016-04-22 08:59:15 +00:00
|
|
|
"-Wmissing-declarations"
|
2015-06-23 04:33:17 +00:00
|
|
|
"-Wmissing-format-attribute"
|
|
|
|
"-Wunused-local-typedefs"
|
2015-06-23 04:25:24 +00:00
|
|
|
"-Wunused-macros"
|
2015-06-23 04:33:17 +00:00
|
|
|
"-Wunused-parameter"
|
2015-06-23 04:25:24 +00:00
|
|
|
"-Wwrite-strings"
|
|
|
|
"-Wredundant-decls"
|
|
|
|
"-Wundef"
|
|
|
|
"-Wshadow"
|
|
|
|
"-Wdouble-promotion"
|
|
|
|
"-Wold-style-definition"
|
|
|
|
"-Werror=[^ ]+"
|
|
|
|
"-Werror"
|
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-10-27 07:26:41 +00:00
|
|
|
# negate flags implied by '-Wall'
|
2018-06-22 12:29:13 +00:00
|
|
|
add_c_flag("${C_REMOVE_STRICT_FLAGS}")
|
2018-06-22 12:07:55 +00:00
|
|
|
add_cxx_flag("${CXX_REMOVE_STRICT_FLAGS}")
|
2010-10-24 03:57:07 +00:00
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2013-12-02 00:36:33 +00:00
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
2015-06-23 04:25:24 +00:00
|
|
|
remove_cc_flag(
|
|
|
|
"-Wunused-parameter"
|
|
|
|
"-Wunused-variable"
|
|
|
|
"-Werror=[^ ]+"
|
|
|
|
"-Werror"
|
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2013-03-14 07:25:54 +00:00
|
|
|
# negate flags implied by '-Wall'
|
2018-06-22 12:29:13 +00:00
|
|
|
add_c_flag("${C_REMOVE_STRICT_FLAGS}")
|
2018-06-22 12:07:55 +00:00
|
|
|
add_cxx_flag("${CXX_REMOVE_STRICT_FLAGS}")
|
2012-06-28 12:32:06 +00:00
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2010-10-24 03:57:07 +00:00
|
|
|
if(MSVC)
|
2019-09-09 20:11:52 +00:00
|
|
|
remove_cc_flag(/w34189) # Restore warn C4189 (unused variable) back to w4
|
2010-10-24 03:57:07 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
endmacro()
|
|
|
|
|
2015-03-27 10:55:58 +00:00
|
|
|
macro(remove_extra_strict_flags)
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCC)
|
2015-06-23 04:25:24 +00:00
|
|
|
remove_cc_flag(
|
|
|
|
"-Wunused-parameter"
|
|
|
|
)
|
2015-03-27 10:55:58 +00:00
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2015-03-27 10:55:58 +00:00
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
2015-06-23 04:25:24 +00:00
|
|
|
remove_cc_flag(
|
|
|
|
"-Wunused-parameter"
|
|
|
|
)
|
2015-03-27 10:55:58 +00:00
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2015-03-27 10:55:58 +00:00
|
|
|
if(MSVC)
|
|
|
|
# TODO
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2011-10-23 17:52:20 +00:00
|
|
|
# note, we can only append flags on a single file so we need to negate the options.
|
2021-06-22 17:42:32 +00:00
|
|
|
# at the moment we can't shut up ffmpeg deprecations, so use this, but will
|
2011-10-23 17:52:20 +00:00
|
|
|
# probably add more removals here.
|
2018-06-22 12:40:00 +00:00
|
|
|
macro(remove_strict_c_flags_file
|
2011-10-23 17:52:20 +00:00
|
|
|
filenames)
|
|
|
|
foreach(_SOURCE ${ARGV})
|
2013-07-15 08:26:16 +00:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC OR
|
2018-06-25 05:30:00 +00:00
|
|
|
(CMAKE_C_COMPILER_ID MATCHES "Clang"))
|
2011-10-23 17:52:20 +00:00
|
|
|
set_source_files_properties(${_SOURCE}
|
|
|
|
PROPERTIES
|
2018-06-22 12:17:55 +00:00
|
|
|
COMPILE_FLAGS "${C_REMOVE_STRICT_FLAGS}"
|
2011-10-23 17:52:20 +00:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
if(MSVC)
|
|
|
|
# TODO
|
|
|
|
endif()
|
2012-10-21 05:46:41 +00:00
|
|
|
endforeach()
|
2011-10-23 17:52:20 +00:00
|
|
|
unset(_SOURCE)
|
2018-06-22 12:40:00 +00:00
|
|
|
endmacro()
|
2011-10-23 17:52:20 +00:00
|
|
|
|
2018-06-22 12:40:00 +00:00
|
|
|
macro(remove_strict_cxx_flags_file
|
|
|
|
filenames)
|
|
|
|
remove_strict_c_flags_file(${filenames} ${ARHV})
|
|
|
|
foreach(_SOURCE ${ARGV})
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCC OR
|
2018-06-25 05:30:00 +00:00
|
|
|
(CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
2018-06-22 12:40:00 +00:00
|
|
|
set_source_files_properties(${_SOURCE}
|
|
|
|
PROPERTIES
|
2018-06-25 05:30:00 +00:00
|
|
|
COMPILE_FLAGS "${CXX_REMOVE_STRICT_FLAGS}"
|
2018-06-22 12:40:00 +00:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
if(MSVC)
|
|
|
|
# TODO
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
unset(_SOURCE)
|
2011-10-23 17:52:20 +00:00
|
|
|
endmacro()
|
|
|
|
|
2016-05-18 21:36:32 +00:00
|
|
|
# External libs may need 'signed char' to be default.
|
|
|
|
macro(remove_cc_flag_unsigned_char)
|
2018-03-04 06:22:05 +00:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC OR
|
|
|
|
(CMAKE_C_COMPILER_ID MATCHES "Clang") OR
|
|
|
|
(CMAKE_C_COMPILER_ID MATCHES "Intel"))
|
2016-05-18 21:36:32 +00:00
|
|
|
remove_cc_flag("-funsigned-char")
|
|
|
|
elseif(MSVC)
|
|
|
|
remove_cc_flag("/J")
|
|
|
|
else()
|
|
|
|
message(WARNING
|
|
|
|
"Compiler '${CMAKE_C_COMPILER_ID}' failed to disable 'unsigned char' flag."
|
|
|
|
"Build files need updating."
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endmacro()
|
2011-10-23 17:52:20 +00:00
|
|
|
|
2015-06-16 23:16:17 +00:00
|
|
|
function(ADD_CHECK_C_COMPILER_FLAG
|
2010-12-16 09:55:35 +00:00
|
|
|
_CFLAGS
|
2010-12-21 03:32:51 +00:00
|
|
|
_CACHE_VAR
|
2015-06-16 23:16:17 +00:00
|
|
|
_FLAG
|
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-02-17 11:38:02 +00:00
|
|
|
include(CheckCCompilerFlag)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-02-17 11:38:02 +00:00
|
|
|
CHECK_C_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
|
2010-12-21 03:32:51 +00:00
|
|
|
if(${_CACHE_VAR})
|
2010-12-16 12:48:30 +00:00
|
|
|
# message(STATUS "Using CFLAG: ${_FLAG}")
|
2015-06-16 23:16:17 +00:00
|
|
|
set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}" PARENT_SCOPE)
|
2010-12-16 09:55:35 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "Unsupported CFLAG: ${_FLAG}")
|
|
|
|
endif()
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2010-12-16 09:55:35 +00:00
|
|
|
|
2015-06-16 23:16:17 +00:00
|
|
|
function(ADD_CHECK_CXX_COMPILER_FLAG
|
2010-12-16 09:55:35 +00:00
|
|
|
_CXXFLAGS
|
2010-12-21 03:32:51 +00:00
|
|
|
_CACHE_VAR
|
2015-06-16 23:16:17 +00:00
|
|
|
_FLAG
|
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2010-12-16 09:55:35 +00:00
|
|
|
include(CheckCXXCompilerFlag)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2010-12-21 03:32:51 +00:00
|
|
|
CHECK_CXX_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
|
|
|
|
if(${_CACHE_VAR})
|
2010-12-16 12:48:30 +00:00
|
|
|
# message(STATUS "Using CXXFLAG: ${_FLAG}")
|
2015-06-16 23:16:17 +00:00
|
|
|
set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}" PARENT_SCOPE)
|
2010-12-16 09:55:35 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "Unsupported CXXFLAG: ${_FLAG}")
|
|
|
|
endif()
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2010-08-02 16:23:58 +00:00
|
|
|
|
2014-11-16 11:57:42 +00:00
|
|
|
function(get_blender_version)
|
2015-02-25 07:15:54 +00:00
|
|
|
# extracts header vars and defines them in the parent scope:
|
|
|
|
#
|
|
|
|
# - BLENDER_VERSION (major.minor)
|
|
|
|
# - BLENDER_VERSION_MAJOR
|
|
|
|
# - BLENDER_VERSION_MINOR
|
Blender: change bugfix release versioning from a/b/c to .1/.2/.3
The file subversion is no longer used in the Python API or user interface,
and is now internal to Blender.
User interface, Python API and file I/O metadata now use more consistent
formatting for version numbers. Official releases use "2.83.0", "2.83.1",
and releases under development use "2.90.0 Alpha", "2.90.0 Beta".
Some Python add-ons may need to lower the Blender version in bl_info to
(2, 83, 0) or (2, 90, 0) if they used a subversion number higher than 0.
https://wiki.blender.org/wiki/Reference/Release_Notes/2.83/Python_API#Compatibility
This change is in preparation of LTS releases, and also brings us more
in line with semantic versioning.
Fixes T76058.
Differential Revision: https://developer.blender.org/D7748
2020-05-25 08:49:04 +00:00
|
|
|
# - BLENDER_VERSION_PATCH
|
2015-02-25 07:15:54 +00:00
|
|
|
# - BLENDER_VERSION_CYCLE (alpha, beta, rc, release)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-02-21 08:31:00 +00:00
|
|
|
# So cmake depends on BKE_blender.h, beware of inf-loops!
|
2016-04-24 12:42:41 +00:00
|
|
|
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender_version.h
|
|
|
|
${CMAKE_BINARY_DIR}/source/blender/blenkernel/BKE_blender_version.h.done)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2016-04-24 12:42:41 +00:00
|
|
|
file(STRINGS ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender_version.h _contents REGEX "^#define[ \t]+BLENDER_.*$")
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-02-21 08:31:00 +00:00
|
|
|
string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION[ \t]+([0-9]+).*" "\\1" _out_version "${_contents}")
|
Blender: change bugfix release versioning from a/b/c to .1/.2/.3
The file subversion is no longer used in the Python API or user interface,
and is now internal to Blender.
User interface, Python API and file I/O metadata now use more consistent
formatting for version numbers. Official releases use "2.83.0", "2.83.1",
and releases under development use "2.90.0 Alpha", "2.90.0 Beta".
Some Python add-ons may need to lower the Blender version in bl_info to
(2, 83, 0) or (2, 90, 0) if they used a subversion number higher than 0.
https://wiki.blender.org/wiki/Reference/Release_Notes/2.83/Python_API#Compatibility
This change is in preparation of LTS releases, and also brings us more
in line with semantic versioning.
Fixes T76058.
Differential Revision: https://developer.blender.org/D7748
2020-05-25 08:49:04 +00:00
|
|
|
string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_PATCH[ \t]+([0-9]+).*" "\\1" _out_version_patch "${_contents}")
|
2011-02-21 08:31:00 +00:00
|
|
|
string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CYCLE[ \t]+([a-z]+).*" "\\1" _out_version_cycle "${_contents}")
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-02-21 08:31:00 +00:00
|
|
|
if(NOT ${_out_version} MATCHES "[0-9]+")
|
|
|
|
message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION")
|
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
Blender: change bugfix release versioning from a/b/c to .1/.2/.3
The file subversion is no longer used in the Python API or user interface,
and is now internal to Blender.
User interface, Python API and file I/O metadata now use more consistent
formatting for version numbers. Official releases use "2.83.0", "2.83.1",
and releases under development use "2.90.0 Alpha", "2.90.0 Beta".
Some Python add-ons may need to lower the Blender version in bl_info to
(2, 83, 0) or (2, 90, 0) if they used a subversion number higher than 0.
https://wiki.blender.org/wiki/Reference/Release_Notes/2.83/Python_API#Compatibility
This change is in preparation of LTS releases, and also brings us more
in line with semantic versioning.
Fixes T76058.
Differential Revision: https://developer.blender.org/D7748
2020-05-25 08:49:04 +00:00
|
|
|
if(NOT ${_out_version_patch} MATCHES "[0-9]+")
|
|
|
|
message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_PATCH")
|
2011-02-21 08:31:00 +00:00
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-02-21 08:31:00 +00:00
|
|
|
if(NOT ${_out_version_cycle} MATCHES "[a-z]+")
|
|
|
|
message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CYCLE")
|
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2015-02-25 07:15:54 +00:00
|
|
|
math(EXPR _out_version_major "${_out_version} / 100")
|
|
|
|
math(EXPR _out_version_minor "${_out_version} % 100")
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2015-02-25 07:15:54 +00:00
|
|
|
# output vars
|
|
|
|
set(BLENDER_VERSION "${_out_version_major}.${_out_version_minor}" PARENT_SCOPE)
|
2015-02-25 07:19:39 +00:00
|
|
|
set(BLENDER_VERSION_MAJOR "${_out_version_major}" PARENT_SCOPE)
|
|
|
|
set(BLENDER_VERSION_MINOR "${_out_version_minor}" PARENT_SCOPE)
|
Blender: change bugfix release versioning from a/b/c to .1/.2/.3
The file subversion is no longer used in the Python API or user interface,
and is now internal to Blender.
User interface, Python API and file I/O metadata now use more consistent
formatting for version numbers. Official releases use "2.83.0", "2.83.1",
and releases under development use "2.90.0 Alpha", "2.90.0 Beta".
Some Python add-ons may need to lower the Blender version in bl_info to
(2, 83, 0) or (2, 90, 0) if they used a subversion number higher than 0.
https://wiki.blender.org/wiki/Reference/Release_Notes/2.83/Python_API#Compatibility
This change is in preparation of LTS releases, and also brings us more
in line with semantic versioning.
Fixes T76058.
Differential Revision: https://developer.blender.org/D7748
2020-05-25 08:49:04 +00:00
|
|
|
set(BLENDER_VERSION_PATCH "${_out_version_patch}" PARENT_SCOPE)
|
2015-02-25 07:15:54 +00:00
|
|
|
set(BLENDER_VERSION_CYCLE "${_out_version_cycle}" PARENT_SCOPE)
|
|
|
|
|
2014-11-16 11:57:42 +00:00
|
|
|
endfunction()
|
2011-05-23 14:56:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
# hacks to override initial project settings
|
2011-09-30 15:51:58 +00:00
|
|
|
# these macros must be called directly before/after project(Blender)
|
2011-05-23 14:56:14 +00:00
|
|
|
macro(blender_project_hack_pre)
|
|
|
|
# ------------------
|
|
|
|
# GCC -O3 HACK START
|
|
|
|
# needed because O3 can cause problems but
|
|
|
|
# allow the builder to set O3 manually after.
|
|
|
|
if(DEFINED CMAKE_C_FLAGS_RELEASE)
|
|
|
|
set(_reset_standard_cflags_rel OFF)
|
|
|
|
else()
|
|
|
|
set(_reset_standard_cflags_rel ON)
|
|
|
|
endif()
|
|
|
|
if(DEFINED CMAKE_CXX_FLAGS_RELEASE)
|
|
|
|
set(_reset_standard_cxxflags_rel OFF)
|
|
|
|
else()
|
|
|
|
set(_reset_standard_cxxflags_rel ON)
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
|
|
|
|
macro(blender_project_hack_post)
|
|
|
|
# ----------------
|
|
|
|
# GCC -O3 HACK END
|
|
|
|
if(_reset_standard_cflags_rel)
|
|
|
|
string(REGEX REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
|
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
|
|
|
|
mark_as_advanced(CMAKE_C_FLAGS_RELEASE)
|
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-05-23 14:56:14 +00:00
|
|
|
if(_reset_standard_cxxflags_rel)
|
|
|
|
string(REGEX REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "" FORCE)
|
|
|
|
mark_as_advanced(CMAKE_CXX_FLAGS_RELEASE)
|
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-05-23 14:56:14 +00:00
|
|
|
unset(_reset_standard_cflags_rel)
|
|
|
|
unset(_reset_standard_cxxflags_rel)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-05-23 14:56:14 +00:00
|
|
|
endmacro()
|
2011-11-07 15:53:40 +00:00
|
|
|
|
|
|
|
# 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.
|
2015-06-16 23:16:17 +00:00
|
|
|
function(delayed_install
|
2011-11-07 15:53:40 +00:00
|
|
|
base
|
|
|
|
files
|
|
|
|
destination)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-11-07 15:53:40 +00:00
|
|
|
foreach(f ${files})
|
2012-11-15 17:16:27 +00:00
|
|
|
if(IS_ABSOLUTE ${f})
|
|
|
|
set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_FILES ${f})
|
|
|
|
else()
|
|
|
|
set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_FILES ${base}/${f})
|
|
|
|
endif()
|
2011-11-07 15:53:40 +00:00
|
|
|
set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_DESTINATIONS ${destination})
|
|
|
|
endforeach()
|
2019-06-18 21:12:16 +00:00
|
|
|
unset(f)
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2011-11-07 15:53:40 +00:00
|
|
|
|
|
|
|
# note this is a function instead of a macro so that ${BUILD_TYPE} in targetdir
|
|
|
|
# does not get expanded in calling but is preserved
|
|
|
|
function(delayed_do_install
|
|
|
|
targetdir)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-11-07 15:53:40 +00:00
|
|
|
get_property(files GLOBAL PROPERTY DELAYED_INSTALL_FILES)
|
|
|
|
get_property(destinations GLOBAL PROPERTY DELAYED_INSTALL_DESTINATIONS)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-11-07 15:53:40 +00:00
|
|
|
if(files)
|
|
|
|
list(LENGTH files n)
|
|
|
|
math(EXPR n "${n}-1")
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2011-11-07 15:53:40 +00:00
|
|
|
foreach(i RANGE ${n})
|
|
|
|
list(GET files ${i} f)
|
|
|
|
list(GET destinations ${i} d)
|
2018-10-22 16:17:08 +00:00
|
|
|
if(NOT IS_ABSOLUTE ${d})
|
|
|
|
install(FILES ${f} DESTINATION ${targetdir}/${d})
|
|
|
|
else()
|
|
|
|
install(FILES ${f} DESTINATION ${d})
|
|
|
|
endif()
|
2011-11-07 15:53:40 +00:00
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2012-08-08 16:03:42 +00:00
|
|
|
|
2015-06-16 23:16:17 +00:00
|
|
|
function(data_to_c
|
|
|
|
file_from file_to
|
|
|
|
list_to_add
|
|
|
|
)
|
2012-08-08 16:03:42 +00:00
|
|
|
|
2012-08-11 12:26:43 +00:00
|
|
|
list(APPEND ${list_to_add} ${file_to})
|
2015-06-16 23:16:17 +00:00
|
|
|
set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
|
2012-08-08 16:03:42 +00:00
|
|
|
|
2012-08-11 16:25:31 +00:00
|
|
|
get_filename_component(_file_to_path ${file_to} PATH)
|
|
|
|
|
2012-08-11 12:26:43 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${file_to}
|
2012-08-11 16:25:31 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
|
2015-09-02 15:11:38 +00:00
|
|
|
COMMAND "$<TARGET_FILE:datatoc>" ${file_from} ${file_to}
|
2012-08-11 18:39:38 +00:00
|
|
|
DEPENDS ${file_from} datatoc)
|
2013-09-20 06:35:28 +00:00
|
|
|
|
|
|
|
set_source_files_properties(${file_to} PROPERTIES GENERATED TRUE)
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2012-08-08 16:03:42 +00:00
|
|
|
|
2012-08-11 18:47:09 +00:00
|
|
|
|
2012-08-11 13:32:19 +00:00
|
|
|
# same as above but generates the var name and output automatic.
|
2015-06-16 23:16:17 +00:00
|
|
|
function(data_to_c_simple
|
|
|
|
file_from
|
|
|
|
list_to_add
|
|
|
|
)
|
2012-08-11 13:32:19 +00:00
|
|
|
|
2012-08-11 18:39:38 +00:00
|
|
|
# remove ../'s
|
|
|
|
get_filename_component(_file_from ${CMAKE_CURRENT_SOURCE_DIR}/${file_from} REALPATH)
|
|
|
|
get_filename_component(_file_to ${CMAKE_CURRENT_BINARY_DIR}/${file_from}.c REALPATH)
|
2012-08-11 13:32:19 +00:00
|
|
|
|
2012-08-11 18:39:38 +00:00
|
|
|
list(APPEND ${list_to_add} ${_file_to})
|
2018-10-16 19:54:59 +00:00
|
|
|
source_group(Generated FILES ${_file_to})
|
|
|
|
list(APPEND ${list_to_add} ${file_from})
|
2015-06-16 23:16:17 +00:00
|
|
|
set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
|
2012-08-11 13:32:19 +00:00
|
|
|
|
2012-08-11 16:25:31 +00:00
|
|
|
get_filename_component(_file_to_path ${_file_to} PATH)
|
|
|
|
|
2012-08-11 13:32:19 +00:00
|
|
|
add_custom_command(
|
2012-08-11 18:39:38 +00:00
|
|
|
OUTPUT ${_file_to}
|
2012-08-11 16:25:31 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
|
2015-09-02 15:11:38 +00:00
|
|
|
COMMAND "$<TARGET_FILE:datatoc>" ${_file_from} ${_file_to}
|
2012-08-11 18:39:38 +00:00
|
|
|
DEPENDS ${_file_from} datatoc)
|
2012-08-11 13:32:19 +00:00
|
|
|
|
2013-09-20 06:35:28 +00:00
|
|
|
set_source_files_properties(${_file_to} PROPERTIES GENERATED TRUE)
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2013-08-22 13:51:00 +00:00
|
|
|
|
2020-03-03 23:47:24 +00:00
|
|
|
# Function for converting pixmap directory to a '.png' and then a '.c' file.
|
2015-06-16 23:16:17 +00:00
|
|
|
function(data_to_c_simple_icons
|
2018-01-24 00:29:29 +00:00
|
|
|
path_from icon_prefix icon_names
|
2015-06-16 23:16:17 +00:00
|
|
|
list_to_add
|
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2014-01-13 12:47:33 +00:00
|
|
|
# Conversion steps
|
|
|
|
# path_from -> _file_from -> _file_to
|
|
|
|
# foo/*.dat -> foo.png -> foo.png.c
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2014-01-13 12:47:33 +00:00
|
|
|
get_filename_component(_path_from_abs ${path_from} ABSOLUTE)
|
|
|
|
# remove ../'s
|
|
|
|
get_filename_component(_file_from ${CMAKE_CURRENT_BINARY_DIR}/${path_from}.png REALPATH)
|
|
|
|
get_filename_component(_file_to ${CMAKE_CURRENT_BINARY_DIR}/${path_from}.png.c REALPATH)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2014-01-13 12:47:33 +00:00
|
|
|
list(APPEND ${list_to_add} ${_file_to})
|
2015-06-16 23:16:17 +00:00
|
|
|
set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2014-01-13 12:47:33 +00:00
|
|
|
get_filename_component(_file_to_path ${_file_to} PATH)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2018-01-24 00:29:29 +00:00
|
|
|
# Construct a list of absolute paths from input
|
|
|
|
set(_icon_files)
|
|
|
|
foreach(_var ${icon_names})
|
|
|
|
list(APPEND _icon_files "${_path_from_abs}/${icon_prefix}${_var}.dat")
|
|
|
|
endforeach()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2014-01-13 12:47:33 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${_file_from} ${_file_to}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
|
2019-10-28 14:32:33 +00:00
|
|
|
# COMMAND python3 ${CMAKE_SOURCE_DIR}/source/blender/datatoc/datatoc_icon.py ${_path_from_abs} ${_file_from}
|
2015-09-02 15:11:38 +00:00
|
|
|
COMMAND "$<TARGET_FILE:datatoc_icon>" ${_path_from_abs} ${_file_from}
|
|
|
|
COMMAND "$<TARGET_FILE:datatoc>" ${_file_from} ${_file_to}
|
2014-01-27 06:25:29 +00:00
|
|
|
DEPENDS
|
|
|
|
${_icon_files}
|
|
|
|
datatoc_icon
|
|
|
|
datatoc
|
|
|
|
# could be an arg but for now we only create icons depending on UI_icons.h
|
|
|
|
${CMAKE_SOURCE_DIR}/source/blender/editors/include/UI_icons.h
|
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2014-01-13 12:47:33 +00:00
|
|
|
set_source_files_properties(${_file_from} ${_file_to} PROPERTIES GENERATED TRUE)
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2014-01-13 12:47:33 +00:00
|
|
|
|
2013-08-26 12:16:23 +00:00
|
|
|
# XXX Not used for now...
|
2015-06-16 23:16:17 +00:00
|
|
|
function(svg_to_png
|
|
|
|
file_from
|
|
|
|
file_to
|
|
|
|
dpi
|
|
|
|
list_to_add
|
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2013-08-22 13:51:00 +00:00
|
|
|
# remove ../'s
|
|
|
|
get_filename_component(_file_from ${CMAKE_CURRENT_SOURCE_DIR}/${file_from} REALPATH)
|
|
|
|
get_filename_component(_file_to ${CMAKE_CURRENT_SOURCE_DIR}/${file_to} REALPATH)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2013-08-22 13:51:00 +00:00
|
|
|
list(APPEND ${list_to_add} ${_file_to})
|
2015-06-16 23:16:17 +00:00
|
|
|
set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2013-08-22 13:51:00 +00:00
|
|
|
find_program(INKSCAPE_EXE inkscape)
|
|
|
|
mark_as_advanced(INKSCAPE_EXE)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2013-08-22 13:51:00 +00:00
|
|
|
if(INKSCAPE_EXE)
|
2013-08-26 14:13:04 +00:00
|
|
|
if(APPLE)
|
|
|
|
# in OS X app bundle, the binary is a shim that doesn't take any
|
|
|
|
# command line arguments, replace it with the actual binary
|
|
|
|
string(REPLACE "MacOS/Inkscape" "Resources/bin/inkscape" INKSCAPE_REAL_EXE ${INKSCAPE_EXE})
|
|
|
|
if(EXISTS "${INKSCAPE_REAL_EXE}")
|
|
|
|
set(INKSCAPE_EXE ${INKSCAPE_REAL_EXE})
|
|
|
|
endif()
|
|
|
|
endif()
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2013-08-22 13:51:00 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${_file_to}
|
|
|
|
COMMAND ${INKSCAPE_EXE} ${_file_from} --export-dpi=${dpi} --without-gui --export-png=${_file_to}
|
|
|
|
DEPENDS ${_file_from} ${INKSCAPE_EXE}
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
message(WARNING "Inkscape not found, could not re-generate ${_file_to} from ${_file_from}!")
|
|
|
|
endif()
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2013-08-22 13:51:00 +00:00
|
|
|
|
2015-06-16 23:16:17 +00:00
|
|
|
function(msgfmt_simple
|
|
|
|
file_from
|
|
|
|
list_to_add
|
|
|
|
)
|
2013-11-08 20:44:48 +00:00
|
|
|
|
|
|
|
# remove ../'s
|
|
|
|
get_filename_component(_file_from_we ${file_from} NAME_WE)
|
|
|
|
|
|
|
|
get_filename_component(_file_from ${file_from} REALPATH)
|
|
|
|
get_filename_component(_file_to ${CMAKE_CURRENT_BINARY_DIR}/${_file_from_we}.mo REALPATH)
|
|
|
|
|
|
|
|
list(APPEND ${list_to_add} ${_file_to})
|
2015-06-16 23:16:17 +00:00
|
|
|
set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
|
2013-11-08 20:44:48 +00:00
|
|
|
|
|
|
|
get_filename_component(_file_to_path ${_file_to} PATH)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${_file_to}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
|
2015-09-02 15:11:38 +00:00
|
|
|
COMMAND "$<TARGET_FILE:msgfmt>" ${_file_from} ${_file_to}
|
2014-06-16 07:21:33 +00:00
|
|
|
DEPENDS msgfmt ${_file_from})
|
2013-11-08 20:44:48 +00:00
|
|
|
|
|
|
|
set_source_files_properties(${_file_to} PROPERTIES GENERATED TRUE)
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2013-11-08 20:44:48 +00:00
|
|
|
|
2015-06-16 23:16:17 +00:00
|
|
|
function(find_python_package
|
|
|
|
package
|
2020-12-14 15:40:00 +00:00
|
|
|
relative_include_dir
|
2015-06-16 23:16:17 +00:00
|
|
|
)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2014-07-28 14:42:30 +00:00
|
|
|
string(TOUPPER ${package} _upper_package)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2014-07-28 14:42:30 +00:00
|
|
|
# set but invalid
|
|
|
|
if((NOT ${PYTHON_${_upper_package}_PATH} STREQUAL "") AND
|
|
|
|
(NOT ${PYTHON_${_upper_package}_PATH} MATCHES NOTFOUND))
|
|
|
|
# if(NOT EXISTS "${PYTHON_${_upper_package}_PATH}/${package}")
|
|
|
|
# message(WARNING "PYTHON_${_upper_package}_PATH is invalid, ${package} not found in '${PYTHON_${_upper_package}_PATH}' "
|
|
|
|
# "WITH_PYTHON_INSTALL_${_upper_package} option will be ignored when installing python")
|
|
|
|
# set(WITH_PYTHON_INSTALL${_upper_package} OFF)
|
|
|
|
# endif()
|
|
|
|
# not set, so initialize
|
|
|
|
else()
|
|
|
|
string(REPLACE "." ";" _PY_VER_SPLIT "${PYTHON_VERSION}")
|
|
|
|
list(GET _PY_VER_SPLIT 0 _PY_VER_MAJOR)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2014-07-28 14:42:30 +00:00
|
|
|
# re-cache
|
|
|
|
unset(PYTHON_${_upper_package}_PATH CACHE)
|
|
|
|
find_path(PYTHON_${_upper_package}_PATH
|
|
|
|
NAMES
|
|
|
|
${package}
|
|
|
|
HINTS
|
2017-08-18 06:24:12 +00:00
|
|
|
"${PYTHON_LIBPATH}/"
|
2014-07-28 14:42:30 +00:00
|
|
|
"${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
|
|
|
|
"${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
|
|
|
|
PATH_SUFFIXES
|
|
|
|
site-packages
|
|
|
|
dist-packages
|
2017-11-30 06:56:01 +00:00
|
|
|
vendor-packages
|
2021-02-04 22:45:16 +00:00
|
|
|
NO_DEFAULT_PATH
|
|
|
|
DOC
|
|
|
|
"Path to python site-packages or dist-packages containing '${package}' module"
|
2014-07-28 14:42:30 +00:00
|
|
|
)
|
2020-12-14 15:40:00 +00:00
|
|
|
mark_as_advanced(PYTHON_${_upper_package}_PATH)
|
2019-04-17 04:35:54 +00:00
|
|
|
|
2019-02-13 21:43:44 +00:00
|
|
|
if(NOT EXISTS "${PYTHON_${_upper_package}_PATH}")
|
2016-01-17 05:01:32 +00:00
|
|
|
message(WARNING
|
|
|
|
"Python package '${package}' path could not be found in:\n"
|
|
|
|
"'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/${package}', "
|
|
|
|
"'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/${package}', "
|
|
|
|
"'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/${package}', "
|
|
|
|
"'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/${package}', "
|
2017-11-30 06:56:01 +00:00
|
|
|
"'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/vendor-packages/${package}', "
|
|
|
|
"'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/vendor-packages/${package}', "
|
2016-01-17 05:01:32 +00:00
|
|
|
"\n"
|
|
|
|
"The 'WITH_PYTHON_INSTALL_${_upper_package}' option will be ignored when installing Python.\n"
|
|
|
|
"The build will be usable, only add-ons that depend on this package won't be functional."
|
|
|
|
)
|
2015-06-16 23:16:17 +00:00
|
|
|
set(WITH_PYTHON_INSTALL_${_upper_package} OFF PARENT_SCOPE)
|
2014-07-28 14:42:30 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "${package} found at '${PYTHON_${_upper_package}_PATH}'")
|
2021-01-13 02:15:22 +00:00
|
|
|
|
2020-12-14 15:40:00 +00:00
|
|
|
if(NOT "${relative_include_dir}" STREQUAL "")
|
|
|
|
set(_relative_include_dir "${package}/${relative_include_dir}")
|
|
|
|
unset(PYTHON_${_upper_package}_INCLUDE_DIRS CACHE)
|
|
|
|
find_path(PYTHON_${_upper_package}_INCLUDE_DIRS
|
|
|
|
NAMES
|
|
|
|
"${_relative_include_dir}"
|
|
|
|
HINTS
|
|
|
|
"${PYTHON_LIBPATH}/"
|
|
|
|
"${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
|
|
|
|
"${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
|
|
|
|
PATH_SUFFIXES
|
|
|
|
"site-packages/"
|
|
|
|
"dist-packages/"
|
|
|
|
"vendor-packages/"
|
|
|
|
NO_DEFAULT_PATH
|
|
|
|
DOC
|
|
|
|
"Path to python site-packages or dist-packages containing '${package}' module header files"
|
|
|
|
)
|
|
|
|
mark_as_advanced(PYTHON_${_upper_package}_INCLUDE_DIRS)
|
|
|
|
|
|
|
|
if(NOT EXISTS "${PYTHON_${_upper_package}_INCLUDE_DIRS}")
|
|
|
|
message(WARNING
|
|
|
|
"Python package '${package}' include dir path could not be found in:\n"
|
|
|
|
"'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/${_relative_include_dir}', "
|
|
|
|
"'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/${_relative_include_dir}', "
|
|
|
|
"'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/${_relative_include_dir}', "
|
|
|
|
"'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/${_relative_include_dir}', "
|
|
|
|
"'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/vendor-packages/${_relative_include_dir}', "
|
|
|
|
"'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/vendor-packages/${_relative_include_dir}', "
|
|
|
|
"\n"
|
|
|
|
"The 'WITH_PYTHON_${_upper_package}' option will be disabled.\n"
|
|
|
|
"The build will be usable, only add-ons that depend on this package won't be functional."
|
|
|
|
)
|
|
|
|
set(WITH_PYTHON_${_upper_package} OFF PARENT_SCOPE)
|
|
|
|
else()
|
|
|
|
set(_temp "${PYTHON_${_upper_package}_INCLUDE_DIRS}/${package}/${relative_include_dir}")
|
|
|
|
unset(PYTHON_${_upper_package}_INCLUDE_DIRS CACHE)
|
|
|
|
set(PYTHON_${_upper_package}_INCLUDE_DIRS "${_temp}"
|
|
|
|
CACHE PATH "Path to the include directory of the ${package} module")
|
|
|
|
|
|
|
|
message(STATUS "${package} include files found at '${PYTHON_${_upper_package}_INCLUDE_DIRS}'")
|
|
|
|
endif()
|
|
|
|
endif()
|
2014-07-28 14:42:30 +00:00
|
|
|
endif()
|
2016-01-17 05:01:32 +00:00
|
|
|
endif()
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2014-11-16 11:57:42 +00:00
|
|
|
|
|
|
|
# like Python's 'print(dir())'
|
2015-06-16 23:16:17 +00:00
|
|
|
function(print_all_vars)
|
2014-11-16 11:57:42 +00:00
|
|
|
get_cmake_property(_vars VARIABLES)
|
|
|
|
foreach(_var ${_vars})
|
|
|
|
message("${_var}=${${_var}}")
|
|
|
|
endforeach()
|
2015-06-16 23:16:17 +00:00
|
|
|
endfunction()
|
2016-07-18 13:16:45 +00:00
|
|
|
|
|
|
|
macro(openmp_delayload
|
|
|
|
projectname
|
|
|
|
)
|
2022-01-28 03:08:11 +00:00
|
|
|
if(MSVC)
|
|
|
|
if(WITH_OPENMP)
|
|
|
|
if(MSVC_CLANG)
|
|
|
|
set(OPENMP_DLL_NAME "libomp")
|
|
|
|
elseif(MSVC_VERSION EQUAL 1800)
|
|
|
|
set(OPENMP_DLL_NAME "vcomp120")
|
|
|
|
else()
|
|
|
|
set(OPENMP_DLL_NAME "vcomp140")
|
2017-10-30 01:58:44 +00:00
|
|
|
endif()
|
2022-01-28 03:08:11 +00:00
|
|
|
set_property(TARGET ${projectname} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib")
|
|
|
|
set_property(TARGET ${projectname} APPEND_STRING PROPERTY LINK_FLAGS_DEBUG " /DELAYLOAD:${OPENMP_DLL_NAME}d.dll delayimp.lib")
|
|
|
|
set_property(TARGET ${projectname} APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib")
|
|
|
|
set_property(TARGET ${projectname} APPEND_STRING PROPERTY LINK_FLAGS_MINSIZEREL " /DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib")
|
2017-10-30 01:58:44 +00:00
|
|
|
endif()
|
2022-01-28 03:08:11 +00:00
|
|
|
endif()
|
2016-07-18 13:16:45 +00:00
|
|
|
endmacro()
|
2016-08-31 12:26:05 +00:00
|
|
|
|
2020-02-07 14:27:40 +00:00
|
|
|
macro(set_and_warn_dependency
|
2020-03-03 23:47:24 +00:00
|
|
|
_dependency _setting _val)
|
|
|
|
# when $_dependency is disabled, forces $_setting = $_val
|
|
|
|
if(NOT ${${_dependency}} AND ${${_setting}})
|
|
|
|
message(STATUS "'${_dependency}' is disabled: forcing 'set(${_setting} ${_val})'")
|
|
|
|
set(${_setting} ${_val})
|
|
|
|
endif()
|
2020-02-07 14:27:40 +00:00
|
|
|
endmacro()
|
|
|
|
|
2020-02-21 05:09:14 +00:00
|
|
|
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}")
|
2020-10-16 08:05:58 +00:00
|
|
|
if(APPLE)
|
|
|
|
# Avoid searching for headers in frameworks (like Mono), and libraries in LIBDIR.
|
2020-10-19 13:15:44 +00:00
|
|
|
set(CMAKE_FIND_FRAMEWORK NEVER)
|
2020-10-16 08:05:58 +00:00
|
|
|
endif()
|
2020-02-21 05:09:14 +00:00
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(without_system_libs_end)
|
|
|
|
unset(CMAKE_IGNORE_PATH)
|
2020-10-16 08:05:58 +00:00
|
|
|
if(APPLE)
|
|
|
|
# FIRST is the default.
|
|
|
|
set(CMAKE_FIND_FRAMEWORK FIRST)
|
|
|
|
endif()
|
2020-02-21 05:09:14 +00:00
|
|
|
endmacro()
|