From c22cdf78d7be7283d7d031c7e9e15246d53354f8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 28 Mar 2018 10:38:29 -0400 Subject: Features: Fix CompileFeatures test checks for C Compare the HAVE_ and EXPECT_ macros as we do for CXX. --- Tests/CompileFeatures/genex_test.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Tests/CompileFeatures/genex_test.c b/Tests/CompileFeatures/genex_test.c index 1d54840..e58d793 100644 --- a/Tests/CompileFeatures/genex_test.c +++ b/Tests/CompileFeatures/genex_test.c @@ -8,7 +8,7 @@ #error EXPECT_C_RESTRICT not defined #endif -#if !EXPECT_C_STATIC_ASSERT +#if !HAVE_C_STATIC_ASSERT #if EXPECT_C_STATIC_ASSERT #error "Expect c_static_assert feature" #endif @@ -18,11 +18,17 @@ #endif #endif -#if !EXPECT_C_FUNCTION_PROTOTYPES +#if !HAVE_C_FUNCTION_PROTOTYPES +#if EXPECT_C_FUNCTION_PROTOTYPES #error Expect c_function_prototypes support #endif +#else +#if !EXPECT_C_FUNCTION_PROTOTYPES +#error Expect no c_function_prototypes support +#endif +#endif -#if !EXPECT_C_RESTRICT +#if !HAVE_C_RESTRICT #if EXPECT_C_RESTRICT #error Expect c_restrict support #endif -- cgit v0.12 From e62dfeccb1bb6a86a85f34908343a89f6d02ee6a Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 28 Mar 2018 10:42:52 -0400 Subject: Features: Do not assume c_restrict support in CompileFeatures test Define `EXPECT_C_RESTRICT` separately for each compiler. --- Tests/CompileFeatures/CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index b560acd..0271cd6 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -227,43 +227,53 @@ if (C_expected_features) if (CMAKE_C_COMPILER_ID STREQUAL "GNU") if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6) list(APPEND expected_defs + EXPECT_C_RESTRICT=1 EXPECT_C_STATIC_ASSERT=1 ) else() list(APPEND expected_defs + EXPECT_C_RESTRICT=1 EXPECT_C_STATIC_ASSERT=0 ) endif() elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang") list(APPEND expected_defs + EXPECT_C_RESTRICT=1 EXPECT_C_STATIC_ASSERT=1 ) elseif (CMAKE_C_COMPILER_ID STREQUAL "Intel") if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15) list(APPEND expected_defs + EXPECT_C_RESTRICT=1 EXPECT_C_STATIC_ASSERT=1 ) else() list(APPEND expected_defs + EXPECT_C_RESTRICT=1 EXPECT_C_STATIC_ASSERT=0 ) endif() elseif (CMAKE_C_COMPILER_ID STREQUAL "SunPro") if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.13) list(APPEND expected_defs + EXPECT_C_RESTRICT=1 EXPECT_C_STATIC_ASSERT=1 ) else() list(APPEND expected_defs + EXPECT_C_RESTRICT=1 EXPECT_C_STATIC_ASSERT=0 ) endif() + else() + list(APPEND expected_defs + EXPECT_C_RESTRICT=1 + ) endif() list(APPEND expected_defs EXPECT_C_FUNCTION_PROTOTYPES=1 - EXPECT_C_RESTRICT=1 ) target_compile_definitions(CompileFeaturesGenex_C PRIVATE -- cgit v0.12 From a53cf69022e57d859864d59b9c03238f180cb400 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 28 Mar 2018 10:56:58 -0400 Subject: 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 --- Help/release/dev/features-msvc-c.rst | 5 +++++ Modules/Compiler/MSVC-C-FeatureTests.cmake | 8 +++++++ Modules/Compiler/MSVC-C.cmake | 25 ++++++++++++++++++++++ .../target_compile_features/CMakeLists.txt | 6 +++--- Tests/CompileFeatures/CMakeLists.txt | 5 +++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 Help/release/dev/features-msvc-c.rst create mode 100644 Modules/Compiler/MSVC-C-FeatureTests.cmake create mode 100644 Modules/Compiler/MSVC-C.cmake diff --git a/Help/release/dev/features-msvc-c.rst b/Help/release/dev/features-msvc-c.rst new file mode 100644 index 0000000..0c55544 --- /dev/null +++ b/Help/release/dev/features-msvc-c.rst @@ -0,0 +1,5 @@ +features-msvc-c +--------------- + +* The :manual:`Compile Features ` functionality + is now aware of the availability of C features in MSVC since VS 2010. diff --git a/Modules/Compiler/MSVC-C-FeatureTests.cmake b/Modules/Compiler/MSVC-C-FeatureTests.cmake new file mode 100644 index 0000000..3f09be2 --- /dev/null +++ b/Modules/Compiler/MSVC-C-FeatureTests.cmake @@ -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}") diff --git a/Modules/Compiler/MSVC-C.cmake b/Modules/Compiler/MSVC-C.cmake new file mode 100644 index 0000000..22c34f8 --- /dev/null +++ b/Modules/Compiler/MSVC-C.cmake @@ -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() diff --git a/Tests/CMakeCommands/target_compile_features/CMakeLists.txt b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt index 5096a58..9664025 100644 --- a/Tests/CMakeCommands/target_compile_features/CMakeLists.txt +++ b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt @@ -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 diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt index 0271cd6..200aa79 100644 --- a/Tests/CompileFeatures/CMakeLists.txt +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -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 -- cgit v0.12