mirror of
https://github.com/Kitware/CMake.git
synced 2026-06-30 19:57:41 +00:00
Features: Record C features for MSVC
The MSVC C compiler has no notion of C language standards or flags. Tell CMake to assume that all language standards are available. Record available C language features depending on the version of the compiler. Fixes: #17858
This commit is contained in:
5
Help/release/dev/features-msvc-c.rst
Normal file
5
Help/release/dev/features-msvc-c.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
features-msvc-c
|
||||
---------------
|
||||
|
||||
* The :manual:`Compile Features <cmake-compile-features(7)>` functionality
|
||||
is now aware of the availability of C features in MSVC since VS 2010.
|
||||
8
Modules/Compiler/MSVC-C-FeatureTests.cmake
Normal file
8
Modules/Compiler/MSVC-C-FeatureTests.cmake
Normal file
@@ -0,0 +1,8 @@
|
||||
set(_cmake_oldestSupported "_MSC_VER >= 1600")
|
||||
|
||||
# Not yet supported:
|
||||
#set(_cmake_feature_test_c_static_assert "")
|
||||
#set(_cmake_feature_test_c_restrict "")
|
||||
|
||||
set(_cmake_feature_test_c_variadic_macros "${_cmake_oldestSupported}")
|
||||
set(_cmake_feature_test_c_function_prototypes "${_cmake_oldestSupported}")
|
||||
25
Modules/Compiler/MSVC-C.cmake
Normal file
25
Modules/Compiler/MSVC-C.cmake
Normal file
@@ -0,0 +1,25 @@
|
||||
# MSVC has no specific options to set C language standards, but set them as
|
||||
# empty strings anyways so the feature test infrastructure can at least check
|
||||
# to see if they are defined.
|
||||
set(CMAKE_C90_STANDARD_COMPILE_OPTION "")
|
||||
set(CMAKE_C90_EXTENSION_COMPILE_OPTION "")
|
||||
set(CMAKE_C99_STANDARD_COMPILE_OPTION "")
|
||||
set(CMAKE_C99_EXTENSION_COMPILE_OPTION "")
|
||||
set(CMAKE_C11_STANDARD_COMPILE_OPTION "")
|
||||
set(CMAKE_C11_EXTENSION_COMPILE_OPTION "")
|
||||
|
||||
# There is no meaningful default for this
|
||||
set(CMAKE_C_STANDARD_DEFAULT "")
|
||||
|
||||
# There are no C compiler modes so we only need to test features once.
|
||||
# Override the default macro for this special case. Pretend that
|
||||
# all language standards are available so that at least compilation
|
||||
# can be attempted.
|
||||
macro(cmake_record_c_compile_features)
|
||||
list(APPEND CMAKE_C_COMPILE_FEATURES
|
||||
c_std_90
|
||||
c_std_99
|
||||
c_std_11
|
||||
)
|
||||
_record_compiler_features(C "" CMAKE_C_COMPILE_FEATURES)
|
||||
endmacro()
|
||||
@@ -1,5 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_policy(SET CMP0057 NEW)
|
||||
cmake_minimum_required(VERSION 3.3)
|
||||
project(target_compile_features)
|
||||
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
@@ -19,7 +18,8 @@ if (c_restrict IN_LIST CMAKE_C_COMPILE_FEATURES)
|
||||
target_link_libraries(c_restrict_user_specific c_lib_restrict_specific)
|
||||
endif()
|
||||
|
||||
if (c_std_99 IN_LIST CMAKE_C_COMPILE_FEATURES)
|
||||
if (c_std_99 IN_LIST CMAKE_C_COMPILE_FEATURES AND
|
||||
NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
|
||||
add_executable(c_target_compile_features_meta main.c)
|
||||
target_compile_features(c_target_compile_features_meta
|
||||
PRIVATE c_std_99
|
||||
|
||||
@@ -254,6 +254,11 @@ if (C_expected_features)
|
||||
EXPECT_C_STATIC_ASSERT=0
|
||||
)
|
||||
endif()
|
||||
elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
||||
list(APPEND expected_defs
|
||||
EXPECT_C_RESTRICT=0
|
||||
EXPECT_C_STATIC_ASSERT=0
|
||||
)
|
||||
elseif (CMAKE_C_COMPILER_ID STREQUAL "SunPro")
|
||||
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.13)
|
||||
list(APPEND expected_defs
|
||||
|
||||
Reference in New Issue
Block a user