diff options
author | Brad King <brad.king@kitware.com> | 2020-09-30 12:10:28 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-09-30 12:10:34 (GMT) |
commit | 1c3244ca30d3139c61f7c8d99481d5c00295e97c (patch) | |
tree | 89003602cdcee9f71641648423fa7df8ec2103a2 | |
parent | c297b61779c6fbfe806e92d7f15af4a7354bb651 (diff) | |
parent | b3254849284f973316a4ffef2d8f7851642c6413 (diff) | |
download | CMake-1c3244ca30d3139c61f7c8d99481d5c00295e97c.zip CMake-1c3244ca30d3139c61f7c8d99481d5c00295e97c.tar.gz CMake-1c3244ca30d3139c61f7c8d99481d5c00295e97c.tar.bz2 |
Merge topic 'vs-mixed-lang-std'
b325484928 VS: Fix C language standard in target with C++ sources
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5295
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 17 | ||||
-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 |
4 files changed, 49 insertions, 0 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index ae4a5be..a7b90b4 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2868,6 +2868,23 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE")); } + // Add C-specific flags expressible in a ClCompile meant for C++. + if (langForClCompile == "CXX") { + std::set<std::string> languages; + this->GeneratorTarget->GetLanguages(languages, configName); + if (languages.count("C")) { + std::string flagsC; + this->LocalGenerator->AddCompileOptions(flagsC, this->GeneratorTarget, + "C", configName); + Options optC(this->LocalGenerator, Options::Compiler, + gg->GetClFlagTable()); + optC.Parse(flagsC); + if (const char* stdC = optC.GetFlag("LanguageStandard_C")) { + clOptions.AddFlag("LanguageStandard_C", stdC); + } + } + } + // Add a definition for the configuration name. std::string configDefine = cmStrCat("CMAKE_INTDIR=\"", configName, '"'); clOptions.AddDefine(configDefine); 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) |