summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-05-20 13:40:14 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2014-05-20 13:40:14 (GMT)
commitc1edede31f4e979826a5fc0f6e56b1b59cb00f21 (patch)
tree11ca8f038a7e363ebd7b218d5cf753fae4b1cd4d /Modules
parent8897116df8e8a6576f2736b96b8e0d529c26139e (diff)
parente0890d03a48d12904ffe24aa94fb2847d8d5f4e7 (diff)
downloadCMake-c1edede31f4e979826a5fc0f6e56b1b59cb00f21.zip
CMake-c1edede31f4e979826a5fc0f6e56b1b59cb00f21.tar.gz
CMake-c1edede31f4e979826a5fc0f6e56b1b59cb00f21.tar.bz2
Merge topic 'compile-features-C-language'
e0890d03 Features: Extend concept to C language.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CMakeCCompiler.cmake.in5
-rw-r--r--Modules/CMakeDetermineCompileFeatures.cmake40
-rw-r--r--Modules/CMakeTestCCompiler.cmake3
-rw-r--r--Modules/Compiler/GNU-C-FeatureTests.cmake12
-rw-r--r--Modules/Compiler/GNU-C.cmake32
-rw-r--r--Modules/WriteCompilerDetectionHeader.cmake24
6 files changed, 111 insertions, 5 deletions
diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in
index 694f8b8..86cd894 100644
--- a/Modules/CMakeCCompiler.cmake.in
+++ b/Modules/CMakeCCompiler.cmake.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@")
diff --git a/Modules/CMakeDetermineCompileFeatures.cmake b/Modules/CMakeDetermineCompileFeatures.cmake
index 583ff8d..3762912 100644
--- a/Modules/CMakeDetermineCompileFeatures.cmake
+++ b/Modules/CMakeDetermineCompileFeatures.cmake
@@ -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)
diff --git a/Modules/CMakeTestCCompiler.cmake b/Modules/CMakeTestCCompiler.cmake
index d133042..29a58bd 100644
--- a/Modules/CMakeTestCCompiler.cmake
+++ b/Modules/CMakeTestCCompiler.cmake
@@ -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(
diff --git a/Modules/Compiler/GNU-C-FeatureTests.cmake b/Modules/Compiler/GNU-C-FeatureTests.cmake
new file mode 100644
index 0000000..dc1695c
--- /dev/null
+++ b/Modules/Compiler/GNU-C-FeatureTests.cmake
@@ -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}")
diff --git a/Modules/Compiler/GNU-C.cmake b/Modules/Compiler/GNU-C.cmake
index 9a5137a..35954be 100644
--- a/Modules/Compiler/GNU-C.cmake
+++ b/Modules/Compiler/GNU-C.cmake
@@ -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()
diff --git a/Modules/WriteCompilerDetectionHeader.cmake b/Modules/WriteCompilerDetectionHeader.cmake
index fd236c1..d3c2037 100644
--- a/Modules/WriteCompilerDetectionHeader.cmake
+++ b/Modules/WriteCompilerDetectionHeader.cmake
@@ -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()