mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-22 14:23:10 -05:00
Features: Extend concept to C language.
Add properties and variables corresponding to CXX equivalents. Add features for c_function_prototypes (C90), c_restrict (C99), c_variadic_macros (C99) and c_static_assert (C11). This feature set can be extended later. Add a <PREFIX>_RESTRICT symbol define to WriteCompilerDetectionHeader to conditionally represent the c_restrict feature.
This commit is contained in:
@@ -2,6 +2,11 @@ set(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@")
|
||||
set(CMAKE_C_COMPILER_ARG1 "@CMAKE_C_COMPILER_ARG1@")
|
||||
set(CMAKE_C_COMPILER_ID "@CMAKE_C_COMPILER_ID@")
|
||||
set(CMAKE_C_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@")
|
||||
set(CMAKE_C_COMPILE_FEATURES "@CMAKE_C_COMPILE_FEATURES@")
|
||||
set(CMAKE_C90_COMPILE_FEATURES "@CMAKE_C90_COMPILE_FEATURES@")
|
||||
set(CMAKE_C99_COMPILE_FEATURES "@CMAKE_C99_COMPILE_FEATURES@")
|
||||
set(CMAKE_C11_COMPILE_FEATURES "@CMAKE_C11_COMPILE_FEATURES@")
|
||||
|
||||
set(CMAKE_C_PLATFORM_ID "@CMAKE_C_PLATFORM_ID@")
|
||||
set(CMAKE_C_SIMULATE_ID "@CMAKE_C_SIMULATE_ID@")
|
||||
set(CMAKE_C_SIMULATE_VERSION "@CMAKE_C_SIMULATE_VERSION@")
|
||||
|
||||
@@ -14,7 +14,45 @@
|
||||
|
||||
function(cmake_determine_compile_features lang)
|
||||
|
||||
if(lang STREQUAL CXX AND COMMAND cmake_record_cxx_compile_features)
|
||||
if(lang STREQUAL C AND COMMAND cmake_record_c_compile_features)
|
||||
message(STATUS "Detecting ${lang} compile features")
|
||||
|
||||
set(CMAKE_C90_COMPILE_FEATURES)
|
||||
set(CMAKE_C99_COMPILE_FEATURES)
|
||||
set(CMAKE_C11_COMPILE_FEATURES)
|
||||
|
||||
include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
|
||||
|
||||
cmake_record_c_compile_features()
|
||||
|
||||
if(NOT _result EQUAL 0)
|
||||
message(STATUS "Detecting ${lang} compile features - failed")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if (CMAKE_C99_COMPILE_FEATURES AND CMAKE_C11_COMPILE_FEATURES)
|
||||
list(REMOVE_ITEM CMAKE_C11_COMPILE_FEATURES ${CMAKE_C99_COMPILE_FEATURES})
|
||||
endif()
|
||||
if (CMAKE_C90_COMPILE_FEATURES AND CMAKE_C99_COMPILE_FEATURES)
|
||||
list(REMOVE_ITEM CMAKE_C99_COMPILE_FEATURES ${CMAKE_C90_COMPILE_FEATURES})
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_C_COMPILE_FEATURES)
|
||||
set(CMAKE_C_COMPILE_FEATURES
|
||||
${CMAKE_C90_COMPILE_FEATURES}
|
||||
${CMAKE_C99_COMPILE_FEATURES}
|
||||
${CMAKE_C11_COMPILE_FEATURES}
|
||||
)
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_COMPILE_FEATURES ${CMAKE_C_COMPILE_FEATURES} PARENT_SCOPE)
|
||||
set(CMAKE_C90_COMPILE_FEATURES ${CMAKE_C90_COMPILE_FEATURES} PARENT_SCOPE)
|
||||
set(CMAKE_C99_COMPILE_FEATURES ${CMAKE_C99_COMPILE_FEATURES} PARENT_SCOPE)
|
||||
set(CMAKE_C11_COMPILE_FEATURES ${CMAKE_C11_COMPILE_FEATURES} PARENT_SCOPE)
|
||||
|
||||
message(STATUS "Detecting ${lang} compile features - done")
|
||||
|
||||
elseif(lang STREQUAL CXX AND COMMAND cmake_record_cxx_compile_features)
|
||||
message(STATUS "Detecting ${lang} compile features")
|
||||
|
||||
set(CMAKE_CXX98_COMPILE_FEATURES)
|
||||
|
||||
@@ -73,6 +73,9 @@ else()
|
||||
# Try to identify the ABI and configure it into CMakeCCompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(C ${CMAKE_ROOT}/Modules/CMakeCCompilerABI.c)
|
||||
# Try to identify the compiler features
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
|
||||
CMAKE_DETERMINE_COMPILE_FEATURES(C)
|
||||
|
||||
# Re-configure to save learned information.
|
||||
configure_file(
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
set(_cmake_oldestSupported "(__GNUC__ * 100 + __GNUC_MINOR__) >= 407")
|
||||
|
||||
set(GNU46_C11 "${_cmake_oldestSupported} && __STDC_VERSION__ >= 201112L")
|
||||
set(_cmake_feature_test_c_static_assert "${GNU46_C11}")
|
||||
# Since 4.4 at least:
|
||||
set(GNU44_C99 "${_cmake_oldestSupported} && __STDC_VERSION__ >= 199901L")
|
||||
set(_cmake_feature_test_c_restrict "${GNU44_C99}")
|
||||
set(_cmake_feature_test_c_variadic_macros "${GNU44_C99}")
|
||||
|
||||
set(GNU_C90 "${_cmake_oldestSupported} && !defined(__STDC_VERSION__)")
|
||||
set(_cmake_feature_test_c_function_prototypes "${GNU_C90}")
|
||||
@@ -1,2 +1,34 @@
|
||||
include(Compiler/GNU)
|
||||
__compiler_gnu(C)
|
||||
|
||||
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.7)
|
||||
set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c90")
|
||||
set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu90")
|
||||
|
||||
set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99")
|
||||
set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99")
|
||||
|
||||
set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11")
|
||||
set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11")
|
||||
endif()
|
||||
|
||||
# This may change in a future GNU version.
|
||||
set(CMAKE_C_STANDARD_DEFAULT 90)
|
||||
|
||||
macro(cmake_record_c_compile_features)
|
||||
macro(_get_gcc_features std_version list)
|
||||
record_compiler_features(C "-std=${std_version}" ${list})
|
||||
endmacro()
|
||||
|
||||
if (UNIX AND NOT APPLE AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.7)
|
||||
_get_gcc_features(c90 CMAKE_C90_COMPILE_FEATURES)
|
||||
if (_result EQUAL 0)
|
||||
_get_gcc_features(c99 CMAKE_C99_COMPILE_FEATURES)
|
||||
endif()
|
||||
if (_result EQUAL 0)
|
||||
_get_gcc_features(c11 CMAKE_C11_COMPILE_FEATURES)
|
||||
endif()
|
||||
else()
|
||||
set(_result 0)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
@@ -43,7 +43,8 @@
|
||||
# Possible compiler identifiers are documented with the
|
||||
# :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
|
||||
# Available features in this version of CMake are listed in the
|
||||
# :prop_gbl:`CMAKE_CXX_KNOWN_FEATURES` global property.
|
||||
# :prop_gbl:`CMAKE_C_KNOWN_FEATURES` and
|
||||
# :prop_gbl:`CMAKE_CXX_KNOWN_FEATURES` global properties.
|
||||
#
|
||||
# Feature Test Macros
|
||||
# ===================
|
||||
@@ -102,6 +103,7 @@
|
||||
# ========================== =================================== =================
|
||||
# Feature Define Symbol
|
||||
# ========================== =================================== =================
|
||||
# ``c_restrict`` ``<PREFIX>_RESTRICT`` ``restrict``
|
||||
# ``cxx_constexpr`` ``<PREFIX>_CONSTEXPR`` ``constexpr``
|
||||
# ``cxx_deleted_functions`` ``<PREFIX>_DELETED_FUNCTION`` ``= delete``
|
||||
# ``cxx_extern_templates`` ``<PREFIX>_EXTERN_TEMPLATE`` ``extern``
|
||||
@@ -221,6 +223,9 @@ function(write_compiler_detection_header
|
||||
if (feature MATCHES "^cxx_")
|
||||
list(APPEND _langs CXX)
|
||||
list(APPEND CXX_features ${feature})
|
||||
elseif (feature MATCHES "^c_")
|
||||
list(APPEND _langs C)
|
||||
list(APPEND C_features ${feature})
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported feature ${feature}.")
|
||||
endif()
|
||||
@@ -239,6 +244,8 @@ function(write_compiler_detection_header
|
||||
|
||||
if(_lang STREQUAL CXX)
|
||||
set(file_content "${file_content}\n#ifdef __cplusplus\n")
|
||||
else()
|
||||
set(file_content "${file_content}\n#ifndef __cplusplus\n")
|
||||
endif()
|
||||
|
||||
compiler_id_detection(ID_CONTENT ${_lang} PREFIX ${prefix_arg}_
|
||||
@@ -279,6 +286,16 @@ function(write_compiler_detection_header
|
||||
string(TOUPPER ${feature} feature_upper)
|
||||
set(feature_PP "COMPILER_${feature_upper}")
|
||||
set(def_name ${prefix_arg}_${feature_PP})
|
||||
if (feature STREQUAL c_restrict)
|
||||
set(def_value "${prefix_arg}_RESTRICT")
|
||||
set(file_content "${file_content}
|
||||
# if ${def_name}
|
||||
# define ${def_value} restrict
|
||||
# else
|
||||
# define ${def_value}
|
||||
# endif
|
||||
\n")
|
||||
endif()
|
||||
if (feature STREQUAL cxx_constexpr)
|
||||
set(def_value "${prefix_arg}_DECL_${feature_upper}")
|
||||
set(file_content "${file_content}
|
||||
@@ -382,9 +399,8 @@ function(write_compiler_detection_header
|
||||
\n")
|
||||
endif()
|
||||
endforeach()
|
||||
if(_lang STREQUAL CXX)
|
||||
set(file_content "${file_content}#endif\n")
|
||||
endif()
|
||||
|
||||
set(file_content "${file_content}#endif\n")
|
||||
|
||||
endforeach()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user