summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2021-12-29 01:08:39 +0100
committerSlávek Banko <slavek.banko@axis.cz>2021-12-29 01:23:25 +0100
commit2bcaeab34e1f7d3714416a6d5290701d2b02be1e (patch)
tree0d38def58def14e0d9783373d5188855e94fa6eb
parent6980b57268b7f10fa56a36a56f16ab255266027f (diff)
downloadtde-cmake-2bcaeab34e1f7d3714416a6d5290701d2b02be1e.tar.gz
tde-cmake-2bcaeab34e1f7d3714416a6d5290701d2b02be1e.zip
Add the ability to specify the necessary CXX features.
This increases the minimum necessary version of CMake to 3.1. There are three levels: 1. TDE_CXX_FEATURES common for all TDE modules 2. PROJECT_CXX_FEATURES common at invidual module level 3. CXX_FEATURES and CXX_FEATURES_PRIVATE for individual libraries and binaries Public CXX_FEATURES for libraries become part of the exported CMake target. Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
-rw-r--r--modules/TDEMacros.cmake40
-rw-r--r--templates/tde_export_library.cmake1
2 files changed, 41 insertions, 0 deletions
diff --git a/modules/TDEMacros.cmake b/modules/TDEMacros.cmake
index 06a6b1b..ed6ca68 100644
--- a/modules/TDEMacros.cmake
+++ b/modules/TDEMacros.cmake
@@ -23,6 +23,10 @@ include( CheckCXXCompilerFlag )
##### initialization...
if( NOT TDE_CMAKE_ROOT )
+ if( "${CMAKE_VERSION}" VERSION_LESS "3.1" )
+ message( FATAL_ERROR "CMake >= 3.1.0 required" )
+ endif()
+
if( ${CMAKE_CURRENT_LIST_DIR} STREQUAL ${CMAKE_ROOT}/Modules )
# TDE CMake is installed in the system directory
@@ -792,6 +796,8 @@ macro( tde_add_library _arg_target )
unset( _version )
unset( _release )
unset( _sources )
+ unset( _cxx_features )
+ unset( _cxx_features_private )
unset( _destination )
unset( _embed )
unset( _link )
@@ -878,6 +884,18 @@ macro( tde_add_library _arg_target )
set( _storage "_sources" )
endif( "+${_arg}" STREQUAL "+SOURCES" )
+ # found directive "CXX_FEATURES"
+ if( "+${_arg}" STREQUAL "+CXX_FEATURES" )
+ set( _skip_store 1 )
+ set( _storage "_cxx_features" )
+ endif( "+${_arg}" STREQUAL "+CXX_FEATURES" )
+
+ # found directive "CXX_FEATURES_PRIVATE"
+ if( "+${_arg}" STREQUAL "+CXX_FEATURES_PRIVATE" )
+ set( _skip_store 1 )
+ set( _storage "_cxx_features_private" )
+ endif( "+${_arg}" STREQUAL "+CXX_FEATURES_PRIVATE" )
+
# found directive "EMBED"
if( "+${_arg}" STREQUAL "+EMBED" )
set( _skip_store 1 )
@@ -997,6 +1015,15 @@ macro( tde_add_library _arg_target )
# add target
add_library( ${_target} ${_type} ${_exclude_from_all} ${_sources} )
+ # set cxx features
+ if( _cxx_features )
+ target_compile_features( ${_target} PUBLIC ${_cxx_features} )
+ endif( )
+ if( TDE_CXX_FEATURES OR PROJECT_CXX_FEATURES OR _cxx_features_private )
+ target_compile_features( ${_target} PRIVATE
+ ${TDE_CXX_FEATURES} ${PROJECT_CXX_FEATURES} ${_cxx_features_private} )
+ endif( )
+
# we assume that modules have no prefix and no version
# also, should not link
if( ${_type} STREQUAL "MODULE" )
@@ -1235,6 +1262,7 @@ macro( tde_add_executable _arg_target )
unset( _meta_includes )
unset( _setuid )
unset( _sources )
+ unset( _cxx_features )
unset( _destination )
unset( _link )
unset( _dependencies )
@@ -1289,6 +1317,12 @@ macro( tde_add_executable _arg_target )
set( _storage "_sources" )
endif( "+${_arg}" STREQUAL "+SOURCES" )
+ # found directive "CXX_FEATURES"
+ if( "+${_arg}" STREQUAL "+CXX_FEATURES" )
+ set( _skip_store 1 )
+ set( _storage "_cxx_features" )
+ endif( "+${_arg}" STREQUAL "+CXX_FEATURES" )
+
# found directive "LINK"
if( "+${_arg}" STREQUAL "+LINK" )
set( _skip_store 1 )
@@ -1372,6 +1406,12 @@ macro( tde_add_executable _arg_target )
# add target
add_executable( ${_target} ${_sources} )
+ # set cxx features
+ if( TDE_CXX_FEATURES OR PROJECT_CXX_FEATURES OR _cxx_features )
+ target_compile_features( ${_target} PRIVATE
+ ${TDE_CXX_FEATURES} ${PROJECT_CXX_FEATURES} ${_cxx_features} )
+ endif( )
+
# set link libraries
if( _link )
target_link_libraries( ${_target} ${_link} )
diff --git a/templates/tde_export_library.cmake b/templates/tde_export_library.cmake
index 4d6cb3f..7e4ec26 100644
--- a/templates/tde_export_library.cmake
+++ b/templates/tde_export_library.cmake
@@ -1,6 +1,7 @@
add_library( @_target@ @_type@ IMPORTED )
set_target_properties( @_target@ PROPERTIES
+ INTERFACE_COMPILE_FEATURES "@_cxx_features@"
IMPORTED_LINK_INTERFACE_LIBRARIES "@_shared_libs@"
IMPORTED_LOCATION "@_location@"
IMPORTED_SONAME "@_soname@" )