2020-10-28 14:43:16 +08:00
include ( CheckCXXCompilerFlag ) # for check_cxx_compiler_flag()
2022-09-23 18:52:56 +08:00
# Set cmake policy to recognize the Apple Clang compiler
2020-07-12 09:44:38 +08:00
# independently from the Clang compiler.
if ( POLICY CMP0025 )
cmake_policy ( SET CMP0025 NEW )
endif ( )
2013-12-23 02:01:39 +08:00
2019-05-29 17:02:10 +08:00
# function: list_append_cache(var [new_values ...])
# Like "list(APPEND ...)" but working for CACHE variables.
# -----------------------------------------------------------
function ( list_append_cache var )
set ( cur_value ${ ${var } } )
list ( APPEND cur_value ${ ARGN } )
get_property ( MYVAR_DOCSTRING CACHE ${ var } PROPERTY HELPSTRING )
set ( ${ var } "${cur_value}" CACHE STRING "${MYVAR_DOCSTRING}" FORCE )
endfunction ( )
# function: append_config_if_not_empty(TARGET_VARIABLE build_type)
# Auxiliary function used to merge configuration-specific flags into the
# global variables that will actually be send to cmake targets.
# -----------------------------------------------------------
function ( append_config_if_not_empty TARGET_VARIABLE_ build_type )
string ( TOUPPER "${build_type}" build_type_toupper )
set ( flags_variable_name "${TARGET_VARIABLE_}_${build_type_toupper}" )
set ( flags_ ${ ${flags_variable_name } } )
if ( NOT "${flags_}" STREQUAL "" )
2019-06-16 08:30:28 +08:00
if ( ${ build_type_toupper } STREQUAL "COMMON" )
2019-05-29 17:02:10 +08:00
# Special "COMMON" configuration type, just append without CMake expression:
list_append_cache ( ${ TARGET_VARIABLE_ } "${flags_}" )
else ( )
# Regular configuration type:
list_append_cache ( ${ TARGET_VARIABLE_ } "$<$<CONFIG:${build_type}>:${flags_}>" )
endif ( )
endif ( )
endfunction ( )
2013-12-23 02:01:39 +08:00
# Add install prefix to search path
list ( APPEND CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}" )
2019-05-29 17:02:10 +08:00
# Set up build types for MSVC and XCode
set ( GTSAM_CMAKE_CONFIGURATION_TYPES Debug Release Timing Profiling RelWithDebInfo MinSizeRel
C A C H E S T R I N G " B u i l d t y p e s a v a i l a b l e t o MSVC a n d X C o d e " )
mark_as_advanced ( FORCE GTSAM_CMAKE_CONFIGURATION_TYPES )
set ( CMAKE_CONFIGURATION_TYPES ${ GTSAM_CMAKE_CONFIGURATION_TYPES } CACHE STRING "Build configurations" FORCE )
2013-12-23 02:01:39 +08:00
# Default to Release mode
2016-02-25 03:01:19 +08:00
if ( NOT CMAKE_BUILD_TYPE AND NOT MSVC AND NOT XCODE_VERSION )
set ( GTSAM_CMAKE_BUILD_TYPE "Release" CACHE STRING
" C h o o s e t h e t y p e o f b u i l d , o p t i o n s a r e : N o n e D e b u g R e l e a s e T i m i n g P r o f i l i n g R e l W i t h D e b I n f o . " )
2016-05-14 00:18:18 +08:00
set ( CMAKE_BUILD_TYPE ${ GTSAM_CMAKE_BUILD_TYPE } CACHE STRING
" C h o o s e t h e t y p e o f b u i l d , o p t i o n s a r e : N o n e D e b u g R e l e a s e T i m i n g P r o f i l i n g R e l W i t h D e b I n f o . " F O R C E )
2013-12-23 02:01:39 +08:00
endif ( )
2019-05-29 17:02:10 +08:00
# Define all cache variables, to be populated below depending on the OS/compiler:
2021-01-23 02:21:09 +08:00
set ( GTSAM_COMPILE_OPTIONS_PRIVATE "" CACHE INTERNAL "(Do not edit) Private compiler flags for all build configurations." FORCE )
set ( GTSAM_COMPILE_OPTIONS_PUBLIC "" CACHE INTERNAL "(Do not edit) Public compiler flags (exported to user projects) for all build configurations." FORCE )
set ( GTSAM_COMPILE_DEFINITIONS_PRIVATE "" CACHE INTERNAL "(Do not edit) Private preprocessor macros for all build configurations." FORCE )
set ( GTSAM_COMPILE_DEFINITIONS_PUBLIC "" CACHE INTERNAL "(Do not edit) Public preprocessor macros for all build configurations." FORCE )
2019-05-29 17:02:10 +08:00
mark_as_advanced ( GTSAM_COMPILE_OPTIONS_PRIVATE )
mark_as_advanced ( GTSAM_COMPILE_OPTIONS_PUBLIC )
mark_as_advanced ( GTSAM_COMPILE_DEFINITIONS_PRIVATE )
mark_as_advanced ( GTSAM_COMPILE_DEFINITIONS_PUBLIC )
foreach ( build_type ${ GTSAM_CMAKE_CONFIGURATION_TYPES } )
string ( TOUPPER "${build_type}" build_type_toupper )
2021-01-23 02:21:09 +08:00
# Define empty cache variables for "public". "private" are created below.
2019-05-29 17:02:10 +08:00
set ( GTSAM_COMPILE_OPTIONS_PUBLIC_ ${ build_type_toupper } "" CACHE STRING "(User editable) Public compiler flags (exported to user projects) for `${build_type_toupper}` configuration." )
set ( GTSAM_COMPILE_DEFINITIONS_PUBLIC_ ${ build_type_toupper } "" CACHE STRING "(User editable) Public preprocessor macros for `${build_type_toupper}` configuration." )
endforeach ( )
# Common preprocessor macros for each configuration:
set ( GTSAM_COMPILE_DEFINITIONS_PRIVATE_DEBUG "_DEBUG;EIGEN_INITIALIZE_MATRICES_BY_NAN" CACHE STRING "(User editable) Private preprocessor macros for Debug configuration." )
set ( GTSAM_COMPILE_DEFINITIONS_PRIVATE_RELWITHDEBINFO "NDEBUG" CACHE STRING "(User editable) Private preprocessor macros for RelWithDebInfo configuration." )
set ( GTSAM_COMPILE_DEFINITIONS_PRIVATE_RELEASE "NDEBUG" CACHE STRING "(User editable) Private preprocessor macros for Release configuration." )
set ( GTSAM_COMPILE_DEFINITIONS_PRIVATE_PROFILING "NDEBUG" CACHE STRING "(User editable) Private preprocessor macros for Profiling configuration." )
set ( GTSAM_COMPILE_DEFINITIONS_PRIVATE_TIMING "NDEBUG;ENABLE_TIMING" CACHE STRING "(User editable) Private preprocessor macros for Timing configuration." )
2023-10-08 23:23:54 +08:00
mark_as_advanced ( GTSAM_COMPILE_DEFINITIONS_PRIVATE_DEBUG )
mark_as_advanced ( GTSAM_COMPILE_DEFINITIONS_PRIVATE_RELWITHDEBINFO )
mark_as_advanced ( GTSAM_COMPILE_DEFINITIONS_PRIVATE_RELEASE )
mark_as_advanced ( GTSAM_COMPILE_DEFINITIONS_PRIVATE_PROFILING )
mark_as_advanced ( GTSAM_COMPILE_DEFINITIONS_PRIVATE_TIMING )
2019-05-29 17:02:10 +08:00
if ( MSVC )
# Common to all configurations:
2019-07-11 20:27:09 +08:00
list_append_cache ( GTSAM_COMPILE_DEFINITIONS_PRIVATE
W I N D O W S _ L E A N _ A N D _ M E A N
N O M I N M A X
2023-02-06 03:01:24 +08:00
)
list_append_cache ( GTSAM_COMPILE_DEFINITIONS_PUBLIC
_ E N A B L E _ E X T E N D E D _ A L I G N E D _ S T O R A G E
)
2019-12-28 03:42:41 +08:00
# Avoid literally hundreds to thousands of warnings:
list_append_cache ( GTSAM_COMPILE_OPTIONS_PUBLIC
2022-09-23 18:52:56 +08:00
/ w d 4 2 6 7 # warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
2019-12-28 03:42:41 +08:00
)
2022-02-18 00:16:13 +08:00
add_compile_options ( /wd4005 )
add_compile_options ( /wd4101 )
add_compile_options ( /wd4834 )
2019-05-29 17:02:10 +08:00
endif ( )
# Other (non-preprocessor macros) compiler flags:
2016-02-25 03:01:19 +08:00
if ( MSVC )
2025-01-07 21:45:47 +08:00
set ( CMAKE_3_15 $< VERSION_LESS:${CMAKE_VERSION},3.15 > )
set ( CMAKE_3_25 $< VERSION_LESS:${CMAKE_VERSION},3.25 > )
2019-05-29 17:02:10 +08:00
# Common to all configurations, next for each configuration:
2025-01-09 12:54:44 +08:00
set ( GTSAM_COMPILE_OPTIONS_PRIVATE_COMMON /W3 /WX /GR /EHsc /MP CACHE STRING "(User editable) Private compiler flags for all configurations." )
2025-01-07 21:45:47 +08:00
set ( GTSAM_COMPILE_OPTIONS_PRIVATE_DEBUG $< ${CMAKE_3_15}:/MDd > $< ${CMAKE_3_25}:/Zi > /Ob0 /Od /RTC1 CACHE STRING "(User editable) Private compiler flags for Debug configuration." )
set ( GTSAM_COMPILE_OPTIONS_PRIVATE_RELWITHDEBINFO $< ${CMAKE_3_15}:/MD > /O2 $< ${CMAKE_3_25}:/Zi > CACHE STRING "(User editable) Private compiler flags for RelWithDebInfo configuration." )
set ( GTSAM_COMPILE_OPTIONS_PRIVATE_RELEASE $< ${CMAKE_3_15}:/MD > /O2 CACHE STRING "(User editable) Private compiler flags for Release configuration." )
set ( GTSAM_COMPILE_OPTIONS_PRIVATE_PROFILING $< ${CMAKE_3_15}:/MD > /O2 $< ${CMAKE_3_25}:/Zi > CACHE STRING "(User editable) Private compiler flags for Profiling configuration." )
set ( GTSAM_COMPILE_OPTIONS_PRIVATE_TIMING $< ${CMAKE_3_15}:/MD > /O2 CACHE STRING "(User editable) Private compiler flags for Timing configuration." )
2019-05-29 17:02:10 +08:00
else ( )
# Common to all configurations, next for each configuration:
2020-07-27 05:35:11 +08:00
2020-10-28 14:43:16 +08:00
if ( NOT MSVC )
check_cxx_compiler_flag ( -Wsuggest-override COMPILER_HAS_WSUGGEST_OVERRIDE )
check_cxx_compiler_flag ( -Wmissing COMPILER_HAS_WMISSING_OVERRIDE )
if ( COMPILER_HAS_WSUGGEST_OVERRIDE )
set ( flag_override_ -Wsuggest-override ) # -Werror=suggest-override: Add again someday
elseif ( COMPILER_HAS_WMISSING_OVERRIDE )
set ( flag_override_ -Wmissing-override ) # -Werror=missing-override: Add again someday
endif ( )
2020-07-27 05:35:11 +08:00
endif ( )
2020-07-26 14:41:57 +08:00
set ( GTSAM_COMPILE_OPTIONS_PRIVATE_COMMON
2025-01-09 12:54:44 +08:00
- W e r r o r # Enable warnings as errors
2020-07-26 14:41:57 +08:00
- W a l l # Enable common warnings
2025-01-09 12:54:44 +08:00
- W p e d a n t i c # Enable pedantic warnings
$ < $ < C O M P I L E _ L A N G U A G E : C X X > : - W e x t r a - W n o - u n u s e d - p a r a m e t e r > # Enable extra warnings, but ignore no-unused-parameter (as we ifdef out chunks of code)
$ < $ < C X X _ C O M P I L E R _ I D : G N U > : - W r e t u r n - l o c a l - a d d r > # Error: return local address
$ < $ < C X X _ C O M P I L E R _ I D : C l a n g > : - W r e t u r n - s t a c k - a d d r e s s > # Error: return local address
$ < $ < C X X _ C O M P I L E R _ I D : C l a n g > : - W n o - w e a k - t e m p l a t e - v t a b l e s > # TODO(dellaert): don't know how to resolve
2023-02-12 04:32:50 +08:00
$ < $ < C X X _ C O M P I L E R _ I D : C l a n g > : - W n o - w e a k - v t a b l e s > # TODO(dellaert): don't know how to resolve
2025-01-09 12:54:44 +08:00
- W r e t u r n - t y p e # Error on missing return()
2020-07-26 14:41:57 +08:00
- W f o r m a t - W e r r o r = f o r m a t - s e c u r i t y # Error on wrong printf() arguments
2020-07-27 05:35:11 +08:00
$ < $ < C O M P I L E _ L A N G U A G E : C X X > : $ { f l a g _ o v e r r i d e _ } > # Enforce the use of the override keyword
2020-07-26 14:41:57 +08:00
#
C A C H E S T R I N G " ( U s e r e d i t a b l e ) P r i v a t e c o m p i l e r f l a g s f o r a l l c o n f i g u r a t i o n s . " )
2019-05-29 17:02:10 +08:00
set ( GTSAM_COMPILE_OPTIONS_PRIVATE_DEBUG -g -fno-inline CACHE STRING "(User editable) Private compiler flags for Debug configuration." )
set ( GTSAM_COMPILE_OPTIONS_PRIVATE_RELWITHDEBINFO -g -O3 CACHE STRING "(User editable) Private compiler flags for RelWithDebInfo configuration." )
set ( GTSAM_COMPILE_OPTIONS_PRIVATE_RELEASE -O3 CACHE STRING "(User editable) Private compiler flags for Release configuration." )
set ( GTSAM_COMPILE_OPTIONS_PRIVATE_PROFILING -O3 CACHE STRING "(User editable) Private compiler flags for Profiling configuration." )
set ( GTSAM_COMPILE_OPTIONS_PRIVATE_TIMING -g -O3 CACHE STRING "(User editable) Private compiler flags for Timing configuration." )
endif ( )
2023-10-08 23:23:54 +08:00
mark_as_advanced ( GTSAM_COMPILE_OPTIONS_PRIVATE_COMMON )
mark_as_advanced ( GTSAM_COMPILE_OPTIONS_PRIVATE_DEBUG )
mark_as_advanced ( GTSAM_COMPILE_OPTIONS_PRIVATE_RELWITHDEBINFO )
mark_as_advanced ( GTSAM_COMPILE_OPTIONS_PRIVATE_RELEASE )
mark_as_advanced ( GTSAM_COMPILE_OPTIONS_PRIVATE_PROFILING )
mark_as_advanced ( GTSAM_COMPILE_OPTIONS_PRIVATE_TIMING )
2023-01-20 14:33:32 +08:00
# Enable C++17:
2025-01-07 21:48:21 +08:00
set ( GTSAM_COMPILE_FEATURES_PUBLIC "cxx_std_17" CACHE STRING "CMake compile features property for all gtsam targets." )
# See: https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html
set ( CMAKE_CXX_EXTENSIONS OFF )
2013-12-23 02:01:39 +08:00
2019-05-29 17:02:10 +08:00
# Merge all user-defined flags into the variables that are to be actually used by CMake:
foreach ( build_type "common" ${ GTSAM_CMAKE_CONFIGURATION_TYPES } )
append_config_if_not_empty ( GTSAM_COMPILE_OPTIONS_PRIVATE ${ build_type } )
append_config_if_not_empty ( GTSAM_COMPILE_OPTIONS_PUBLIC ${ build_type } )
append_config_if_not_empty ( GTSAM_COMPILE_DEFINITIONS_PRIVATE ${ build_type } )
append_config_if_not_empty ( GTSAM_COMPILE_DEFINITIONS_PUBLIC ${ build_type } )
endforeach ( )
2024-12-19 01:30:33 +08:00
# Check if timing is enabled and add appropriate definition flag
if ( GTSAM_ENABLE_TIMING AND(NOT ${ CMAKE_BUILD_TYPE } EQUAL "Timing" ) )
message ( STATUS "Enabling timing for non-timing build" )
list_append_cache ( GTSAM_COMPILE_DEFINITIONS_PRIVATE "ENABLE_TIMING" )
endif ( )
2019-05-29 17:02:10 +08:00
# Linker flags:
2016-02-25 03:01:19 +08:00
set ( GTSAM_CMAKE_SHARED_LINKER_FLAGS_TIMING "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}" CACHE STRING "Linker flags during timing builds." )
set ( GTSAM_CMAKE_MODULE_LINKER_FLAGS_TIMING "${CMAKE_MODULE_LINKER_FLAGS_RELEASE}" CACHE STRING "Linker flags during timing builds." )
set ( GTSAM_CMAKE_EXE_LINKER_FLAGS_TIMING "${CMAKE_EXE_LINKER_FLAGS_RELEASE}" CACHE STRING "Linker flags during timing builds." )
set ( GTSAM_CMAKE_SHARED_LINKER_FLAGS_PROFILING "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}" CACHE STRING "Linker flags during profiling builds." )
set ( GTSAM_CMAKE_MODULE_LINKER_FLAGS_PROFILING "${CMAKE_MODULE_LINKER_FLAGS_RELEASE}" CACHE STRING "Linker flags during profiling builds." )
set ( GTSAM_CMAKE_EXE_LINKER_FLAGS_PROFILING "${CMAKE_EXE_LINKER_FLAGS_RELEASE}" CACHE STRING "Linker flags during profiling builds." )
2019-05-29 17:02:10 +08:00
mark_as_advanced ( GTSAM_CMAKE_EXE_LINKER_FLAGS_TIMING
2016-02-25 03:01:19 +08:00
G T S A M _ C M A K E _ S H A R E D _ L I N K E R _ F L A G S _ T I M I N G G T S A M _ C M A K E _ M O D U L E _ L I N K E R _ F L A G S _ T I M I N G
2019-05-29 17:02:10 +08:00
G T S A M _ C M A K E _ C _ F L A G S _ P R O F I L I N G G T S A M _ G T S A M _ C M A K E _ E X E _ L I N K E R _ F L A G S _ P R O F I L I N G
2016-02-25 03:01:19 +08:00
G T S A M _ C M A K E _ S H A R E D _ L I N K E R _ F L A G S _ P R O F I L I N G G T S A M _ C M A K E _ M O D U L E _ L I N K E R _ F L A G S _ P R O F I L I N G )
set ( CMAKE_SHARED_LINKER_FLAGS_TIMING ${ GTSAM_CMAKE_SHARED_LINKER_FLAGS_TIMING } )
set ( CMAKE_MODULE_LINKER_FLAGS_TIMING ${ GTSAM_CMAKE_MODULE_LINKER_FLAGS_TIMING } )
set ( CMAKE_EXE_LINKER_FLAGS_TIMING ${ GTSAM_CMAKE_EXE_LINKER_FLAGS_TIMING } )
set ( CMAKE_SHARED_LINKER_FLAGS_PROFILING ${ GTSAM_CMAKE_SHARED_LINKER_FLAGS_PROFILING } )
set ( CMAKE_MODULE_LINKER_FLAGS_PROFILING ${ GTSAM_CMAKE_MODULE_LINKER_FLAGS_PROFILING } )
set ( CMAKE_EXE_LINKER_FLAGS_PROFILING ${ GTSAM_CMAKE_EXE_LINKER_FLAGS_PROFILING } )
2015-04-09 20:01:16 +08:00
# Clang uses a template depth that is less than standard and is too small
2015-01-16 22:33:02 +08:00
if ( ${ CMAKE_CXX_COMPILER_ID } STREQUAL "Clang" )
2022-09-23 18:52:56 +08:00
# Apple Clang before 5.0 does not support -ftemplate-depth.
if ( NOT ( APPLE AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "5.0" ) )
list_append_cache ( GTSAM_COMPILE_OPTIONS_PUBLIC "-ftemplate-depth=1024" )
endif ( )
2013-12-23 02:01:39 +08:00
endif ( )
2025-01-10 23:20:50 +08:00
if ( ( NOT MSVC ) AND ( NOT QNX ) )
option ( GTSAM_BUILD_WITH_MARCH_NATIVE "Enable/Disable building with all instructions supported by native architecture (binary may not be portable!)" ON )
2022-10-19 20:54:24 +08:00
if ( GTSAM_BUILD_WITH_MARCH_NATIVE )
2022-12-24 01:02:03 +08:00
# Check if Apple OS and compiler is [Apple]Clang
if ( APPLE AND ( ${ CMAKE_CXX_COMPILER_ID } MATCHES "^(Apple)?Clang$" ) )
# Check Clang version since march=native is only supported for version 15.0+.
if ( "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "15.0" )
if ( NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" )
# Add as public flag so all dependent projects also use it, as required
# by Eigen to avoid crashes due to SIMD vectorization:
list_append_cache ( GTSAM_COMPILE_OPTIONS_PUBLIC "-march=native" )
else ( )
message ( WARNING "Option GTSAM_BUILD_WITH_MARCH_NATIVE ignored, because native architecture is not supported for Apple silicon and AppleClang version < 15.0." )
endif ( ) # CMAKE_SYSTEM_PROCESSOR
else ( )
# Add as public flag so all dependent projects also use it, as required
2022-10-19 20:54:24 +08:00
# by Eigen to avoid crashes due to SIMD vectorization:
2022-09-23 18:52:56 +08:00
list_append_cache ( GTSAM_COMPILE_OPTIONS_PUBLIC "-march=native" )
2022-12-24 01:02:03 +08:00
endif ( ) # CMAKE_CXX_COMPILER_VERSION
2022-10-19 20:54:24 +08:00
else ( )
include ( CheckCXXCompilerFlag )
CHECK_CXX_COMPILER_FLAG ( "-march=native" COMPILER_SUPPORTS_MARCH_NATIVE )
2022-09-23 18:52:56 +08:00
if ( COMPILER_SUPPORTS_MARCH_NATIVE )
2022-12-24 01:02:03 +08:00
# Add as public flag so all dependent projects also use it, as required
2022-10-19 20:54:24 +08:00
# by Eigen to avoid crashes due to SIMD vectorization:
list_append_cache ( GTSAM_COMPILE_OPTIONS_PUBLIC "-march=native" )
2022-09-23 18:52:56 +08:00
else ( )
2022-12-24 01:02:03 +08:00
message ( WARNING "Option GTSAM_BUILD_WITH_MARCH_NATIVE ignored, because native architecture is not supported." )
2022-10-19 20:54:24 +08:00
endif ( ) # COMPILER_SUPPORTS_MARCH_NATIVE
endif ( ) # APPLE
endif ( ) # GTSAM_BUILD_WITH_MARCH_NATIVE
2019-05-19 06:15:27 +08:00
endif ( )
2013-12-23 02:01:39 +08:00
# Set up build type library postfixes
if ( GTSAM_BUILD_TYPE_POSTFIXES )
2016-02-25 03:01:19 +08:00
foreach ( build_type Debug Timing Profiling RelWithDebInfo MinSizeRel )
string ( TOUPPER "${build_type}" build_type_toupper )
set ( CMAKE_ ${ build_type_toupper } _POSTFIX ${ build_type } )
endforeach ( )
2013-12-23 02:01:39 +08:00
endif ( )
# Make common binary output directory when on Windows
if ( WIN32 )
2025-01-03 20:58:05 +08:00
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${GTSAM_BINARY_DIR}/bin" )
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${GTSAM_BINARY_DIR}/lib" )
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${GTSAM_BINARY_DIR}/lib" )
2013-12-23 02:01:39 +08:00
endif ( )
# Set up build type list for cmake-gui
if ( NOT "${CMAKE_BUILD_TYPE}" STREQUAL "" )
2016-02-25 03:01:19 +08:00
if ( ${ CMAKE_MAJOR_VERSION } . ${ CMAKE_MINOR_VERSION } VERSION_GREATER 2.8 OR ${ CMAKE_MAJOR_VERSION } . ${ CMAKE_MINOR_VERSION } VERSION_EQUAL 2.8 )
set_property ( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS None Debug Release Timing Profiling RelWithDebInfo MinSizeRel )
endif ( )
2013-12-23 02:01:39 +08:00
endif ( )
# Check build types
string ( TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower )
if ( NOT cmake_build_type_tolower STREQUAL ""
A N D N O T c m a k e _ b u i l d _ t y p e _ t o l o w e r S T R E Q U A L " n o n e "
A N D N O T c m a k e _ b u i l d _ t y p e _ t o l o w e r S T R E Q U A L " d e b u g "
A N D N O T c m a k e _ b u i l d _ t y p e _ t o l o w e r S T R E Q U A L " r e l e a s e "
A N D N O T c m a k e _ b u i l d _ t y p e _ t o l o w e r S T R E Q U A L " t i m i n g "
A N D N O T c m a k e _ b u i l d _ t y p e _ t o l o w e r S T R E Q U A L " p r o f i l i n g "
2015-05-14 13:26:24 +08:00
A N D N O T c m a k e _ b u i l d _ t y p e _ t o l o w e r S T R E Q U A L " r e l w i t h d e b i n f o "
A N D N O T c m a k e _ b u i l d _ t y p e _ t o l o w e r S T R E Q U A L " m i n s i z e r e l " )
2016-02-25 03:01:19 +08:00
message ( FATAL_ERROR "Unknown build type \" ${ CMAKE_BUILD_TYPE } \". Allowed values are None, Debug, Release, Timing, Profiling, RelWithDebInfo, MinSizeRel ( case-insensitive ) . " )
2013-12-23 02:01:39 +08:00
endif ( )
# Enable Visual Studio solution folders
set_property ( GLOBAL PROPERTY USE_FOLDERS On )
# Function for automatically assigning source folders
function ( gtsam_assign_source_folders )
set ( FILES ${ ARGV } )
foreach ( file ${ FILES } )
file ( RELATIVE_PATH relative_file "${CMAKE_CURRENT_SOURCE_DIR}" "${file}" )
get_filename_component ( relative_path "${relative_file}" PATH )
file ( TO_NATIVE_PATH "${relative_path}" relative_path )
source_group ( "${relative_path}" FILES "${file}" )
endforeach ( )
endfunction ( )
# Find and assign all source and header files
function ( gtsam_assign_all_source_folders )
file ( GLOB_RECURSE all_c_srcs "*.c" )
file ( GLOB_RECURSE all_cpp_srcs "*.cpp" )
file ( GLOB_RECURSE all_headers "*.h" )
gtsam_assign_source_folders ( "${all_c_srcs};${all_cpp_srcs};${all_headers}" )
endfunction ( )
2019-05-29 17:02:10 +08:00
# Applies the per-config build flags to the given target (e.g. gtsam, wrap_lib)
function ( gtsam_apply_build_flags target_name_ )
# To enable C++11: the use of target_compile_features() is preferred since
# it will be not in conflict with a more modern C++ standard, if used in a
# client program.
if ( NOT "${GTSAM_COMPILE_FEATURES_PUBLIC}" STREQUAL "" )
target_compile_features ( ${ target_name_ } PUBLIC ${ GTSAM_COMPILE_FEATURES_PUBLIC } )
endif ( )
target_compile_definitions ( ${ target_name_ } PRIVATE ${ GTSAM_COMPILE_DEFINITIONS_PRIVATE } )
target_compile_definitions ( ${ target_name_ } PUBLIC ${ GTSAM_COMPILE_DEFINITIONS_PUBLIC } )
if ( NOT "${GTSAM_COMPILE_OPTIONS_PUBLIC}" STREQUAL "" )
target_compile_options ( ${ target_name_ } PUBLIC ${ GTSAM_COMPILE_OPTIONS_PUBLIC } )
endif ( )
target_compile_options ( ${ target_name_ } PRIVATE ${ GTSAM_COMPILE_OPTIONS_PRIVATE } )
endfunction ( gtsam_apply_build_flags )
2020-10-07 00:10:06 +08:00
if ( NOT MSVC AND NOT XCODE_VERSION )
# Set the build type to upper case for downstream use
string ( TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER )
# Set the GTSAM_BUILD_TAG variable.
# If build type is Release, set to blank (""), else set to the build type.
if ( ${ CMAKE_BUILD_TYPE_UPPER } STREQUAL "RELEASE" )
set ( GTSAM_BUILD_TAG "" ) # Don't create release mode tag on installed directory
else ( )
set ( GTSAM_BUILD_TAG "${CMAKE_BUILD_TYPE}" )
endif ( )
endif ( )