diff options
author | Marc Chevrier <marc.chevrier@sap.com> | 2017-12-01 16:10:45 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-12-04 14:10:09 (GMT) |
commit | 6bffc13ef1c85ec565273d25e811fd6c326533f0 (patch) | |
tree | 752484518da79d7edfe4ba98880f1ce7d694478c /Source/cmGlobalXCodeGenerator.cxx | |
parent | a4faf8638744edf7e3dd8931b55ba87e8f7738be (diff) | |
download | CMake-6bffc13ef1c85ec565273d25e811fd6c326533f0.zip CMake-6bffc13ef1c85ec565273d25e811fd6c326533f0.tar.gz CMake-6bffc13ef1c85ec565273d25e811fd6c326533f0.tar.bz2 |
Refactor per-source generator expression evaluation
Prepare to add generator expression support to more source properties.
Factor out some duplicated code into a helper to avoid further
duplication.
Diffstat (limited to 'Source/cmGlobalXCodeGenerator.cxx')
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index c376c8d..63f708b 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -676,9 +676,51 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFileFromPath( return buildFile; } +class XCodeGeneratorExpressionInterpreter + : public cmGeneratorExpressionInterpreter +{ + CM_DISABLE_COPY(XCodeGeneratorExpressionInterpreter) + +public: + XCodeGeneratorExpressionInterpreter(cmSourceFile* sourceFile, + cmLocalGenerator* localGenerator, + cmGeneratorTarget* generatorTarget) + : cmGeneratorExpressionInterpreter(localGenerator, generatorTarget, + "NO-PER-CONFIG-SUPPORT-IN-XCODE") + , SourceFile(sourceFile) + { + } + + using cmGeneratorExpressionInterpreter::Evaluate; + + const char* Evaluate(const char* expression, const char* property) + { + const char* processed = this->Evaluate(expression); + if (this->GetCompiledGeneratorExpression() + .GetHadContextSensitiveCondition()) { + std::ostringstream e; + /* clang-format off */ + e << + "Xcode does not support per-config per-source " << property << ":\n" + " " << expression << "\n" + "specified for source:\n" + " " << this->SourceFile->GetFullPath() << "\n"; + /* clang-format on */ + this->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str()); + } + + return processed; + } + +private: + cmSourceFile* SourceFile = nullptr; +}; + cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile( cmLocalGenerator* lg, cmSourceFile* sf, cmGeneratorTarget* gtgt) { + XCodeGeneratorExpressionInterpreter genexInterpreter(sf, lg, gtgt); + // Add flags from target and source file properties. std::string flags; const char* srcfmt = sf->GetProperty("Fortran_FORMAT"); @@ -693,24 +735,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile( break; } if (const char* cflags = sf->GetProperty("COMPILE_FLAGS")) { - cmGeneratorExpression ge; - std::string configName = "NO-PER-CONFIG-SUPPORT-IN-XCODE"; - std::unique_ptr<cmCompiledGeneratorExpression> compiledExpr = - ge.Parse(cflags); - const char* processed = - compiledExpr->Evaluate(lg, configName, false, gtgt); - if (compiledExpr->GetHadContextSensitiveCondition()) { - std::ostringstream e; - /* clang-format off */ - e << - "Xcode does not support per-config per-source COMPILE_FLAGS:\n" - " " << cflags << "\n" - "specified for source:\n" - " " << sf->GetFullPath() << "\n"; - /* clang-format on */ - lg->IssueMessage(cmake::FATAL_ERROR, e.str()); - } - lg->AppendFlags(flags, processed); + lg->AppendFlags(flags, genexInterpreter.Evaluate(cflags, "COMPILE_FLAGS")); } // Add per-source definitions. |