diff options
author | Brad King <brad.king@kitware.com> | 2020-09-28 20:26:12 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-09-29 11:26:36 (GMT) |
commit | b3254849284f973316a4ffef2d8f7851642c6413 (patch) | |
tree | d9e15266a6611e0c3fadde635a483367cb067c18 /Tests/RunCMake | |
parent | 39677de5e209445c8cbc5957c1e79088d5d2a03a (diff) | |
download | CMake-b3254849284f973316a4ffef2d8f7851642c6413.zip CMake-b3254849284f973316a4ffef2d8f7851642c6413.tar.gz CMake-b3254849284f973316a4ffef2d8f7851642c6413.tar.bz2 |
VS: Fix C language standard in target with C++ sources
Add C-language standard to target-wide C++ settings.
Fixes: #21195
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r-- | Tests/RunCMake/VS10Project/LanguageStandard-check.cmake | 23 | ||||
-rw-r--r-- | Tests/RunCMake/VS10Project/LanguageStandard.cmake | 5 | ||||
-rw-r--r-- | Tests/RunCMake/VS10Project/RunCMakeTest.cmake | 4 |
3 files changed, 32 insertions, 0 deletions
diff --git a/Tests/RunCMake/VS10Project/LanguageStandard-check.cmake b/Tests/RunCMake/VS10Project/LanguageStandard-check.cmake new file mode 100644 index 0000000..85e2858 --- /dev/null +++ b/Tests/RunCMake/VS10Project/LanguageStandard-check.cmake @@ -0,0 +1,23 @@ +set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj") +if(NOT EXISTS "${vcProjectFile}") + set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.") + return() +endif() + +set(found_LanguageStandard_stdcpp17 0) +set(found_LanguageStandard_C_stdc11 0) +file(STRINGS "${vcProjectFile}" lines) +foreach(line IN LISTS lines) + if(line MATCHES "<LanguageStandard>stdcpp17</LanguageStandard>") + set(found_LanguageStandard_stdcpp17 1) + endif() + if(line MATCHES "<LanguageStandard_C>stdc11</LanguageStandard_C>") + set(found_LanguageStandard_C_stdc11 1) + endif() +endforeach() +if(NOT found_LanguageStandard_stdcpp17) + string(APPEND RunCMake_TEST_FAILED "LanguageStandard stdcpp17 not found in\n ${vcProjectFile}\n") +endif() +if(NOT found_LanguageStandard_C_stdc11) + string(APPEND RunCMake_TEST_FAILED "LanguageStandard_C stdc11 not found in\n ${vcProjectFile}\n") +endif() diff --git a/Tests/RunCMake/VS10Project/LanguageStandard.cmake b/Tests/RunCMake/VS10Project/LanguageStandard.cmake new file mode 100644 index 0000000..f8b62e2 --- /dev/null +++ b/Tests/RunCMake/VS10Project/LanguageStandard.cmake @@ -0,0 +1,5 @@ +enable_language(C) +enable_language(CXX) + +add_library(foo empty.c empty.cxx) +target_compile_features(foo PRIVATE c_std_11 cxx_std_17) diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake index e9f251a..8e56e1b 100644 --- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake +++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake @@ -3,6 +3,10 @@ cmake_policy(SET CMP0057 NEW) include(RunCMake) cmake_policy(SET CMP0054 NEW) +if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.27) + run_cmake(LanguageStandard) +endif() + run_cmake(VsCsharpSourceGroup) run_cmake(VsCSharpCompilerOpts) run_cmake(ExplicitCMakeLists) |