diff options
author | Zsolt Parragi <zsolt.parragi@cancellar.hu> | 2016-10-25 16:23:22 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-10-28 15:18:03 (GMT) |
commit | 1e4bb358946a100ea04bbc97f8195b90b44a5e9c (patch) | |
tree | ec0cebb25ef0f6fcc0d68ab8548e0d2a1f004ab3 /Source/cmVisualStudio10TargetGenerator.cxx | |
parent | ee0f2d23fcf3cd7a67ad8d7bd132a475ed78405f (diff) | |
download | CMake-1e4bb358946a100ea04bbc97f8195b90b44a5e9c.zip CMake-1e4bb358946a100ea04bbc97f8195b90b44a5e9c.tar.gz CMake-1e4bb358946a100ea04bbc97f8195b90b44a5e9c.tar.bz2 |
Add generator expression support to per-source COMPILE_FLAGS
This allows users to specify different genex-based compile flags for
each file in a target, e.g. compiling just a single file with `Od/Ox` in
release builds on Visual Studio.
Diffstat (limited to 'Source/cmVisualStudio10TargetGenerator.cxx')
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 22167ca..97eb3c7 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1355,8 +1355,13 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( objectName = this->GeneratorTarget->GetObjectName(&sf); } std::string flags; + bool configDependentFlags = false; std::string defines; if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) { + + if (cmGeneratorExpression::Find(cflags) != std::string::npos) { + configDependentFlags = true; + } flags += cflags; } if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) { @@ -1412,7 +1417,8 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } // if we have flags or defines for this config then // use them - if (!flags.empty() || !configDefines.empty() || compileAs || noWinRT) { + if (!flags.empty() || configDependentFlags || !configDefines.empty() || + compileAs || noWinRT) { (*this->BuildFileStream) << firstString; firstString = ""; // only do firstString once hasFlags = true; @@ -1427,7 +1433,15 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( if (noWinRT) { clOptions.AddFlag("CompileAsWinRT", "false"); } - clOptions.Parse(flags.c_str()); + if (configDependentFlags) { + cmGeneratorExpression ge; + CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(flags); + std::string evaluatedFlags = + cge->Evaluate(this->LocalGenerator, *config); + clOptions.Parse(evaluatedFlags.c_str()); + } else { + clOptions.Parse(flags.c_str()); + } if (clOptions.HasFlag("AdditionalIncludeDirectories")) { clOptions.AppendFlag("AdditionalIncludeDirectories", "%(AdditionalIncludeDirectories)"); |