From dd11ae8f0f72562f4cb0fabdf8b798cd75d36f41 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 22 Aug 2014 09:27:00 -0400 Subject: [PATCH] VS: Do not compile C sources as WinRT (#15100) The MSVC /ZW flag is valid only for C++ sources. Whenever we enable CompileAsWinRT for the whole target, disable it for all C sources. Update the documentation of VS_WINRT_COMPONENT to drop the statement about undefined behavior for non-C++ sources, because it is now defined as expected. --- Help/prop_tgt/VS_WINRT_COMPONENT.rst | 3 --- Source/cmVisualStudio10TargetGenerator.cxx | 15 ++++++++++++++- Source/cmVisualStudio10TargetGenerator.h | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Help/prop_tgt/VS_WINRT_COMPONENT.rst b/Help/prop_tgt/VS_WINRT_COMPONENT.rst index a017f0ea7..e160bd64b 100644 --- a/Help/prop_tgt/VS_WINRT_COMPONENT.rst +++ b/Help/prop_tgt/VS_WINRT_COMPONENT.rst @@ -7,8 +7,5 @@ For ``SHARED`` and ``MODULE`` libraries, this also defines the ``_WINRT_DLL`` preprocessor macro. .. note:: - Behavior is not defined for targets with source files that compile as - any language other than ``CXX``. - Currently this is implemented only by Visual Studio generators. Support may be added to other generators in the future. diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index c87bf71fb..c00d400db 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -159,6 +159,7 @@ cmVisualStudio10TargetGenerator(cmTarget* target, this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str()); this->Platform = gg->GetPlatformName(); this->MSTools = true; + this->TargetCompileAsWinRT = false; this->BuildFileStream = 0; this->IsMissingFiles = false; this->DefaultArtifactDir = @@ -1414,6 +1415,7 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( compileAs = "CompileAsC"; } } + bool noWinRT = this->TargetCompileAsWinRT && lang == "C"; bool hasFlags = false; // for the first time we need a new line if there is something // produced here. @@ -1447,7 +1449,7 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } // if we have flags or defines for this config then // use them - if(!flags.empty() || !configDefines.empty() || compileAs) + if(!flags.empty() || !configDefines.empty() || compileAs || noWinRT) { (*this->BuildFileStream ) << firstString; firstString = ""; // only do firstString once @@ -1460,6 +1462,10 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( { clOptions.AddFlag("CompileAs", compileAs); } + if(noWinRT) + { + clOptions.AddFlag("CompileAsWinRT", "false"); + } clOptions.Parse(flags.c_str()); clOptions.AddDefines(configDefines.c_str()); clOptions.SetConfiguration((*config).c_str()); @@ -1711,6 +1717,13 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( clOptions.AddFlag("CompileAsWinRT", "false"); } } + if(const char* winRT = clOptions.GetFlag("CompileAsWinRT")) + { + if(cmSystemTools::IsOn(winRT)) + { + this->TargetCompileAsWinRT = true; + } + } } this->ClOptions[configName] = pOptions.release(); diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 9d94365af..e558f74e1 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -134,6 +134,7 @@ private: std::string GUID; std::string Name; bool MSTools; + bool TargetCompileAsWinRT; cmGlobalVisualStudio10Generator* GlobalGenerator; cmGeneratedFileStream* BuildFileStream; cmLocalVisualStudio7Generator* LocalGenerator;