CompileFeatures: memoize C compilers with full language level support

Previously compilers that had full support for a language
standard level was forced to verify this every time a new build
directory was created. Now we record this information and insert
the correct granular compile features instead of doing a try_compile.
This commit is contained in:
Robert Maynard 2019-03-06 12:28:00 -05:00
parent 9fbad8b40b
commit f92ccbc306
2 changed files with 29 additions and 3 deletions

View File

@ -65,14 +65,29 @@ endmacro()
macro(cmake_record_c_compile_features) macro(cmake_record_c_compile_features)
set(_result 0) set(_result 0)
if(_result EQUAL 0 AND DEFINED CMAKE_C11_STANDARD_COMPILE_OPTION) if(_result EQUAL 0 AND DEFINED CMAKE_C11_STANDARD_COMPILE_OPTION)
if(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT)
_has_compiler_features_c(11)
else()
_record_compiler_features_c(11) _record_compiler_features_c(11)
endif() endif()
unset(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT)
endif()
if(_result EQUAL 0 AND DEFINED CMAKE_C99_STANDARD_COMPILE_OPTION) if(_result EQUAL 0 AND DEFINED CMAKE_C99_STANDARD_COMPILE_OPTION)
if(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT)
_has_compiler_features_c(99)
else()
_record_compiler_features_c(99) _record_compiler_features_c(99)
endif() endif()
unset(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT)
endif()
if(_result EQUAL 0 AND DEFINED CMAKE_C90_STANDARD_COMPILE_OPTION) if(_result EQUAL 0 AND DEFINED CMAKE_C90_STANDARD_COMPILE_OPTION)
if(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT)
_has_compiler_features_c(90)
else()
_record_compiler_features_c(90) _record_compiler_features_c(90)
endif() endif()
unset(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT)
endif()
endmacro() endmacro()
# Define to allow compile features to be automatically determined # Define to allow compile features to be automatically determined

View File

@ -88,3 +88,14 @@ macro(_record_compiler_features_cxx std)
endif() endif()
unset(lang_level_has_features) unset(lang_level_has_features)
endmacro() endmacro()
macro(_has_compiler_features lang level compile_flags feature_list)
# presume all known features are supported
get_property(known_features GLOBAL PROPERTY CMAKE_${lang}${level}_KNOWN_FEATURES)
list(APPEND ${feature_list} ${known_features})
endmacro()
macro(_has_compiler_features_c std)
list(APPEND CMAKE_C${std}_COMPILE_FEATURES c_std_${std})
_has_compiler_features(C ${std} "${CMAKE_C${std}_STANDARD_COMPILE_OPTION}" CMAKE_C${std}_COMPILE_FEATURES)
endmacro()