diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Source/cmExportBuildFileGenerator.cxx | 3 | ||||
-rw-r--r-- | Source/cmExportInstallFileGenerator.cxx | 4 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionDAGChecker.h | 3 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 39 | ||||
-rw-r--r-- | Source/cmLocalGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 133 | ||||
-rw-r--r-- | Source/cmMakefile.h | 4 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 159 | ||||
-rw-r--r-- | Source/cmTarget.h | 3 | ||||
-rw-r--r-- | Source/cmTargetCompileDefinitionsCommand.cxx | 3 | ||||
-rw-r--r-- | Source/cmTargetCompileDefinitionsCommand.h | 2 | ||||
-rw-r--r-- | Source/cmTargetCompileFeaturesCommand.cxx | 70 | ||||
-rw-r--r-- | Source/cmTargetCompileFeaturesCommand.h | 41 | ||||
-rw-r--r-- | Source/cmTargetCompileOptionsCommand.cxx | 3 | ||||
-rw-r--r-- | Source/cmTargetCompileOptionsCommand.h | 2 | ||||
-rw-r--r-- | Source/cmTargetIncludeDirectoriesCommand.cxx | 3 | ||||
-rw-r--r-- | Source/cmTargetIncludeDirectoriesCommand.h | 2 | ||||
-rw-r--r-- | Source/cmTargetPropCommandBase.cxx | 14 | ||||
-rw-r--r-- | Source/cmTargetPropCommandBase.h | 4 | ||||
-rw-r--r-- | Source/cmTargetSourcesCommand.cxx | 3 | ||||
-rw-r--r-- | Source/cmTargetSourcesCommand.h | 2 |
22 files changed, 483 insertions, 17 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 4c678d8..660c0c5 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -346,6 +346,7 @@ foreach(command_file cmSourceGroupCommand cmSubdirDependsCommand cmTargetCompileDefinitionsCommand + cmTargetCompileFeaturesCommand cmTargetCompileOptionsCommand cmTargetIncludeDirectoriesCommand cmTargetSourcesCommand diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index e79206d..6c8ebb6 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -85,6 +85,9 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) this->PopulateInterfaceProperty("INTERFACE_AUTOUIC_OPTIONS", te, cmGeneratorExpression::BuildInterface, properties, missingTargets); + this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES", te, + cmGeneratorExpression::BuildInterface, + properties, missingTargets); this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", te, properties); const bool newCMP0022Behavior = diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index a83a228..89071c0 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -149,6 +149,10 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) te, cmGeneratorExpression::InstallInterface, properties, missingTargets); + this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES", + te, + cmGeneratorExpression::InstallInterface, + properties, missingTargets); const bool newCMP0022Behavior = te->GetPolicyStatusCMP0022() != cmPolicies::WARN diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h index b3147f7..7217a56 100644 --- a/Source/cmGeneratorExpressionDAGChecker.h +++ b/Source/cmGeneratorExpressionDAGChecker.h @@ -26,7 +26,8 @@ SELECT(F, EvaluatingCompileDefinitions, COMPILE_DEFINITIONS) \ SELECT(F, EvaluatingCompileOptions, COMPILE_OPTIONS) \ SELECT(F, EvaluatingAutoUicOptions, AUTOUIC_OPTIONS) \ - SELECT(F, EvaluatingSources, SOURCES) + SELECT(F, EvaluatingSources, SOURCES) \ + SELECT(F, EvaluatingCompileFeatures, COMPILE_FEATURES) #define CM_FOR_EACH_TRANSITIVE_PROPERTY(F) \ CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, CM_SELECT_BOTH) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 8e56d2f..f375b5f 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1460,6 +1460,17 @@ void cmLocalGenerator::AddCompileOptions( this->AppendFlagEscape(flags, *i); } } + std::vector<std::string> features; + target->GetCompileFeatures(features, config); + for(std::vector<std::string>::const_iterator it = features.begin(); + it != features.end(); ++it) + { + if (!this->Makefile->AddRequiredTargetFeature(target, *it)) + { + return; + } + } + this->AddCompilerRequirementFlag(flags, target, lang); } //---------------------------------------------------------------------------- @@ -2131,6 +2142,34 @@ void cmLocalGenerator::AddSharedFlags(std::string& flags, } } +//---------------------------------------------------------------------------- +void cmLocalGenerator:: +AddCompilerRequirementFlag(std::string &flags, cmTarget* target, + const std::string& lang) +{ + if (lang.empty()) + { + return; + } + std::string stdProp = lang + "_STANDARD"; + const char *standard = target->GetProperty(stdProp); + if (!standard) + { + return; + } + std::string extProp = lang + "_EXTENSIONS"; + bool ext = target->GetPropertyAsBool(extProp); + std::string type = ext ? "EXTENSION" : "STANDARD"; + + std::string compile_option = + "CMAKE_" + lang + std::string(standard) + + "_" + type + "_COMPILE_OPTION"; + if (const char *opt = target->GetMakefile()->GetDefinition(compile_option)) + { + this->AppendFlags(flags, opt); + } +} + static void AddVisibilityCompileOption(std::string &flags, cmTarget* target, cmLocalGenerator *lg, const std::string& lang) diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 8090b34..cf754aa 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -149,6 +149,8 @@ public: const std::string& lang); void AddConfigVariableFlags(std::string& flags, const std::string& var, const std::string& config); + void AddCompilerRequirementFlag(std::string &flags, cmTarget* target, + const std::string& lang); ///! Append flags to a string. virtual void AppendFlags(std::string& flags, const char* newFlags); virtual void AppendFlagEscape(std::string& flags, diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 1328974..5004a08 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -41,6 +41,9 @@ #include <ctype.h> // for isspace #include <assert.h> +#define FOR_EACH_CXX_FEATURE(F) \ + F(cxx_auto_type) + class cmMakefile::Internals { public: @@ -2451,6 +2454,12 @@ const char* cmMakefile::GetDefinition(const std::string& name) const { this->Internal->VarUsageStack.top().insert(name); } + if (name == "CMAKE_CXX_KNOWN_FEATURES") + { +#define STRING_LIST_ELEMENT(F) ";" #F + return FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT) + 1; +#undef STRING_LIST_ELEMENT + } const char* def = this->Internal->VarStack.top().Get(name); if(!def) { @@ -4494,3 +4503,127 @@ void cmMakefile::RecordPolicies(cmPolicies::PolicyMap& pm) pm[pid] = this->GetPolicyStatus(pid); } } + +#define FEATURE_STRING(F) , #F + +static const char * const CXX_FEATURES[] = { + 0 + FOR_EACH_CXX_FEATURE(FEATURE_STRING) +}; + +static const char * const CXX_STANDARDS[] = { + "98" + , "11" +}; + +//---------------------------------------------------------------------------- +bool cmMakefile:: +AddRequiredTargetFeature(cmTarget *target, const std::string& feature, + std::string *error) const +{ + if (cmGeneratorExpression::Find(feature) != std::string::npos) + { + target->AppendProperty("COMPILE_FEATURES", feature.c_str()); + return true; + } + bool isCxxFeature = std::find_if(cmArrayBegin(CXX_FEATURES) + 1, + cmArrayEnd(CXX_FEATURES), cmStrCmp(feature)) + != cmArrayEnd(CXX_FEATURES); + if (!isCxxFeature) + { + cmOStringStream e; + if (error) + { + e << "specified"; + } + else + { + e << "Specified"; + } + e << " unknown feature \"" << feature << "\" for " + "target \"" << target->GetName() << "\"."; + if (error) + { + *error = e.str(); + } + else + { + this->IssueMessage(cmake::FATAL_ERROR, e.str()); + } + return false; + } + + std::string lang = "CXX"; + + const char* featuresKnown = + this->GetDefinition("CMAKE_" + lang + "_COMPILE_FEATURES"); + + if (!featuresKnown || !*featuresKnown) + { + // We know of no features for the compiler at all. + return true; + } + + std::vector<std::string> availableFeatures; + cmSystemTools::ExpandListArgument(featuresKnown, availableFeatures); + if (std::find(availableFeatures.begin(), + availableFeatures.end(), + feature) == availableFeatures.end()) + { + cmOStringStream e; + e << "The compiler feature \"" << feature + << "\" is not known to compiler\n\"" + << this->GetDefinition("CMAKE_" + lang + "_COMPILER_ID") + << "\"\nversion " + << this->GetDefinition("CMAKE_" + lang + "_COMPILER_VERSION") << "."; + this->IssueMessage(cmake::FATAL_ERROR, e.str()); + return false; + } + + target->AppendProperty("COMPILE_FEATURES", feature.c_str()); + + bool needCxx11 = false; + + if (const char *propCxx11 = + this->GetDefinition("CMAKE_CXX11_COMPILE_FEATURES")) + { + std::vector<std::string> props; + cmSystemTools::ExpandListArgument(propCxx11, props); + needCxx11 = std::find(props.begin(), props.end(), feature) != props.end(); + } + + const char *existingCxxStandard = target->GetProperty("CXX_STANDARD"); + if (existingCxxStandard) + { + if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), + cmStrCmp(existingCxxStandard)) == cmArrayEnd(CXX_STANDARDS)) + { + cmOStringStream e; + e << "The CXX_STANDARD property on target \"" << target->GetName() + << "\" contained an invalid value: \"" << existingCxxStandard << "\"."; + this->IssueMessage(cmake::FATAL_ERROR, e.str()); + return false; + } + } + const char * const *existingCxxIt = existingCxxStandard + ? std::find_if(cmArrayBegin(CXX_STANDARDS), + cmArrayEnd(CXX_STANDARDS), + cmStrCmp(existingCxxStandard)) + : cmArrayEnd(CXX_STANDARDS); + + bool setCxx11 = needCxx11 && !existingCxxStandard; + + if (needCxx11 && existingCxxStandard && existingCxxIt < + std::find_if(cmArrayBegin(CXX_STANDARDS), + cmArrayEnd(CXX_STANDARDS), + cmStrCmp("11"))) + { + setCxx11 = true; + } + + if (setCxx11) + { + target->SetProperty("CXX_STANDARD", "11"); + } + return true; +} diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 7695d6e..3bccb63 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -885,6 +885,10 @@ public: bool PolicyOptionalWarningEnabled(std::string const& var); + bool AddRequiredTargetFeature(cmTarget *target, + const std::string& feature, + std::string *error = 0) const; + protected: // add link libraries and directories to the target void AddGlobalLinkInformation(const std::string& name, cmTarget& target); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 6a87342..ee6cb44 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -153,6 +153,7 @@ public: }; std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries; std::vector<TargetPropertyEntry*> CompileOptionsEntries; + std::vector<TargetPropertyEntry*> CompileFeaturesEntries; std::vector<TargetPropertyEntry*> CompileDefinitionsEntries; std::vector<TargetPropertyEntry*> SourceEntries; std::vector<cmValueWithOrigin> LinkImplementationPropertyEntries; @@ -165,11 +166,14 @@ public: CachedLinkInterfaceCompileDefinitionsEntries; mutable std::map<std::string, std::vector<TargetPropertyEntry*> > CachedLinkInterfaceSourcesEntries; + mutable std::map<std::string, std::vector<TargetPropertyEntry*> > + CachedLinkInterfaceCompileFeaturesEntries; mutable std::map<std::string, bool> CacheLinkInterfaceIncludeDirectoriesDone; mutable std::map<std::string, bool> CacheLinkInterfaceCompileDefinitionsDone; mutable std::map<std::string, bool> CacheLinkInterfaceCompileOptionsDone; mutable std::map<std::string, bool> CacheLinkInterfaceSourcesDone; + mutable std::map<std::string, bool> CacheLinkInterfaceCompileFeaturesDone; }; //---------------------------------------------------------------------------- @@ -204,6 +208,7 @@ cmTargetInternals::~cmTargetInternals() { deleteAndClear(this->CachedLinkInterfaceIncludeDirectoriesEntries); deleteAndClear(this->CachedLinkInterfaceCompileOptionsEntries); + deleteAndClear(this->CachedLinkInterfaceCompileFeaturesEntries); deleteAndClear(this->CachedLinkInterfaceCompileDefinitionsEntries); deleteAndClear(this->CachedLinkInterfaceSourcesEntries); } @@ -227,6 +232,7 @@ cmTarget::cmTarget() this->BuildInterfaceIncludesAppended = false; this->DebugIncludesDone = false; this->DebugCompileOptionsDone = false; + this->DebugCompileFeaturesDone = false; this->DebugCompileDefinitionsDone = false; this->DebugSourcesDone = false; this->LinkImplementationLanguageIsContextDependent = true; @@ -308,6 +314,8 @@ void cmTarget::SetMakefile(cmMakefile* mf) this->SetPropertyDefault("MACOSX_BUNDLE", 0); this->SetPropertyDefault("MACOSX_RPATH", 0); this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0); + this->SetPropertyDefault("CXX_STANDARD", 0); + this->SetPropertyDefault("CXX_EXTENSIONS", 0); } // Collect the set of configuration types. @@ -1803,6 +1811,17 @@ void cmTarget::SetProperty(const std::string& prop, const char* value) new cmTargetInternals::TargetPropertyEntry(cge)); return; } + if(prop == "COMPILE_FEATURES") + { + cmListFileBacktrace lfbt; + this->Makefile->GetBacktrace(lfbt); + cmGeneratorExpression ge(lfbt); + deleteAndClear(this->Internal->CompileFeaturesEntries); + cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value); + this->Internal->CompileFeaturesEntries.push_back( + new cmTargetInternals::TargetPropertyEntry(cge)); + return; + } if(prop == "COMPILE_DEFINITIONS") { cmListFileBacktrace lfbt; @@ -1893,6 +1912,15 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value, new cmTargetInternals::TargetPropertyEntry(ge.Parse(value))); return; } + if(prop == "COMPILE_FEATURES") + { + cmListFileBacktrace lfbt; + this->Makefile->GetBacktrace(lfbt); + cmGeneratorExpression ge(lfbt); + this->Internal->CompileFeaturesEntries.push_back( + new cmTargetInternals::TargetPropertyEntry(ge.Parse(value))); + return; + } if(prop == "COMPILE_DEFINITIONS") { cmListFileBacktrace lfbt; @@ -2677,6 +2705,118 @@ void cmTarget::GetCompileDefinitions(std::vector<std::string> &list, } //---------------------------------------------------------------------------- +static void processCompileFeatures(cmTarget const* tgt, + const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries, + std::vector<std::string> &options, + std::set<std::string> &uniqueOptions, + cmGeneratorExpressionDAGChecker *dagChecker, + const std::string& config, bool debugOptions) +{ + processCompileOptionsInternal(tgt, entries, options, uniqueOptions, + dagChecker, config, debugOptions, "features"); +} + +//---------------------------------------------------------------------------- +void cmTarget::GetCompileFeatures(std::vector<std::string> &result, + const std::string& config) const +{ + std::set<std::string> uniqueFeatures; + cmListFileBacktrace lfbt; + + cmGeneratorExpressionDAGChecker dagChecker(lfbt, + this->GetName(), + "COMPILE_FEATURES", + 0, 0); + + std::vector<std::string> debugProperties; + const char *debugProp = + this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES"); + if (debugProp) + { + cmSystemTools::ExpandListArgument(debugProp, debugProperties); + } + + bool debugFeatures = !this->DebugCompileFeaturesDone + && std::find(debugProperties.begin(), + debugProperties.end(), + "COMPILE_FEATURES") + != debugProperties.end(); + + if (this->Makefile->IsGeneratingBuildSystem()) + { + this->DebugCompileFeaturesDone = true; + } + + processCompileFeatures(this, + this->Internal->CompileFeaturesEntries, + result, + uniqueFeatures, + &dagChecker, + config, + debugFeatures); + + if (!this->Internal->CacheLinkInterfaceCompileFeaturesDone[config]) + { + for (std::vector<cmValueWithOrigin>::const_iterator + it = this->Internal->LinkImplementationPropertyEntries.begin(), + end = this->Internal->LinkImplementationPropertyEntries.end(); + it != end; ++it) + { + if (!cmGeneratorExpression::IsValidTargetName(it->Value) + && cmGeneratorExpression::Find(it->Value) == std::string::npos) + { + continue; + } + { + cmGeneratorExpression ge(lfbt); + cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = + ge.Parse(it->Value); + std::string targetResult = cge->Evaluate(this->Makefile, config, + false, this, 0, 0); + if (!this->Makefile->FindTargetToUse(targetResult)) + { + continue; + } + } + std::string featureGenex = "$<TARGET_PROPERTY:" + + it->Value + ",INTERFACE_COMPILE_FEATURES>"; + if (cmGeneratorExpression::Find(it->Value) != std::string::npos) + { + // Because it->Value is a generator expression, ensure that it + // evaluates to the non-empty string before being used in the + // TARGET_PROPERTY expression. + featureGenex = "$<$<BOOL:" + it->Value + ">:" + featureGenex + ">"; + } + cmGeneratorExpression ge(it->Backtrace); + cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse( + featureGenex); + + this->Internal + ->CachedLinkInterfaceCompileFeaturesEntries[config].push_back( + new cmTargetInternals::TargetPropertyEntry(cge, + it->Value)); + } + } + + processCompileFeatures(this, + this->Internal->CachedLinkInterfaceCompileFeaturesEntries[config], + result, + uniqueFeatures, + &dagChecker, + config, + debugFeatures); + + if (!this->Makefile->IsGeneratingBuildSystem()) + { + deleteAndClear(this->Internal->CachedLinkInterfaceCompileFeaturesEntries); + } + else + { + this->Internal->CacheLinkInterfaceCompileFeaturesDone[config] = true; + } +} + +//---------------------------------------------------------------------------- void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop) { // Wipe out maps caching information affected by this property. @@ -3190,6 +3330,24 @@ const char *cmTarget::GetProperty(const std::string& prop, } return output.c_str(); } + if(prop == "COMPILE_FEATURES") + { + static std::string output; + output = ""; + std::string sep; + typedef cmTargetInternals::TargetPropertyEntry + TargetPropertyEntry; + for (std::vector<TargetPropertyEntry*>::const_iterator + it = this->Internal->CompileFeaturesEntries.begin(), + end = this->Internal->CompileFeaturesEntries.end(); + it != end; ++it) + { + output += sep; + output += (*it)->ge->GetInput(); + sep = ";"; + } + return output.c_str(); + } if(prop == "COMPILE_DEFINITIONS") { static std::string output; @@ -6987,6 +7145,7 @@ cmTargetInternalPointer::~cmTargetInternalPointer() { deleteAndClear(this->Pointer->IncludeDirectoriesEntries); deleteAndClear(this->Pointer->CompileOptionsEntries); + deleteAndClear(this->Pointer->CompileFeaturesEntries); deleteAndClear(this->Pointer->CompileDefinitionsEntries); deleteAndClear(this->Pointer->SourceEntries); delete this->Pointer; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 0a086cb..4d8022e 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -549,6 +549,8 @@ public: const std::string& config) const; void GetAutoUicOptions(std::vector<std::string> &result, const std::string& config) const; + void GetCompileFeatures(std::vector<std::string> &features, + const std::string& config) const; bool IsNullImpliedByLinkLibraries(const std::string &p) const; bool IsLinkInterfaceDependentBoolProperty(const std::string &p, @@ -715,6 +717,7 @@ private: mutable bool DebugCompileOptionsDone; mutable bool DebugCompileDefinitionsDone; mutable bool DebugSourcesDone; + mutable bool DebugCompileFeaturesDone; mutable std::set<std::string> LinkImplicitNullProperties; bool BuildInterfaceIncludesAppended; diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx index b567252..66d8ad3 100644 --- a/Source/cmTargetCompileDefinitionsCommand.cxx +++ b/Source/cmTargetCompileDefinitionsCommand.cxx @@ -58,9 +58,10 @@ std::string cmTargetCompileDefinitionsCommand } //---------------------------------------------------------------------------- -void cmTargetCompileDefinitionsCommand +bool cmTargetCompileDefinitionsCommand ::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content, bool, bool) { tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str()); + return true; } diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h index 5ba9e03..b548c70 100644 --- a/Source/cmTargetCompileDefinitionsCommand.h +++ b/Source/cmTargetCompileDefinitionsCommand.h @@ -44,7 +44,7 @@ private: virtual void HandleImportedTarget(const std::string &tgt); virtual void HandleMissingTarget(const std::string &name); - virtual void HandleDirectContent(cmTarget *tgt, + virtual bool HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content, bool prepend, bool system); virtual std::string Join(const std::vector<std::string> &content); diff --git a/Source/cmTargetCompileFeaturesCommand.cxx b/Source/cmTargetCompileFeaturesCommand.cxx new file mode 100644 index 0000000..10daad4 --- /dev/null +++ b/Source/cmTargetCompileFeaturesCommand.cxx @@ -0,0 +1,70 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2013 Stephen Kelly <steveire@gmail.com> + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmTargetCompileFeaturesCommand.h" + +bool cmTargetCompileFeaturesCommand::InitialPass( + std::vector<std::string> const& args, + cmExecutionStatus &) +{ + return this->HandleArguments(args, "COMPILE_FEATURES", NO_FLAGS); +} + +void cmTargetCompileFeaturesCommand +::HandleImportedTarget(const std::string &tgt) +{ + cmOStringStream e; + e << "Cannot specify compile features for imported target \"" + << tgt << "\"."; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); +} + +void cmTargetCompileFeaturesCommand +::HandleMissingTarget(const std::string &name) +{ + cmOStringStream e; + e << "Cannot specify compile features for target \"" << name << "\" " + "which is not built by this project."; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); +} + +//---------------------------------------------------------------------------- +std::string cmTargetCompileFeaturesCommand +::Join(const std::vector<std::string> &content) +{ + std::string defs; + std::string sep; + for(std::vector<std::string>::const_iterator it = content.begin(); + it != content.end(); ++it) + { + defs += sep + *it; + sep = ";"; + } + return defs; +} + +//---------------------------------------------------------------------------- +bool cmTargetCompileFeaturesCommand +::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content, + bool, bool) +{ + for(std::vector<std::string>::const_iterator it = content.begin(); + it != content.end(); ++it) + { + std::string error; + if(!this->Makefile->AddRequiredTargetFeature(tgt, *it, &error)) + { + this->SetError(error); + return false; + } + } + return true; +} diff --git a/Source/cmTargetCompileFeaturesCommand.h b/Source/cmTargetCompileFeaturesCommand.h new file mode 100644 index 0000000..fa7ae8d --- /dev/null +++ b/Source/cmTargetCompileFeaturesCommand.h @@ -0,0 +1,41 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2013 Stephen Kelly <steveire@gmail.com> + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmTargetCompileFeaturesCommand_h +#define cmTargetCompileFeaturesCommand_h + +#include "cmTargetPropCommandBase.h" + +class cmTargetCompileFeaturesCommand : public cmTargetPropCommandBase +{ + virtual cmCommand* Clone() + { + return new cmTargetCompileFeaturesCommand; + } + + virtual bool InitialPass(std::vector<std::string> const& args, + cmExecutionStatus &status); + + virtual std::string GetName() const { return "target_compile_features";} + + cmTypeMacro(cmTargetCompileFeaturesCommand, cmTargetPropCommandBase); + +private: + virtual void HandleImportedTarget(const std::string &tgt); + virtual void HandleMissingTarget(const std::string &name); + + virtual bool HandleDirectContent(cmTarget *tgt, + const std::vector<std::string> &content, + bool prepend, bool system); + virtual std::string Join(const std::vector<std::string> &content); +}; + +#endif diff --git a/Source/cmTargetCompileOptionsCommand.cxx b/Source/cmTargetCompileOptionsCommand.cxx index 254acc7..18499fd 100644 --- a/Source/cmTargetCompileOptionsCommand.cxx +++ b/Source/cmTargetCompileOptionsCommand.cxx @@ -51,7 +51,7 @@ std::string cmTargetCompileOptionsCommand } //---------------------------------------------------------------------------- -void cmTargetCompileOptionsCommand +bool cmTargetCompileOptionsCommand ::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content, bool, bool) { @@ -59,4 +59,5 @@ void cmTargetCompileOptionsCommand this->Makefile->GetBacktrace(lfbt); cmValueWithOrigin entry(this->Join(content), lfbt); tgt->InsertCompileOption(entry); + return true; } diff --git a/Source/cmTargetCompileOptionsCommand.h b/Source/cmTargetCompileOptionsCommand.h index d58dc07..d43534d 100644 --- a/Source/cmTargetCompileOptionsCommand.h +++ b/Source/cmTargetCompileOptionsCommand.h @@ -44,7 +44,7 @@ private: virtual void HandleImportedTarget(const std::string &tgt); virtual void HandleMissingTarget(const std::string &name); - virtual void HandleDirectContent(cmTarget *tgt, + virtual bool HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content, bool prepend, bool system); virtual std::string Join(const std::vector<std::string> &content); diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx index f8e1188..caec7eb 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.cxx +++ b/Source/cmTargetIncludeDirectoriesCommand.cxx @@ -66,7 +66,7 @@ std::string cmTargetIncludeDirectoriesCommand } //---------------------------------------------------------------------------- -void cmTargetIncludeDirectoriesCommand +bool cmTargetIncludeDirectoriesCommand ::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content, bool prepend, bool system) { @@ -78,6 +78,7 @@ void cmTargetIncludeDirectoriesCommand { tgt->AddSystemIncludeDirectories(content); } + return true; } //---------------------------------------------------------------------------- diff --git a/Source/cmTargetIncludeDirectoriesCommand.h b/Source/cmTargetIncludeDirectoriesCommand.h index c8b22fb..2a7814e 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.h +++ b/Source/cmTargetIncludeDirectoriesCommand.h @@ -45,7 +45,7 @@ private: virtual void HandleImportedTarget(const std::string &tgt); virtual void HandleMissingTarget(const std::string &name); - virtual void HandleDirectContent(cmTarget *tgt, + virtual bool HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content, bool prepend, bool system); virtual void HandleInterfaceContent(cmTarget *tgt, diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx index d356611..4696de4 100644 --- a/Source/cmTargetPropCommandBase.cxx +++ b/Source/cmTargetPropCommandBase.cxx @@ -132,29 +132,31 @@ bool cmTargetPropCommandBase || args[i] == "PRIVATE" || args[i] == "INTERFACE" ) { - this->PopulateTargetProperies(scope, content, prepend, system); - return true; + return this->PopulateTargetProperies(scope, content, prepend, system); } content.push_back(args[i]); } - this->PopulateTargetProperies(scope, content, prepend, system); - return true; + return this->PopulateTargetProperies(scope, content, prepend, system); } //---------------------------------------------------------------------------- -void cmTargetPropCommandBase +bool cmTargetPropCommandBase ::PopulateTargetProperies(const std::string &scope, const std::vector<std::string> &content, bool prepend, bool system) { if (scope == "PRIVATE" || scope == "PUBLIC") { - this->HandleDirectContent(this->Target, content, prepend, system); + if (!this->HandleDirectContent(this->Target, content, prepend, system)) + { + return false; + } } if (scope == "INTERFACE" || scope == "PUBLIC") { this->HandleInterfaceContent(this->Target, content, prepend, system); } + return true; } //---------------------------------------------------------------------------- diff --git a/Source/cmTargetPropCommandBase.h b/Source/cmTargetPropCommandBase.h index 555a08a..d42b588 100644 --- a/Source/cmTargetPropCommandBase.h +++ b/Source/cmTargetPropCommandBase.h @@ -44,7 +44,7 @@ private: virtual void HandleImportedTarget(const std::string &tgt) = 0; virtual void HandleMissingTarget(const std::string &name) = 0; - virtual void HandleDirectContent(cmTarget *tgt, + virtual bool HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content, bool prepend, bool system) = 0; @@ -52,7 +52,7 @@ private: bool ProcessContentArgs(std::vector<std::string> const& args, unsigned int &argIndex, bool prepend, bool system); - void PopulateTargetProperies(const std::string &scope, + bool PopulateTargetProperies(const std::string &scope, const std::vector<std::string> &content, bool prepend, bool system); }; diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index e82b36d..ce3b11e 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -56,9 +56,10 @@ std::string cmTargetSourcesCommand } //---------------------------------------------------------------------------- -void cmTargetSourcesCommand +bool cmTargetSourcesCommand ::HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content, bool, bool) { tgt->AppendProperty("SOURCES", this->Join(content).c_str()); + return true; } diff --git a/Source/cmTargetSourcesCommand.h b/Source/cmTargetSourcesCommand.h index dae78c4..a170e36 100644 --- a/Source/cmTargetSourcesCommand.h +++ b/Source/cmTargetSourcesCommand.h @@ -45,7 +45,7 @@ private: virtual void HandleImportedTarget(const std::string &tgt); virtual void HandleMissingTarget(const std::string &name); - virtual void HandleDirectContent(cmTarget *tgt, + virtual bool HandleDirectContent(cmTarget *tgt, const std::vector<std::string> &content, bool prepend, bool system); |