From beaa7e037761c734d7587b847d8af1ce3dce37d9 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 18 Mar 2014 17:46:37 +0100 Subject: cmGeneratorTarget: Compute the object directory early. Ensure it is populated before tracing dependencies. --- Source/cmGlobalGenerator.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 5b6d729..07637b3 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1407,6 +1407,7 @@ void cmGlobalGenerator::CreateGeneratorTargets(cmMakefile *mf) { cmTarget* t = &ti->second; cmGeneratorTarget* gt = new cmGeneratorTarget(t); + this->ComputeTargetObjectDirectory(gt); this->GeneratorTargets[t] = gt; generatorTargets[t] = gt; } @@ -1449,7 +1450,6 @@ void cmGlobalGenerator::ComputeGeneratorTargetObjects() continue; } cmGeneratorTarget* gt = ti->second; - this->ComputeTargetObjectDirectory(gt); gt->LookupObjectLibraries(); this->ComputeTargetObjects(gt); } -- cgit v0.12 From 99a9c51f1a65b58f366506929b3b82297809c1ca Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 12 Mar 2014 12:29:58 +0100 Subject: cmTarget: Use GetSourceFiles for languages. --- Source/cmTarget.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 17c8a4d..a7c4488 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -4844,8 +4844,10 @@ bool cmTarget::IsLinkInterfaceDependentNumberMaxProperty(const std::string &p, //---------------------------------------------------------------------------- void cmTarget::GetLanguages(std::set& languages) const { + std::vector sourceFiles; + this->GetSourceFiles(sourceFiles); for(std::vector::const_iterator - i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i) + i = sourceFiles.begin(); i != sourceFiles.end(); ++i) { const std::string& lang = (*i)->GetLanguage(); if(!lang.empty()) -- cgit v0.12 From 0ed5ce4cd8cdd7613a5fa43c9a9fc48f210c90f6 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 17 Mar 2014 16:54:11 +0100 Subject: cmTarget: Rename AddSource method for backward compatibility. Add a new AddSource method for future use. --- Source/cmGlobalXCodeGenerator.cxx | 4 ++-- Source/cmMakefile.cxx | 2 +- Source/cmTarget.cxx | 9 +++++++-- Source/cmTarget.h | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index d4eb85b..f93fc12 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -412,7 +412,7 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root, std::string listfile = mf->GetStartDirectory(); listfile += "/"; listfile += "CMakeLists.txt"; - allbuild->AddSource(listfile.c_str()); + allbuild->AddSourceCMP0049(listfile.c_str()); // Add XCODE depend helper std::string dir = mf->GetCurrentOutputDirectory(); @@ -495,7 +495,7 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root, listfile = lg->GetMakefile()->GetStartDirectory(); listfile += "/"; listfile += "CMakeLists.txt"; - target.AddSource(listfile.c_str()); + target.AddSourceCMP0049(listfile.c_str()); } } } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index dce71de..1fcbcd7 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1266,7 +1266,7 @@ cmMakefile::AddUtilityCommand(const std::string& utilityName, commandLines, comment, workingDirectory, no_replace, escapeOldStyle); - cmSourceFile* sf = target->AddSource(force); + cmSourceFile* sf = target->AddSourceCMP0049(force); // The output is not actually created so mark it symbolic. if(sf) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index a7c4488..835aaad 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -587,13 +587,13 @@ void cmTarget::AddSources(std::vector const& srcs) } else { - this->AddSource(src); + this->AddSourceCMP0049(src); } } } //---------------------------------------------------------------------------- -cmSourceFile* cmTarget::AddSource(const std::string& s) +cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s) { std::string src = s; @@ -632,7 +632,12 @@ cmSourceFile* cmTarget::AddSource(const std::string& s) } } } + return this->AddSource(src); +} +//---------------------------------------------------------------------------- +cmSourceFile* cmTarget::AddSource(const std::string& src) +{ cmSourceFile* sf = this->Makefile->GetOrCreateSource(src); this->AddSourceFile(sf); return sf; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 3ef853b..e385443 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -146,6 +146,7 @@ public: * Add sources to the target. */ void AddSources(std::vector const& srcs); + cmSourceFile* AddSourceCMP0049(const std::string& src); cmSourceFile* AddSource(const std::string& src); enum LinkLibraryType {GENERAL, DEBUG, OPTIMIZED}; -- cgit v0.12 From b1cbba68ce44bf8d78a6e41ff465461f0abf83a9 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Feb 2014 13:26:05 +0100 Subject: cmSourceFileLocation: Make copyable and assignable. This allows using it in containers and algorithms. --- Source/cmSourceFileLocation.cxx | 41 +++++++++++++++++++++++++++++++++++++++++ Source/cmSourceFileLocation.h | 3 +++ 2 files changed, 44 insertions(+) diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx index 30a53cb..3e78b29 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -16,6 +16,42 @@ #include "cmGlobalGenerator.h" #include "cmSystemTools.h" +#include "assert.h" + +//---------------------------------------------------------------------------- +cmSourceFileLocation::cmSourceFileLocation() + : Makefile(0), AmbiguousDirectory(true), AmbiguousExtension(true) +{ + +} + +//---------------------------------------------------------------------------- +cmSourceFileLocation::cmSourceFileLocation(const cmSourceFileLocation& loc) + : Makefile(loc.Makefile) +{ + this->AmbiguousDirectory = loc.AmbiguousDirectory; + this->AmbiguousExtension = loc.AmbiguousExtension; + this->Directory = loc.Directory; + this->Name = loc.Name; +} + +//---------------------------------------------------------------------------- +cmSourceFileLocation& +cmSourceFileLocation::operator=(const cmSourceFileLocation& loc) +{ + if(this == &loc) + { + return *this; + } + this->Makefile = loc.Makefile; + this->AmbiguousDirectory = loc.AmbiguousDirectory; + this->AmbiguousExtension = loc.AmbiguousExtension; + this->Directory = loc.Directory; + this->Name = loc.Name; + this->UpdateExtension(this->Name); + return *this; +} + //---------------------------------------------------------------------------- cmSourceFileLocation ::cmSourceFileLocation(cmMakefile const* mf, const std::string& name) @@ -59,6 +95,7 @@ void cmSourceFileLocation::Update(cmSourceFileLocation const& loc) //---------------------------------------------------------------------------- void cmSourceFileLocation::DirectoryUseSource() { + assert(this->Makefile); if(this->AmbiguousDirectory) { this->Directory = @@ -71,6 +108,7 @@ void cmSourceFileLocation::DirectoryUseSource() //---------------------------------------------------------------------------- void cmSourceFileLocation::DirectoryUseBinary() { + assert(this->Makefile); if(this->AmbiguousDirectory) { this->Directory = @@ -83,6 +121,7 @@ void cmSourceFileLocation::DirectoryUseBinary() //---------------------------------------------------------------------------- void cmSourceFileLocation::UpdateExtension(const std::string& name) { + assert(this->Makefile); // Check the extension. std::string ext = cmSystemTools::GetFilenameLastExtension(name); if(!ext.empty()) { ext = ext.substr(1); } @@ -152,6 +191,7 @@ bool cmSourceFileLocation ::MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const { + assert(this->Makefile); // This location's extension is not ambiguous but loc's extension // is. See if the names match as-is. if(this->Name == loc.Name) @@ -188,6 +228,7 @@ cmSourceFileLocation //---------------------------------------------------------------------------- bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc) { + assert(this->Makefile); if(this->AmbiguousExtension && loc.AmbiguousExtension) { // Both extensions are ambiguous. Since only the old fixed set of diff --git a/Source/cmSourceFileLocation.h b/Source/cmSourceFileLocation.h index c83e8c0..82a62ab 100644 --- a/Source/cmSourceFileLocation.h +++ b/Source/cmSourceFileLocation.h @@ -34,6 +34,9 @@ public: * instance with an initial name. */ cmSourceFileLocation(cmMakefile const* mf, const std::string& name); + cmSourceFileLocation(); + cmSourceFileLocation(const cmSourceFileLocation& loc); + cmSourceFileLocation& operator=(const cmSourceFileLocation& loc); /** * Return whether the givne source file location could refers to the -- cgit v0.12 From d38423ecc4105d8339b7461130b964f3c69e8847 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 17 Mar 2014 17:49:38 +0100 Subject: cmTarget: Add a method to obtain list of filenames for sources. --- Source/cmGeneratorTarget.cxx | 24 ++++++++++++------------ Source/cmTarget.cxx | 14 ++++++++++++++ Source/cmTarget.h | 1 + 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index b35e859..834f9fd 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -600,12 +600,12 @@ private: cmGlobalGenerator const* GlobalGenerator; typedef cmGeneratorTarget::SourceEntry SourceEntry; SourceEntry* CurrentEntry; - std::queue SourceQueue; - std::set SourcesQueued; + std::queue SourceQueue; + std::set SourcesQueued; typedef std::map NameMapType; NameMapType NameMap; - void QueueSource(cmSourceFile* sf); + void QueueSource(std::string const& name); void FollowName(std::string const& name); void FollowNames(std::vector const& names); bool IsUtility(std::string const& dep); @@ -628,11 +628,11 @@ cmTargetTraceDependencies this->CurrentEntry = 0; // Queue all the source files already specified for the target. - std::vector sources; if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY) { + std::vector sources; this->Target->GetSourceFiles(sources); - for(std::vector::const_iterator si = sources.begin(); + for(std::vector::const_iterator si = sources.begin(); si != sources.end(); ++si) { this->QueueSource(*si); @@ -652,7 +652,8 @@ void cmTargetTraceDependencies::Trace() while(!this->SourceQueue.empty()) { // Get the next source from the queue. - cmSourceFile* sf = this->SourceQueue.front(); + std::string src = this->SourceQueue.front(); + cmSourceFile* sf = this->Makefile->GetSource(src); this->SourceQueue.pop(); this->CurrentEntry = &this->GeneratorTarget->SourceEntries[sf]; @@ -680,14 +681,14 @@ void cmTargetTraceDependencies::Trace() } //---------------------------------------------------------------------------- -void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf) +void cmTargetTraceDependencies::QueueSource(std::string const& name) { - if(this->SourcesQueued.insert(sf).second) + if(this->SourcesQueued.insert(name).second) { - this->SourceQueue.push(sf); + this->SourceQueue.push(name); // Make sure this file is in the target. - this->Target->AddSourceFile(sf); + this->Target->AddSource(name); } } @@ -709,8 +710,7 @@ void cmTargetTraceDependencies::FollowName(std::string const& name) { this->CurrentEntry->Depends.push_back(sf); } - - this->QueueSource(sf); + this->QueueSource(sf->GetFullPath()); } } diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 835aaad..0866d10 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -542,6 +542,20 @@ bool cmTarget::IsBundleOnApple() const } //---------------------------------------------------------------------------- +void cmTarget::GetSourceFiles(std::vector &files) const +{ + assert(this->GetType() != INTERFACE_LIBRARY); + std::vector sourceFiles; + this->GetSourceFiles(sourceFiles); + for(std::vector::const_iterator + si = sourceFiles.begin(); + si != sourceFiles.end(); ++si) + { + files.push_back((*si)->GetFullPath()); + } +} + +//---------------------------------------------------------------------------- void cmTarget::GetSourceFiles(std::vector &files) const { assert(this->GetType() != INTERFACE_LIBRARY); diff --git a/Source/cmTarget.h b/Source/cmTarget.h index e385443..8df9bd8 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -135,6 +135,7 @@ public: /** * Get the list of the source files used by this target */ + void GetSourceFiles(std::vector &files) const; void GetSourceFiles(std::vector &files) const; void AddSourceFile(cmSourceFile* sf); std::vector const& GetObjectLibraries() const -- cgit v0.12 From 26d494ba01809553e335cca4f925d14dab2c50f7 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 12 Mar 2014 12:45:14 +0100 Subject: cmTarget: Use string API to add sources to cmTarget objects. Continue to call GetOrCreateSource where necessary to create cmSourceFile objects which have the GENERATED attribute set. --- Source/cmFLTKWrapUICommand.cxx | 2 +- Source/cmGlobalVisualStudio8Generator.cxx | 3 ++- Source/cmGlobalXCodeGenerator.cxx | 6 +++--- Source/cmLocalGenerator.cxx | 4 ++-- Source/cmLocalVisualStudio6Generator.cxx | 6 +++--- Source/cmLocalVisualStudio7Generator.cxx | 4 ++-- Source/cmMakefile.cxx | 2 +- Source/cmQtAutoGenerators.cxx | 17 +++++++---------- 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index 0a36b82..e2b114a 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -168,7 +168,7 @@ void cmFLTKWrapUICommand::FinalPass() for(size_t classNum = 0; classNum < lastHeadersClass; classNum++) { this->Makefile->GetTargets()[this->Target] - .AddSourceFile(this->GeneratedSourcesClasses[classNum]); + .AddSource(this->GeneratedSourcesClasses[classNum]->GetFullPath()); } } } diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index ab4380c..e80df84 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -16,6 +16,7 @@ #include "cmVisualStudioWCEPlatformParser.h" #include "cmake.h" #include "cmGeneratedFileStream.h" +#include "cmSourceFile.h" static const char vs8generatorName[] = "Visual Studio 8 2005"; @@ -323,7 +324,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() no_main_dependency, commandLines, "Checking Build System", no_working_directory, true)) { - tgt->AddSourceFile(file); + tgt->AddSource(file->GetFullPath()); } else { diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index f93fc12..96b23d2 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1260,7 +1260,7 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget) if(cmSourceFile* sf = mf->GetOrCreateSource(fname.c_str())) { sf->SetProperty("LANGUAGE", llang.c_str()); - cmtarget.AddSourceFile(sf); + cmtarget.AddSource(fname); } } @@ -2934,8 +2934,8 @@ void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root, if(cmtarget.GetPropertyAsBool("MACOSX_BUNDLE")) { std::string plist = this->ComputeInfoPListLocation(cmtarget); - cmSourceFile* sf = mf->GetOrCreateSource(plist.c_str(), true); - cmtarget.AddSourceFile(sf); + mf->GetOrCreateSource(plist, true); + cmtarget.AddSource(plist); } std::vector classes; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index c47147c..61d2a80 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -754,8 +754,8 @@ void cmLocalGenerator::AddBuildTargetRule(const std::string& llang, comment.c_str(), this->Makefile->GetStartOutputDirectory() ); - target.Target->AddSourceFile - (this->Makefile->GetSource(targetFullPath)); + this->Makefile->GetSource(targetFullPath); + target.Target->AddSource(targetFullPath); } diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index 2ab25cc..e99f3a4 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -253,9 +253,9 @@ void cmLocalVisualStudio6Generator::AddDSPBuildRule(cmTarget& tgt) makefileIn.c_str(), commandLines, comment.c_str(), no_working_directory, true); - if(cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str())) + if(this->Makefile->GetSource(makefileIn.c_str())) { - tgt.AddSourceFile(file); + tgt.AddSource(makefileIn); } else { @@ -591,7 +591,7 @@ cmLocalVisualStudio6Generator origCommand.GetCommandLines(), comment, origCommand.GetWorkingDirectory().c_str())) { - target.AddSourceFile(outsf); + target.AddSource(outsf->GetFullPath()); } // Replace the dependencies with the output of this rule so that the diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 52524aa..e8562ca 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -117,7 +117,7 @@ void cmLocalVisualStudio7Generator::AddCMakeListsRules() { if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET) { - l->second.AddSourceFile(sf); + l->second.AddSource(sf->GetFullPath()); } } } @@ -153,7 +153,7 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets() force.c_str(), no_depends, no_main_dependency, force_commands, " ", 0, true)) { - tgt.AddSourceFile(file); + tgt.AddSource(file->GetFullPath()); } } } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 1fcbcd7..06dc0c5 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1182,7 +1182,7 @@ cmMakefile::AddCustomCommandOldStyle(const std::string& target, { if (this->Targets.find(target) != this->Targets.end()) { - this->Targets[target].AddSourceFile(sf); + this->Targets[target].AddSource(sf->GetFullPath()); } else { diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index a6e6af7..71c4630 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -187,13 +187,11 @@ bool cmQtAutoGenerators::InitializeAutogenTarget(cmTarget* target) mocCppFile += "/"; mocCppFile += automocTargetName; mocCppFile += ".cpp"; - cmSourceFile* mocCppSource = makefile->GetOrCreateSource( - mocCppFile, - true); + makefile->GetOrCreateSource(mocCppFile, true); makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", mocCppFile.c_str(), false); - target->AddSourceFile(mocCppSource); + target->AddSource(mocCppFile); } // create a custom target for running generators at buildtime: std::string autogenTargetName = getAutogenTargetName(target); @@ -479,7 +477,7 @@ void cmQtAutoGenerators::SetupSourceFiles(cmTarget const* target) const char *skipMocSep = ""; const char *skipUicSep = ""; - std::vector newRccFiles; + std::vector newRccFiles; for(std::vector::const_iterator fileIt = srcFiles.begin(); fileIt != srcFiles.end(); @@ -512,9 +510,8 @@ void cmQtAutoGenerators::SetupSourceFiles(cmTarget const* target) rcc_output_file += "/qrc_" + basename + ".cpp"; makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", rcc_output_file.c_str(), false); - cmSourceFile* rccCppSource - = makefile->GetOrCreateSource(rcc_output_file, true); - newRccFiles.push_back(rccCppSource); + makefile->GetOrCreateSource(rcc_output_file, true); + newRccFiles.push_back(rcc_output_file); } } @@ -546,11 +543,11 @@ void cmQtAutoGenerators::SetupSourceFiles(cmTarget const* target) } } - for(std::vector::const_iterator fileIt = newRccFiles.begin(); + for(std::vector::const_iterator fileIt = newRccFiles.begin(); fileIt != newRccFiles.end(); ++fileIt) { - const_cast(target)->AddSourceFile(*fileIt); + const_cast(target)->AddSource(*fileIt); } } -- cgit v0.12 From 59e8740acaf0b749e8a7028f168a6a6d6d69194f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 17 Mar 2014 18:45:37 +0100 Subject: cmTarget: Remove AddSourceFile method It is no longer used. --- Source/cmTarget.cxx | 16 +++++----------- Source/cmTarget.h | 1 - 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 0866d10..9d17320 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -579,16 +579,6 @@ void cmTarget::GetSourceFiles(std::vector &files) const } //---------------------------------------------------------------------------- -void cmTarget::AddSourceFile(cmSourceFile* sf) -{ - if (std::find(this->SourceFiles.begin(), this->SourceFiles.end(), sf) - == this->SourceFiles.end()) - { - this->SourceFiles.push_back(sf); - } -} - -//---------------------------------------------------------------------------- void cmTarget::AddSources(std::vector const& srcs) { for(std::vector::const_iterator i = srcs.begin(); @@ -653,7 +643,11 @@ cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s) cmSourceFile* cmTarget::AddSource(const std::string& src) { cmSourceFile* sf = this->Makefile->GetOrCreateSource(src); - this->AddSourceFile(sf); + if (std::find(this->SourceFiles.begin(), this->SourceFiles.end(), sf) + == this->SourceFiles.end()) + { + this->SourceFiles.push_back(sf); + } return sf; } diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 8df9bd8..e9e3622 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -137,7 +137,6 @@ public: */ void GetSourceFiles(std::vector &files) const; void GetSourceFiles(std::vector &files) const; - void AddSourceFile(cmSourceFile* sf); std::vector const& GetObjectLibraries() const { return this->ObjectLibraries; -- cgit v0.12 From fcc9287897dd9b378c2f87329346c2f23becd54f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 27 Mar 2014 23:09:39 +0100 Subject: cmSourceFileLocation: Remove unused Update method. The string overload is never called. This allows the removal of the unused UpdateDirectory method. --- Source/cmSourceFileLocation.cxx | 24 ------------------------ Source/cmSourceFileLocation.h | 2 -- 2 files changed, 26 deletions(-) diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx index 3e78b29..24e646f 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -65,19 +65,6 @@ cmSourceFileLocation } //---------------------------------------------------------------------------- -void cmSourceFileLocation::Update(const std::string& name) -{ - if(this->AmbiguousDirectory) - { - this->UpdateDirectory(name); - } - if(this->AmbiguousExtension) - { - this->UpdateExtension(name); - } -} - -//---------------------------------------------------------------------------- void cmSourceFileLocation::Update(cmSourceFileLocation const& loc) { if(this->AmbiguousDirectory && !loc.AmbiguousDirectory) @@ -176,17 +163,6 @@ void cmSourceFileLocation::UpdateExtension(const std::string& name) } //---------------------------------------------------------------------------- -void cmSourceFileLocation::UpdateDirectory(const std::string& name) -{ - // If a full path was given we know the directory. - if(cmSystemTools::FileIsFullPath(name.c_str())) - { - this->Directory = cmSystemTools::GetFilenamePath(name); - this->AmbiguousDirectory = false; - } -} - -//---------------------------------------------------------------------------- bool cmSourceFileLocation ::MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const diff --git a/Source/cmSourceFileLocation.h b/Source/cmSourceFileLocation.h index 82a62ab..c37fb1d 100644 --- a/Source/cmSourceFileLocation.h +++ b/Source/cmSourceFileLocation.h @@ -96,9 +96,7 @@ private: // Update the location with additional knowledge. void Update(cmSourceFileLocation const& loc); - void Update(const std::string& name); void UpdateExtension(const std::string& name); - void UpdateDirectory(const std::string& name); }; #endif -- cgit v0.12 From 4959f3413c83f38dd222dced11d7a3933e145ae4 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 27 Mar 2014 22:56:36 +0100 Subject: cmSourceFileLocation: Collapse full path for directory comparisons. Otherwise Matches() ends up doing a comparison of the directories /path/to/dir/subdir/.. and /path/to/dir as strings and not matching where it should. --- Source/cmSourceFileLocation.cxx | 5 +++++ Tests/Properties/CMakeLists.txt | 2 ++ Tests/Properties/SubDir2/CMakeLists.txt | 5 +++++ Tests/Properties/subdirtest.cxx | 9 +++++++++ 4 files changed, 21 insertions(+) create mode 100644 Tests/Properties/SubDir2/CMakeLists.txt create mode 100644 Tests/Properties/subdirtest.cxx diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx index 24e646f..c050202 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -60,6 +60,11 @@ cmSourceFileLocation this->AmbiguousDirectory = !cmSystemTools::FileIsFullPath(name.c_str()); this->AmbiguousExtension = true; this->Directory = cmSystemTools::GetFilenamePath(name); + if (cmSystemTools::FileIsFullPath(this->Directory.c_str())) + { + this->Directory + = cmSystemTools::CollapseFullPath(this->Directory.c_str()); + } this->Name = cmSystemTools::GetFilenameName(name); this->UpdateExtension(name); } diff --git a/Tests/Properties/CMakeLists.txt b/Tests/Properties/CMakeLists.txt index 285d596..11fca45 100644 --- a/Tests/Properties/CMakeLists.txt +++ b/Tests/Properties/CMakeLists.txt @@ -143,3 +143,5 @@ set_property(CACHE SOME_ENTRY PROPERTY VALUE "${expect_VALUE}") set_property(CACHE SOME_ENTRY PROPERTY ADVANCED "${expect_ADVANCED}") set_property(CACHE SOME_ENTRY PROPERTY STRINGS "${expect_STRINGS}") check_cache_props() + +add_subdirectory(SubDir2) diff --git a/Tests/Properties/SubDir2/CMakeLists.txt b/Tests/Properties/SubDir2/CMakeLists.txt new file mode 100644 index 0000000..377dc83 --- /dev/null +++ b/Tests/Properties/SubDir2/CMakeLists.txt @@ -0,0 +1,5 @@ + +set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/../subdirtest.cxx" + PROPERTIES COMPILE_DEFINITIONS SUBDIR_TEST) + +add_executable(subdirtest "${CMAKE_CURRENT_SOURCE_DIR}/../subdirtest.cxx") diff --git a/Tests/Properties/subdirtest.cxx b/Tests/Properties/subdirtest.cxx new file mode 100644 index 0000000..02d8f3d --- /dev/null +++ b/Tests/Properties/subdirtest.cxx @@ -0,0 +1,9 @@ + +#ifndef SUBDIR_TEST +#error Expected SUBDIR_TEST +#endif + +int main(int, char**) +{ + return 0; +} -- cgit v0.12 From 8cd113ad1d715cc9ce865956870cd462d3659089 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 17 Mar 2014 18:36:04 +0100 Subject: cmTarget: Store strings instead of cmSourceFile* to represent SOURCES. This will allow the strings to contain generator expressions. At this point, generator expressions are still not part of the SOURCES property when it is read. --- Source/cmTarget.cxx | 176 ++++++++++++++++++++++++++++++++++++++++------------ Source/cmTarget.h | 1 - 2 files changed, 135 insertions(+), 42 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 9d17320..8bfc428 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -150,6 +150,7 @@ public: std::vector IncludeDirectoriesEntries; std::vector CompileOptionsEntries; std::vector CompileDefinitionsEntries; + std::vector SourceEntries; std::vector LinkImplementationPropertyEntries; mutable std::map > @@ -545,37 +546,51 @@ bool cmTarget::IsBundleOnApple() const void cmTarget::GetSourceFiles(std::vector &files) const { assert(this->GetType() != INTERFACE_LIBRARY); - std::vector sourceFiles; - this->GetSourceFiles(sourceFiles); - for(std::vector::const_iterator - si = sourceFiles.begin(); - si != sourceFiles.end(); ++si) - { - files.push_back((*si)->GetFullPath()); + for(std::vector::const_iterator + si = this->Internal->SourceEntries.begin(); + si != this->Internal->SourceEntries.end(); ++si) + { + std::vector srcs; + cmSystemTools::ExpandListArgument((*si)->ge->GetInput(), srcs); + for(std::vector::const_iterator i = srcs.begin(); + i != srcs.end(); ++i) + { + std::string src = *i; + cmSourceFile* sf = this->Makefile->GetOrCreateSource(src); + std::string e; + src = sf->GetFullPath(&e); + if(src.empty()) + { + if(!e.empty()) + { + cmake* cm = this->Makefile->GetCMakeInstance(); + cm->IssueMessage(cmake::FATAL_ERROR, e, + this->GetBacktrace()); + } + return; + } + files.push_back(src); + } } } //---------------------------------------------------------------------------- void cmTarget::GetSourceFiles(std::vector &files) const { - assert(this->GetType() != INTERFACE_LIBRARY); - for(std::vector::const_iterator - si = this->SourceFiles.begin(); - si != this->SourceFiles.end(); ++si) + std::vector srcs; + this->GetSourceFiles(srcs); + + std::set emitted; + + for(std::vector::const_iterator i = srcs.begin(); + i != srcs.end(); ++i) { - std::string e; - if((*si)->GetFullPath(&e).empty()) + cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i); + if (emitted.insert(sf).second) { - if(!e.empty()) - { - cmake* cm = this->Makefile->GetCMakeInstance(); - cm->IssueMessage(cmake::FATAL_ERROR, e, - this->GetBacktrace()); - } - return; + files.push_back(sf); } } - files = this->SourceFiles; } //---------------------------------------------------------------------------- @@ -640,17 +655,86 @@ cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s) } //---------------------------------------------------------------------------- +struct CreateLocation +{ + cmMakefile const* Makefile; + + CreateLocation(cmMakefile const* mf) + : Makefile(mf) + { + + } + + cmSourceFileLocation operator()(const std::string& filename) + { + return cmSourceFileLocation(this->Makefile, filename); + } +}; + +//---------------------------------------------------------------------------- +struct LocationMatcher +{ + const cmSourceFileLocation& Needle; + + LocationMatcher(const cmSourceFileLocation& needle) + : Needle(needle) + { + + } + + bool operator()(cmSourceFileLocation &loc) + { + return loc.Matches(this->Needle); + } +}; + + +//---------------------------------------------------------------------------- +struct TargetPropertyEntryFinder +{ +private: + const cmSourceFileLocation& Needle; +public: + TargetPropertyEntryFinder(const cmSourceFileLocation& needle) + : Needle(needle) + { + + } + + bool operator()(cmTargetInternals::TargetPropertyEntry* entry) + { + std::vector files; + cmSystemTools::ExpandListArgument(entry->ge->GetInput(), files); + std::vector locations(files.size()); + std::transform(files.begin(), files.end(), locations.begin(), + CreateLocation(this->Needle.GetMakefile())); + + return std::find_if(locations.begin(), locations.end(), + LocationMatcher(this->Needle)) != locations.end(); + } +}; + +//---------------------------------------------------------------------------- cmSourceFile* cmTarget::AddSource(const std::string& src) { - cmSourceFile* sf = this->Makefile->GetOrCreateSource(src); - if (std::find(this->SourceFiles.begin(), this->SourceFiles.end(), sf) - == this->SourceFiles.end()) + cmSourceFileLocation sfl(this->Makefile, src); + if (std::find_if(this->Internal->SourceEntries.begin(), + this->Internal->SourceEntries.end(), + TargetPropertyEntryFinder(sfl)) + == this->Internal->SourceEntries.end()) { - this->SourceFiles.push_back(sf); + cmListFileBacktrace lfbt; + this->Makefile->GetBacktrace(lfbt); + cmGeneratorExpression ge(lfbt); + cmsys::auto_ptr cge = ge.Parse(src); + this->Internal->SourceEntries.push_back( + new cmTargetInternals::TargetPropertyEntry(cge)); } - return sf; + return this->Makefile->GetOrCreateSource(src); } + + //---------------------------------------------------------------------------- void cmTarget::ProcessSourceExpression(std::string const& expr) { @@ -2779,25 +2863,34 @@ const char *cmTarget::GetProperty(const std::string& prop, { cmOStringStream ss; const char* sep = ""; - for(std::vector::const_iterator - i = this->SourceFiles.begin(); - i != this->SourceFiles.end(); ++i) + typedef cmTargetInternals::TargetPropertyEntry + TargetPropertyEntry; + for(std::vector::const_iterator + i = this->Internal->SourceEntries.begin(); + i != this->Internal->SourceEntries.end(); ++i) { - // Separate from the previous list entries. - ss << sep; - sep = ";"; + std::string entry = (*i)->ge->GetInput(); - // Construct what is known about this source file location. - cmSourceFileLocation const& location = (*i)->GetLocation(); - std::string sname = location.GetDirectory(); - if(!sname.empty()) + std::vector files; + cmSystemTools::ExpandListArgument(entry, files); + for (std::vector::const_iterator + li = files.begin(); li != files.end(); ++li) { - sname += "/"; - } - sname += location.GetName(); + cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li); + // Construct what is known about this source file location. + cmSourceFileLocation const& location = sf->GetLocation(); + std::string sname = location.GetDirectory(); + if(!sname.empty()) + { + sname += "/"; + } + sname += location.GetName(); - // Append this list entry. - ss << sname; + ss << sep; + sep = ";"; + // Append this list entry. + ss << sname; + } } this->Properties.SetProperty("SOURCES", ss.str().c_str(), cmProperty::TARGET); @@ -6410,6 +6503,7 @@ cmTargetInternalPointer::~cmTargetInternalPointer() deleteAndClear(this->Pointer->IncludeDirectoriesEntries); deleteAndClear(this->Pointer->CompileOptionsEntries); deleteAndClear(this->Pointer->CompileDefinitionsEntries); + deleteAndClear(this->Pointer->SourceEntries); delete this->Pointer; } diff --git a/Source/cmTarget.h b/Source/cmTarget.h index e9e3622..45fca53 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -686,7 +686,6 @@ private: std::vector PreLinkCommands; std::vector PostBuildCommands; TargetType TargetTypeValue; - std::vector SourceFiles; std::vector ObjectLibraries; LinkLibraryVectorType LinkLibraries; LinkLibraryVectorType PrevLinkedLibraries; -- cgit v0.12 From bf98cc252f18e761ed9a57d2f7a9304bfbb621de Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Feb 2014 15:59:18 +0100 Subject: Genex: Evaluate TARGET_OBJECTS as a normal expression. --- Help/manual/cmake-generator-expressions.7.rst | 3 + Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst | 6 ++ Source/cmGeneratorExpressionEvaluator.cxx | 64 ++++++++++++++++++++++ Source/cmSourceFile.cxx | 12 ++++ Source/cmSourceFile.h | 4 ++ Tests/GeneratorExpression/CMakeLists.txt | 14 +++++ Tests/GeneratorExpression/check_object_files.cmake | 48 ++++++++++++++++ Tests/GeneratorExpression/objlib1.c | 5 ++ Tests/GeneratorExpression/objlib2.c | 5 ++ Tests/RunCMake/CMakeLists.txt | 1 + Tests/RunCMake/TargetObjects/CMakeLists.txt | 3 + Tests/RunCMake/TargetObjects/NoTarget-result.txt | 1 + Tests/RunCMake/TargetObjects/NoTarget-stderr.txt | 8 +++ Tests/RunCMake/TargetObjects/NoTarget.cmake | 2 + .../TargetObjects/NotObjlibTarget-result.txt | 1 + .../TargetObjects/NotObjlibTarget-stderr.txt | 8 +++ Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake | 4 ++ Tests/RunCMake/TargetObjects/RunCMakeTest.cmake | 4 ++ Tests/RunCMake/TargetObjects/empty.cpp | 7 +++ 19 files changed, 200 insertions(+) create mode 100644 Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst create mode 100644 Tests/GeneratorExpression/check_object_files.cmake create mode 100644 Tests/GeneratorExpression/objlib1.c create mode 100644 Tests/GeneratorExpression/objlib2.c create mode 100644 Tests/RunCMake/TargetObjects/CMakeLists.txt create mode 100644 Tests/RunCMake/TargetObjects/NoTarget-result.txt create mode 100644 Tests/RunCMake/TargetObjects/NoTarget-stderr.txt create mode 100644 Tests/RunCMake/TargetObjects/NoTarget.cmake create mode 100644 Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt create mode 100644 Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt create mode 100644 Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake create mode 100644 Tests/RunCMake/TargetObjects/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/TargetObjects/empty.cpp diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index ac8c3f8..17263d4 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -188,3 +188,6 @@ property is non-empty:: Content of ``...`` converted to upper case. ``$`` Content of ``...`` converted to a C identifier. +``$`` + List of objects resulting from build of ``objLib``. ``objLib`` must be an + object of type ``OBJECT_LIBRARY``. diff --git a/Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst b/Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst new file mode 100644 index 0000000..853a803 --- /dev/null +++ b/Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst @@ -0,0 +1,6 @@ +file-GENERATE-TARGET_OBJECTS +---------------------------- + +* The :command:`file(GENERATE)` subcommand learned to evaluate the + ``TARGET_OBJECTS`` + :manual:`generator expression `. diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 14b2a1a..669694c 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -15,6 +15,8 @@ #include "cmGeneratorExpressionParser.h" #include "cmGeneratorExpressionDAGChecker.h" #include "cmGeneratorExpression.h" +#include "cmLocalGenerator.h" +#include "cmSourceFile.h" #include @@ -1240,6 +1242,67 @@ static const struct TargetNameNode : public cmGeneratorExpressionNode } targetNameNode; //---------------------------------------------------------------------------- +static const struct TargetObjectsNode : public cmGeneratorExpressionNode +{ + TargetObjectsNode() {} + + std::string Evaluate(const std::vector ¶meters, + cmGeneratorExpressionContext *context, + const GeneratorExpressionContent *content, + cmGeneratorExpressionDAGChecker *) const + { + std::string tgtName = parameters.front(); + cmGeneratorTarget* gt = + context->Makefile->FindGeneratorTargetToUse(tgtName.c_str()); + if (!gt) + { + cmOStringStream e; + e << "Objects of target \"" << tgtName + << "\" referenced but no such target exists."; + reportError(context, content->GetOriginalExpression(), e.str()); + return std::string(); + } + if (gt->GetType() != cmTarget::OBJECT_LIBRARY) + { + cmOStringStream e; + e << "Objects of target \"" << tgtName + << "\" referenced but is not an OBJECT library."; + reportError(context, content->GetOriginalExpression(), e.str()); + return std::string(); + } + + std::vector objectSources; + gt->GetObjectSources(objectSources); + std::map mapping; + + for(std::vector::const_iterator it + = objectSources.begin(); it != objectSources.end(); ++it) + { + mapping[*it]; + } + + gt->LocalGenerator->ComputeObjectFilenames(mapping, gt); + + std::string obj_dir = gt->ObjectDirectory; + std::string result; + const char* sep = ""; + for(std::map::const_iterator it + = mapping.begin(); it != mapping.end(); ++it) + { + assert(!it->second.empty()); + result += sep; + std::string objFile = obj_dir + it->second; + cmSourceFile* sf = context->Makefile->GetOrCreateSource(objFile, true); + sf->SetObjectLibrary(tgtName); + sf->SetProperty("EXTERNAL_OBJECT", "1"); + result += objFile; + sep = ";"; + } + return result; + } +} targetObjectsNode; + +//---------------------------------------------------------------------------- static const char* targetPolicyWhitelist[] = { 0 #define TARGET_POLICY_STRING(POLICY) \ @@ -1593,6 +1656,7 @@ cmGeneratorExpressionNode* GetNode(const std::string &identifier) nodeMap["SEMICOLON"] = &semicolonNode; nodeMap["TARGET_PROPERTY"] = &targetPropertyNode; nodeMap["TARGET_NAME"] = &targetNameNode; + nodeMap["TARGET_OBJECTS"] = &targetObjectsNode; nodeMap["TARGET_POLICY"] = &targetPolicyNode; nodeMap["BUILD_INTERFACE"] = &buildInterfaceNode; nodeMap["INSTALL_INTERFACE"] = &installInterfaceNode; diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index b9b6251..0ab30a2 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -39,6 +39,18 @@ std::string const& cmSourceFile::GetExtension() const } //---------------------------------------------------------------------------- +void cmSourceFile::SetObjectLibrary(std::string const& objlib) +{ + this->ObjectLibrary = objlib; +} + +//---------------------------------------------------------------------------- +std::string cmSourceFile::GetObjectLibrary() const +{ + return this->ObjectLibrary; +} + +//---------------------------------------------------------------------------- std::string cmSourceFile::GetLanguage() { // If the language was set explicitly by the user then use it. diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index 17c96ac..755a2cf 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -97,6 +97,9 @@ public: */ bool Matches(cmSourceFileLocation const&); + void SetObjectLibrary(std::string const& objlib); + std::string GetObjectLibrary() const; + private: cmSourceFileLocation Location; cmPropertyMap Properties; @@ -105,6 +108,7 @@ private: std::string Language; std::string FullPath; bool FindFullPathFailed; + std::string ObjectLibrary; bool FindFullPath(std::string* error); bool TryFullPath(const std::string& path, const std::string& ext); diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt index a0e34ef..66b175a 100644 --- a/Tests/GeneratorExpression/CMakeLists.txt +++ b/Tests/GeneratorExpression/CMakeLists.txt @@ -258,3 +258,17 @@ set(CMP0044_TYPE NEW) add_subdirectory(CMP0044 ${CMAKE_BINARY_DIR}/CMP0044-NEW) set(CMP0044_TYPE OLD) add_subdirectory(CMP0044 ${CMAKE_BINARY_DIR}/CMP0044-OLD) + +add_library(objlib OBJECT objlib1.c objlib2.c) +file(GENERATE + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/objlib_files" + CONTENT "$,\n>\n" +) +add_custom_target(check_object_files ALL + COMMAND ${CMAKE_COMMAND} + "-DOBJLIB_LISTFILE=${CMAKE_CURRENT_BINARY_DIR}/objlib_files" + -DTEST_CONFIGURATION=${CMAKE_BUILD_TYPE} + -DEXPECTED_NUM_OBJECTFILES=2 + -P "${CMAKE_CURRENT_SOURCE_DIR}/check_object_files.cmake" + DEPENDS objlib +) diff --git a/Tests/GeneratorExpression/check_object_files.cmake b/Tests/GeneratorExpression/check_object_files.cmake new file mode 100644 index 0000000..889fe80 --- /dev/null +++ b/Tests/GeneratorExpression/check_object_files.cmake @@ -0,0 +1,48 @@ + +if (NOT EXISTS ${OBJLIB_LISTFILE}) + message(SEND_ERROR "Object listing file \"${OBJLIB_LISTFILE}\" not found!") +endif() + +file(STRINGS ${OBJLIB_LISTFILE} objlib_files) + +list(LENGTH objlib_files num_objectfiles) +if (NOT EXPECTED_NUM_OBJECTFILES EQUAL num_objectfiles) + message(SEND_ERROR "Unexpected number of entries in object list file (${num_objectfiles} instead of ${EXPECTED_NUM_OBJECTFILES})") +endif() + +foreach(objlib_file ${objlib_files}) + set(file_exists False) + if (EXISTS ${objlib_file}) + set(file_exists True) + endif() + + if (NOT file_exists) + if (objlib_file MATCHES ".(CURRENT_ARCH)") + string(REPLACE "$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)" "*" config_file "${objlib_file}") + string(REPLACE "$(PROJECT_NAME)" "GeneratorExpression" config_file "${config_file}") + string(REPLACE "$(CURRENT_ARCH)" "*" config_file "${config_file}") + file(GLOB_RECURSE files "${config_file}") + list(LENGTH files num_files) + if (NOT files) + message(SEND_ERROR "Got no files for expression ${config_file}") + endif() + set(file_exists True) + else() + foreach(config_macro "$(Configuration)" "$(OutDir)" "$(IntDir)") + string(REPLACE "${config_macro}" "${TEST_CONFIGURATION}" config_file "${objlib_file}") + list(APPEND attempts ${config_file}) + if (EXISTS ${config_file}) + set(file_exists True) + endif() + endforeach() + endif() + endif() + + if (NOT file_exists) + if(attempts) + list(REMOVE_DUPLICATES attempts) + set(tried " Tried ${attempts}") + endif() + message(SEND_ERROR "File \"${objlib_file}\" does not exist!${tried}") + endif() +endforeach() diff --git a/Tests/GeneratorExpression/objlib1.c b/Tests/GeneratorExpression/objlib1.c new file mode 100644 index 0000000..aa8de0a --- /dev/null +++ b/Tests/GeneratorExpression/objlib1.c @@ -0,0 +1,5 @@ + +void objlib1() +{ + +} diff --git a/Tests/GeneratorExpression/objlib2.c b/Tests/GeneratorExpression/objlib2.c new file mode 100644 index 0000000..3c7307a --- /dev/null +++ b/Tests/GeneratorExpression/objlib2.c @@ -0,0 +1,5 @@ + +void objlib2() +{ + +} diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 7691f32..31e7805 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -49,6 +49,7 @@ add_RunCMake_test(GeneratorToolset) add_RunCMake_test(TargetPropertyGeneratorExpressions) add_RunCMake_test(Languages) add_RunCMake_test(ObjectLibrary) +add_RunCMake_test(TargetObjects) add_RunCMake_test(find_dependency) if(NOT WIN32) add_RunCMake_test(PositionIndependentCode) diff --git a/Tests/RunCMake/TargetObjects/CMakeLists.txt b/Tests/RunCMake/TargetObjects/CMakeLists.txt new file mode 100644 index 0000000..be9d403 --- /dev/null +++ b/Tests/RunCMake/TargetObjects/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.4) +project(${RunCMake_TEST}) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/TargetObjects/NoTarget-result.txt b/Tests/RunCMake/TargetObjects/NoTarget-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetObjects/NoTarget-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetObjects/NoTarget-stderr.txt b/Tests/RunCMake/TargetObjects/NoTarget-stderr.txt new file mode 100644 index 0000000..2c4f877 --- /dev/null +++ b/Tests/RunCMake/TargetObjects/NoTarget-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at NoTarget.cmake:2 \(file\): + Error evaluating generator expression: + + \$ + + Objects of target "NoTarget" referenced but no such target exists. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/TargetObjects/NoTarget.cmake b/Tests/RunCMake/TargetObjects/NoTarget.cmake new file mode 100644 index 0000000..f203c23 --- /dev/null +++ b/Tests/RunCMake/TargetObjects/NoTarget.cmake @@ -0,0 +1,2 @@ + +file(GENERATE OUTPUT test_output CONTENT $) diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt b/Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt b/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt new file mode 100644 index 0000000..bb83934 --- /dev/null +++ b/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at NotObjlibTarget.cmake:4 \(file\): + Error evaluating generator expression: + + \$ + + Objects of target "StaticLib" referenced but is not an OBJECT library. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake b/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake new file mode 100644 index 0000000..c7f8a71 --- /dev/null +++ b/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake @@ -0,0 +1,4 @@ + +add_library(StaticLib empty.cpp) + +file(GENERATE OUTPUT test_output CONTENT $) diff --git a/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake b/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake new file mode 100644 index 0000000..30b9fee --- /dev/null +++ b/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake @@ -0,0 +1,4 @@ +include(RunCMake) + +run_cmake(NoTarget) +run_cmake(NotObjlibTarget) diff --git a/Tests/RunCMake/TargetObjects/empty.cpp b/Tests/RunCMake/TargetObjects/empty.cpp new file mode 100644 index 0000000..bfbbdde --- /dev/null +++ b/Tests/RunCMake/TargetObjects/empty.cpp @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif +int empty() +{ + return 0; +} -- cgit v0.12 From 28e1d2f8fc08516e8fc3a009777437d3e086b8e6 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 18 Mar 2014 16:21:08 +0100 Subject: cmStringCommand: Add GENEX_STRIP subcommand. Strip out any generator expressions in the input string. --- Help/command/string.rst | 5 +++++ Help/release/dev/string-GENEX_STRIP.rst | 6 ++++++ Source/cmStringCommand.cxx | 25 +++++++++++++++++++++++++ Source/cmStringCommand.h | 1 + Tests/StringFileTest/CMakeLists.txt | 6 ++++++ 5 files changed, 43 insertions(+) create mode 100644 Help/release/dev/string-GENEX_STRIP.rst diff --git a/Help/command/string.rst b/Help/command/string.rst index af18825..abde6ee 100644 --- a/Help/command/string.rst +++ b/Help/command/string.rst @@ -35,6 +35,7 @@ String operations. string(FIND [REVERSE]) string(TIMESTAMP [] [UTC]) string(MAKE_C_IDENTIFIER ) + string(GENEX_STRIP ) REGEX MATCH will match the regular expression once and store the match in the output variable. @@ -154,3 +155,7 @@ If no explicit is given it will default to: MAKE_C_IDENTIFIER will write a string which can be used as an identifier in C. + +``GENEX_STRIP`` will strip any +:manual:`generator expressions ` from the +``input string`` and store the result in the ``output variable``. diff --git a/Help/release/dev/string-GENEX_STRIP.rst b/Help/release/dev/string-GENEX_STRIP.rst new file mode 100644 index 0000000..b5b1074 --- /dev/null +++ b/Help/release/dev/string-GENEX_STRIP.rst @@ -0,0 +1,6 @@ +string-GENEX_STRIP +------------------ + +* The :command:`string` command learned a new ``GENEX_STRIP`` subcommand + which removes + :manual:`generator expression `. diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx index 7bc7b05..ea762eb 100644 --- a/Source/cmStringCommand.cxx +++ b/Source/cmStringCommand.cxx @@ -101,6 +101,10 @@ bool cmStringCommand { return this->HandleMakeCIdentifierCommand(args); } + else if(subCommand == "GENEX_STRIP") + { + return this->HandleGenexStripCommand(args); + } std::string e = "does not recognize sub-command "+subCommand; this->SetError(e); @@ -810,6 +814,27 @@ bool cmStringCommand } //---------------------------------------------------------------------------- +bool cmStringCommand +::HandleGenexStripCommand(std::vector const& args) +{ + if(args.size() != 3) + { + this->SetError("sub-command GENEX_STRIP requires two arguments."); + return false; + } + + const std::string& input = args[1]; + + std::string result = cmGeneratorExpression::Preprocess(input, + cmGeneratorExpression::StripAllGeneratorExpressions); + + const std::string& variableName = args[2]; + + this->Makefile->AddDefinition(variableName, result.c_str()); + return true; +} + +//---------------------------------------------------------------------------- bool cmStringCommand::HandleStripCommand( std::vector const& args) { diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h index b8053c5..5b7412d 100644 --- a/Source/cmStringCommand.h +++ b/Source/cmStringCommand.h @@ -75,6 +75,7 @@ protected: bool HandleFindCommand(std::vector const& args); bool HandleTimestampCommand(std::vector const& args); bool HandleMakeCIdentifierCommand(std::vector const& args); + bool HandleGenexStripCommand(std::vector const& args); class RegexReplacement { diff --git a/Tests/StringFileTest/CMakeLists.txt b/Tests/StringFileTest/CMakeLists.txt index 00383ab..be6d8fe 100644 --- a/Tests/StringFileTest/CMakeLists.txt +++ b/Tests/StringFileTest/CMakeLists.txt @@ -286,3 +286,9 @@ string(MAKE_C_IDENTIFIER "1one-two$" MCI_1) if(NOT MCI_1 STREQUAL _1one_two_) message(SEND_ERROR "MAKE_C_IDENTIFIER did not create expected result.") endif() + +string(GENEX_STRIP "one;$<1:two;three>;four;$" strip_result) + +if (NOT strip_result STREQUAL "one;four") + message(SEND_ERROR "GENEX_STRIP did not create expected result: ${strip_result}") +endif() -- cgit v0.12 From 857d30b52ef2fb011bad16249d34972fadae9b70 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 19 Mar 2014 09:11:11 +0100 Subject: cmGlobalGenerator: Add interface to call ForceLinkerLanguages Avoid calling it too early when cmGeneratorTarget instances don't yet exist. --- Source/cmGlobalGenerator.cxx | 7 +++++++ Source/cmGlobalGenerator.h | 2 ++ Source/cmGlobalXCodeGenerator.cxx | 1 - 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 07637b3..2f3c6c9 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -216,6 +216,11 @@ bool cmGlobalGenerator::GenerateImportFile(const std::string &file) return false; } +void cmGlobalGenerator::ForceLinkerLanguages() +{ + +} + bool cmGlobalGenerator::IsExportedTargetsFile(const std::string &filename) const { @@ -1194,6 +1199,8 @@ void cmGlobalGenerator::Generate() // Create per-target generator information. this->CreateGeneratorTargets(); + this->ForceLinkerLanguages(); + #ifdef CMAKE_BUILD_WITH_CMAKE for (AutogensType::iterator it = autogens.begin(); it != autogens.end(); ++it) diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 49a418d..668bb6b 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -423,6 +423,8 @@ private: void WriteSummary(cmTarget* target); void FinalizeTargetCompileInfo(); + virtual void ForceLinkerLanguages(); + virtual void PrintCompilerAdvice(std::ostream& os, std::string const& lang, const char* envVar) const; void CheckCompilerIdCompatibility(cmMakefile* mf, diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 96b23d2..fdf73d6 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -343,7 +343,6 @@ void cmGlobalXCodeGenerator::Generate() // add ALL_BUILD, INSTALL, etc this->AddExtraTargets(root, it->second); } - this->ForceLinkerLanguages(); this->cmGlobalGenerator::Generate(); if(cmSystemTools::GetErrorOccuredFlag()) { -- cgit v0.12 From 5702e10677e72a75370e8c1bbe6f10fa5ad675a9 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 18 Mar 2014 16:15:15 +0100 Subject: cmTarget: Include TARGET_OBJECTS genex in target SOURCES property. Add policy CMP0051 to control this behavior. --- Help/manual/cmake-policies.7.rst | 1 + Help/policy/CMP0051.rst | 24 +++++++++ Help/release/dev/target-SOURCES-genex.rst | 7 +++ Source/cmPolicies.cxx | 5 ++ Source/cmPolicies.h | 1 + Source/cmTarget.cxx | 69 ++++++++++++++++++++++---- Tests/RunCMake/CMP0051/CMP0051-NEW-result.txt | 1 + Tests/RunCMake/CMP0051/CMP0051-NEW-stderr.txt | 1 + Tests/RunCMake/CMP0051/CMP0051-NEW.cmake | 10 ++++ Tests/RunCMake/CMP0051/CMP0051-OLD-result.txt | 1 + Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt | 1 + Tests/RunCMake/CMP0051/CMP0051-OLD.cmake | 10 ++++ Tests/RunCMake/CMP0051/CMP0051-WARN-result.txt | 1 + Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt | 15 ++++++ Tests/RunCMake/CMP0051/CMP0051-WARN.cmake | 8 +++ Tests/RunCMake/CMP0051/CMakeLists.txt | 3 ++ Tests/RunCMake/CMP0051/RunCMakeTest.cmake | 5 ++ Tests/RunCMake/CMP0051/empty.cpp | 7 +++ Tests/RunCMake/CMakeLists.txt | 1 + 19 files changed, 160 insertions(+), 11 deletions(-) create mode 100644 Help/policy/CMP0051.rst create mode 100644 Help/release/dev/target-SOURCES-genex.rst create mode 100644 Tests/RunCMake/CMP0051/CMP0051-NEW-result.txt create mode 100644 Tests/RunCMake/CMP0051/CMP0051-NEW-stderr.txt create mode 100644 Tests/RunCMake/CMP0051/CMP0051-NEW.cmake create mode 100644 Tests/RunCMake/CMP0051/CMP0051-OLD-result.txt create mode 100644 Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt create mode 100644 Tests/RunCMake/CMP0051/CMP0051-OLD.cmake create mode 100644 Tests/RunCMake/CMP0051/CMP0051-WARN-result.txt create mode 100644 Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt create mode 100644 Tests/RunCMake/CMP0051/CMP0051-WARN.cmake create mode 100644 Tests/RunCMake/CMP0051/CMakeLists.txt create mode 100644 Tests/RunCMake/CMP0051/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/CMP0051/empty.cpp diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst index 8650a58..b763882 100644 --- a/Help/manual/cmake-policies.7.rst +++ b/Help/manual/cmake-policies.7.rst @@ -102,3 +102,4 @@ All Policies /policy/CMP0048 /policy/CMP0049 /policy/CMP0050 + /policy/CMP0051 diff --git a/Help/policy/CMP0051.rst b/Help/policy/CMP0051.rst new file mode 100644 index 0000000..7d85929 --- /dev/null +++ b/Help/policy/CMP0051.rst @@ -0,0 +1,24 @@ +CMP0051 +------- + +List TARGET_OBJECTS in SOURCES target property. + +CMake 3.0 and lower did not include the ``TARGET_OBJECTS`` +:manual:`generator expression ` when +returning the :prop_tgt:`SOURCES` target property. + +Configure-time CMake code is not able to handle generator expressions. If +using the :prop_tgt:`SOURCES` target property at configure time, it may be +necessary to first remove generator expressions using the +:command:`string(STRIP_GENEX)` command. Generate-time CMake code such as +:command:`file(GENERATE)` can handle the content without stripping. + +The ``OLD`` behavior for this policy is to omit ``TARGET_OBJECTS`` +expressions from the :prop_tgt:`SOURCES` target property. The ``NEW`` +behavior for this policy is to include ``TARGET_OBJECTS`` expressions +in the output. + +This policy was introduced in CMake version 3.1. +CMake version |release| warns when the policy is not set and uses +``OLD`` behavior. Use the :command:`cmake_policy` command to set it +to ``OLD`` or ``NEW`` explicitly. diff --git a/Help/release/dev/target-SOURCES-genex.rst b/Help/release/dev/target-SOURCES-genex.rst new file mode 100644 index 0000000..1ca6f66 --- /dev/null +++ b/Help/release/dev/target-SOURCES-genex.rst @@ -0,0 +1,7 @@ +target-SOURCES-genex +-------------------- + +* The :prop_tgt:`SOURCES` target property now contains + :manual:`generator expression ` + such as ``TARGET_OBJECTS`` when read at configure time, if + policy :policy:`CMP0051` is ``NEW``. diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 2bd553f..759df91 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -343,6 +343,11 @@ cmPolicies::cmPolicies() CMP0050, "CMP0050", "Disallow add_custom_command SOURCE signatures.", 3,0,0, cmPolicies::WARN); + + this->DefinePolicy( + CMP0051, "CMP0051", + "List TARGET_OBJECTS in SOURCES target property.", + 3,1,0, cmPolicies::WARN); } cmPolicies::~cmPolicies() diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index b77235d..7a08a34 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -104,6 +104,7 @@ public: CMP0048, ///< project() command manages VERSION variables CMP0049, ///< Do not expand variables in target source entries CMP0050, ///< Disallow add_custom_command SOURCE signatures + CMP0051, ///< List TARGET_OBJECTS in SOURCES target property /** \brief Always the last entry. * diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 8bfc428..04ae5af 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -556,6 +556,10 @@ void cmTarget::GetSourceFiles(std::vector &files) const i != srcs.end(); ++i) { std::string src = *i; + if (cmGeneratorExpression::Find(src) != std::string::npos) + { + continue; + } cmSourceFile* sf = this->Makefile->GetOrCreateSource(src); std::string e; src = sf->GetFullPath(&e); @@ -743,6 +747,7 @@ void cmTarget::ProcessSourceExpression(std::string const& expr) { std::string objLibName = expr.substr(17, expr.size()-18); this->ObjectLibraries.push_back(objLibName); + this->AddSource(expr); } else { @@ -2876,20 +2881,62 @@ const char *cmTarget::GetProperty(const std::string& prop, for (std::vector::const_iterator li = files.begin(); li != files.end(); ++li) { - cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li); - // Construct what is known about this source file location. - cmSourceFileLocation const& location = sf->GetLocation(); - std::string sname = location.GetDirectory(); - if(!sname.empty()) + if(cmHasLiteralPrefix(*li, "$size() - 1] == '>') { - sname += "/"; + std::string objLibName = li->substr(17, li->size()-18); + + bool addContent = false; + bool noMessage = true; + cmOStringStream e; + cmake::MessageType messageType = cmake::AUTHOR_WARNING; + switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0051)) + { + case cmPolicies::WARN: + e << (this->Makefile->GetPolicies() + ->GetPolicyWarning(cmPolicies::CMP0051)) << "\n"; + noMessage = false; + case cmPolicies::OLD: + break; + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::NEW: + addContent = true; + } + if (!noMessage) + { + e << "Target \"" << this->Name << "\" contains $ " + "generator expression in its sources list. This content was not " + "previously part of the SOURCES property when that property was " + "read at configure time. Code reading that property needs to be " + "adapted to ignore the generator expression using the " + "string(GENEX_STRIP) command."; + this->Makefile->IssueMessage(messageType, e.str()); + } + if (addContent) + { + ss << sep; + sep = ";"; + ss << *li; + } } - sname += location.GetName(); + else + { + cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li); + // Construct what is known about this source file location. + cmSourceFileLocation const& location = sf->GetLocation(); + std::string sname = location.GetDirectory(); + if(!sname.empty()) + { + sname += "/"; + } + sname += location.GetName(); - ss << sep; - sep = ";"; - // Append this list entry. - ss << sname; + ss << sep; + sep = ";"; + // Append this list entry. + ss << sname; + } } } this->Properties.SetProperty("SOURCES", ss.str().c_str(), diff --git a/Tests/RunCMake/CMP0051/CMP0051-NEW-result.txt b/Tests/RunCMake/CMP0051/CMP0051-NEW-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CMP0051/CMP0051-NEW-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CMP0051/CMP0051-NEW-stderr.txt b/Tests/RunCMake/CMP0051/CMP0051-NEW-stderr.txt new file mode 100644 index 0000000..e5578ba --- /dev/null +++ b/Tests/RunCMake/CMP0051/CMP0051-NEW-stderr.txt @@ -0,0 +1 @@ +^Sources: "empty.cpp;\$"$ diff --git a/Tests/RunCMake/CMP0051/CMP0051-NEW.cmake b/Tests/RunCMake/CMP0051/CMP0051-NEW.cmake new file mode 100644 index 0000000..f304bf1 --- /dev/null +++ b/Tests/RunCMake/CMP0051/CMP0051-NEW.cmake @@ -0,0 +1,10 @@ + +cmake_policy(SET CMP0051 NEW) + +add_library(objects OBJECT empty.cpp) + +add_library(empty empty.cpp $) + +get_target_property(srcs empty SOURCES) + +message("Sources: \"${srcs}\"") diff --git a/Tests/RunCMake/CMP0051/CMP0051-OLD-result.txt b/Tests/RunCMake/CMP0051/CMP0051-OLD-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CMP0051/CMP0051-OLD-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt b/Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt new file mode 100644 index 0000000..cc17f33 --- /dev/null +++ b/Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt @@ -0,0 +1 @@ +^Sources: "empty.cpp"$ diff --git a/Tests/RunCMake/CMP0051/CMP0051-OLD.cmake b/Tests/RunCMake/CMP0051/CMP0051-OLD.cmake new file mode 100644 index 0000000..0243e94 --- /dev/null +++ b/Tests/RunCMake/CMP0051/CMP0051-OLD.cmake @@ -0,0 +1,10 @@ + +cmake_policy(SET CMP0051 OLD) + +add_library(objects OBJECT empty.cpp) + +add_library(empty empty.cpp $) + +get_target_property(srcs empty SOURCES) + +message("Sources: \"${srcs}\"") diff --git a/Tests/RunCMake/CMP0051/CMP0051-WARN-result.txt b/Tests/RunCMake/CMP0051/CMP0051-WARN-result.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/Tests/RunCMake/CMP0051/CMP0051-WARN-result.txt @@ -0,0 +1 @@ +0 diff --git a/Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt b/Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt new file mode 100644 index 0000000..f1b0357 --- /dev/null +++ b/Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt @@ -0,0 +1,15 @@ +CMake Warning \(dev\) at CMP0051-WARN.cmake:6 \(get_target_property\): + Policy CMP0051 is not set: List TARGET_OBJECTS in SOURCES target property. + Run "cmake --help-policy CMP0051" for policy details. Use the cmake_policy + command to set the policy and suppress this warning. + + Target "empty" contains \$ generator expression in its + sources list. This content was not previously part of the SOURCES property + when that property was read at configure time. Code reading that property + needs to be adapted to ignore the generator expression using the + string\(GENEX_STRIP\) command. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. + +Sources: "empty.cpp"$ diff --git a/Tests/RunCMake/CMP0051/CMP0051-WARN.cmake b/Tests/RunCMake/CMP0051/CMP0051-WARN.cmake new file mode 100644 index 0000000..fd595ce --- /dev/null +++ b/Tests/RunCMake/CMP0051/CMP0051-WARN.cmake @@ -0,0 +1,8 @@ + +add_library(objects OBJECT empty.cpp) + +add_library(empty empty.cpp $) + +get_target_property(srcs empty SOURCES) + +message("Sources: \"${srcs}\"") diff --git a/Tests/RunCMake/CMP0051/CMakeLists.txt b/Tests/RunCMake/CMP0051/CMakeLists.txt new file mode 100644 index 0000000..3482e6b --- /dev/null +++ b/Tests/RunCMake/CMP0051/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.0) +project(${RunCMake_TEST} CXX) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/CMP0051/RunCMakeTest.cmake b/Tests/RunCMake/CMP0051/RunCMakeTest.cmake new file mode 100644 index 0000000..621192d --- /dev/null +++ b/Tests/RunCMake/CMP0051/RunCMakeTest.cmake @@ -0,0 +1,5 @@ +include(RunCMake) + +run_cmake(CMP0051-OLD) +run_cmake(CMP0051-NEW) +run_cmake(CMP0051-WARN) diff --git a/Tests/RunCMake/CMP0051/empty.cpp b/Tests/RunCMake/CMP0051/empty.cpp new file mode 100644 index 0000000..bfbbdde --- /dev/null +++ b/Tests/RunCMake/CMP0051/empty.cpp @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif +int empty() +{ + return 0; +} diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 31e7805..4f059d6 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -34,6 +34,7 @@ add_RunCMake_test(CMP0045) add_RunCMake_test(CMP0046) add_RunCMake_test(CMP0049) add_RunCMake_test(CMP0050) +add_RunCMake_test(CMP0051) add_RunCMake_test(CTest) if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles") add_RunCMake_test(CompilerChange) -- cgit v0.12 From e5da9e51d02ba912bba4f556ecd6453dd187c8d8 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 18 Mar 2014 16:40:46 +0100 Subject: cmTarget: Allow any generator expression in SOURCES property. Remove use of UseObjectLibraries from Makefile and Ninja generators. It is not needed now because those generators use GetExternalObjects which already contains the objects from object libraries. The VS10 generator calls both the UseObjectLibraries and the GetExternalObjects methods. Ensure that duplicates are not created by skipping objects from object libraries in handling of GetExternalObjects. Similarly, fix VS6, VS7 and Xcode object handling by skipping external objects from OBJECT_LIBRARY usage as appropriate. The error message in the BadSourceExpression1 test is now reported by the generator expression evaluator, so it has different text. --- Help/command/add_executable.rst | 7 ++- Help/command/add_library.rst | 6 ++- Help/release/dev/target-SOURCES-genex.rst | 5 ++ Source/cmGlobalXCodeGenerator.cxx | 5 +- Source/cmLocalVisualStudio6Generator.cxx | 10 ++++ Source/cmLocalVisualStudio7Generator.cxx | 4 ++ Source/cmMakefileTargetGenerator.cxx | 3 -- Source/cmNinjaTargetGenerator.cxx | 11 ----- Source/cmTarget.cxx | 57 ++++++++++++---------- Source/cmVisualStudio10TargetGenerator.cxx | 13 +++++ Tests/GeneratorExpression/CMakeLists.txt | 2 +- .../ObjectLibrary/BadSourceExpression1-stderr.txt | 4 +- 12 files changed, 80 insertions(+), 47 deletions(-) diff --git a/Help/command/add_executable.rst b/Help/command/add_executable.rst index 231eeed..4ed10e1 100644 --- a/Help/command/add_executable.rst +++ b/Help/command/add_executable.rst @@ -35,8 +35,11 @@ If ``EXCLUDE_FROM_ALL`` is given the corresponding property will be set on the created target. See documentation of the :prop_tgt:`EXCLUDE_FROM_ALL` target property for details. -See the :manual:`cmake-buildsystem(7)` manual for more on defining -buildsystem properties. +Source arguments to ``add_executable`` may use "generator expressions" with +the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` +manual for available expressions. See the :manual:`cmake-buildsystem(7)` +manual for more on defining buildsystem properties. + -------------------------------------------------------------------------- diff --git a/Help/command/add_library.rst b/Help/command/add_library.rst index 0944269..e93ef53 100644 --- a/Help/command/add_library.rst +++ b/Help/command/add_library.rst @@ -39,8 +39,10 @@ If ``EXCLUDE_FROM_ALL`` is given the corresponding property will be set on the created target. See documentation of the :prop_tgt:`EXCLUDE_FROM_ALL` target property for details. -See the :manual:`cmake-buildsystem(7)` manual for more on defining buildsystem -properties. +Source arguments to ``add_library`` may use "generator expressions" with +the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)` +manual for available expressions. See the :manual:`cmake-buildsystem(7)` +manual for more on defining buildsystem properties. -------------------------------------------------------------------------- diff --git a/Help/release/dev/target-SOURCES-genex.rst b/Help/release/dev/target-SOURCES-genex.rst index 1ca6f66..9a65101 100644 --- a/Help/release/dev/target-SOURCES-genex.rst +++ b/Help/release/dev/target-SOURCES-genex.rst @@ -5,3 +5,8 @@ target-SOURCES-genex :manual:`generator expression ` such as ``TARGET_OBJECTS`` when read at configure time, if policy :policy:`CMP0051` is ``NEW``. + +* The :prop_tgt:`SOURCES` target property now generally supports + :manual:`generator expression `. The + generator expressions may be used in the :command:`add_library` and + :command:`add_executable` commands. diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index fdf73d6..2a6e522 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1007,7 +1007,10 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen, if(filetype && filetype->GetString() == "compiled.mach-o.objfile") { - externalObjFiles.push_back(xsf); + if ((*i)->GetObjectLibrary().empty()) + { + externalObjFiles.push_back(xsf); + } } else if(this->IsHeaderFile(*i) || (tsFlags.Type == cmGeneratorTarget::SourceFileTypePrivateHeader) || diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index e99f3a4..11e9679 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -324,6 +324,11 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout, for(std::vector::const_iterator i = classes.begin(); i != classes.end(); i++) { + if (!(*i)->GetObjectLibrary().empty()) + { + continue; + } + // Add the file to the list of sources. std::string source = (*i)->GetFullPath(); cmSourceGroup* sourceGroup = @@ -398,6 +403,11 @@ void cmLocalVisualStudio6Generator for(std::vector::const_iterator sf = sourceFiles.begin(); sf != sourceFiles.end(); ++sf) { + if (!(*sf)->GetObjectLibrary().empty()) + { + continue; + } + std::string source = (*sf)->GetFullPath(); const cmCustomCommand *command = (*sf)->GetCustomCommand(); diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index e8562ca..8bac10d 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1401,6 +1401,10 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, for(std::vector::const_iterator i = classes.begin(); i != classes.end(); i++) { + if (!(*i)->GetObjectLibrary().empty()) + { + continue; + } // Add the file to the list of sources. std::string source = (*i)->GetFullPath(); if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF") diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 6759d05..c520f9e 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -202,9 +202,6 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() // Generate this object file's rule file. this->WriteObjectRuleFiles(**si); } - - // Add object library contents as external objects. - this->GeneratorTarget->UseObjectLibraries(this->ExternalObjects); } //---------------------------------------------------------------------------- diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 8865b3d..b7eab7d 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -525,17 +525,6 @@ cmNinjaTargetGenerator this->ModuleDefinitionFile = this->ConvertToNinjaPath(def.c_str()); } - { - // Add object library contents as external objects. - std::vector objs; - this->GeneratorTarget->UseObjectLibraries(objs); - for(std::vector::iterator oi = objs.begin(); - oi != objs.end(); ++oi) - { - this->Objects.push_back(ConvertToNinjaPath(oi->c_str())); - } - } - this->GetBuildFileStream() << "\n"; } diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 04ae5af..aea6446 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -551,15 +551,16 @@ void cmTarget::GetSourceFiles(std::vector &files) const si != this->Internal->SourceEntries.end(); ++si) { std::vector srcs; - cmSystemTools::ExpandListArgument((*si)->ge->GetInput(), srcs); + cmSystemTools::ExpandListArgument((*si)->ge->Evaluate(this->Makefile, + "", + false, + this), + srcs); + for(std::vector::const_iterator i = srcs.begin(); i != srcs.end(); ++i) { std::string src = *i; - if (cmGeneratorExpression::Find(src) != std::string::npos) - { - continue; - } cmSourceFile* sf = this->Makefile->GetOrCreateSource(src); std::string e; src = sf->GetFullPath(&e); @@ -606,7 +607,14 @@ void cmTarget::AddSources(std::vector const& srcs) const char* src = i->c_str(); if(src[0] == '$' && src[1] == '<') { - this->ProcessSourceExpression(*i); + this->AddSource(src); + + if(cmHasLiteralPrefix(i->c_str(), "$size()-1] == '>') + { + std::string objLibName = i->substr(17, i->size()-18); + this->ObjectLibraries.push_back(objLibName); + } } else { @@ -734,28 +742,11 @@ cmSourceFile* cmTarget::AddSource(const std::string& src) this->Internal->SourceEntries.push_back( new cmTargetInternals::TargetPropertyEntry(cge)); } - return this->Makefile->GetOrCreateSource(src); -} - - - -//---------------------------------------------------------------------------- -void cmTarget::ProcessSourceExpression(std::string const& expr) -{ - if(cmHasLiteralPrefix(expr.c_str(), "$') + if (cmGeneratorExpression::Find(src) != std::string::npos) { - std::string objLibName = expr.substr(17, expr.size()-18); - this->ObjectLibraries.push_back(objLibName); - this->AddSource(expr); - } - else - { - cmOStringStream e; - e << "Unrecognized generator expression:\n" - << " " << expr; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + return 0; } + return this->Makefile->GetOrCreateSource(src); } //---------------------------------------------------------------------------- @@ -2886,6 +2877,14 @@ const char *cmTarget::GetProperty(const std::string& prop, { std::string objLibName = li->substr(17, li->size()-18); + if (cmGeneratorExpression::Find(objLibName) != std::string::npos) + { + ss << sep; + sep = ";"; + ss << *li; + continue; + } + bool addContent = false; bool noMessage = true; cmOStringStream e; @@ -2920,6 +2919,12 @@ const char *cmTarget::GetProperty(const std::string& prop, ss << *li; } } + else if (cmGeneratorExpression::Find(*li) == std::string::npos) + { + ss << sep; + sep = ";"; + ss << *li; + } else { cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li); diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index bb76b7f..8d10e7c 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1054,6 +1054,19 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() std::vector externalObjects; this->GeneratorTarget->GetExternalObjects(externalObjects); + for(std::vector::iterator + si = externalObjects.begin(); + si != externalObjects.end(); ) + { + if (!(*si)->GetObjectLibrary().empty()) + { + si = externalObjects.erase(si); + } + else + { + ++si; + } + } if(this->LocalGenerator->GetVersion() > cmLocalVisualStudioGenerator::VS10) { // For VS >= 11 we use LinkObjects to avoid linking custom command diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt index 66b175a..b506853 100644 --- a/Tests/GeneratorExpression/CMakeLists.txt +++ b/Tests/GeneratorExpression/CMakeLists.txt @@ -166,7 +166,7 @@ add_library(imported4 SHARED IMPORTED) set_property(TARGET imported4 APPEND PROPERTY INCLUDE_DIRECTORIES $) -add_executable(someexe empty.cpp) +add_executable(someexe $<1:empty.cpp> $<0:does_not_exist>) add_executable(Alias::SomeExe ALIAS someexe) add_library(Alias::SomeLib ALIAS empty1) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt index a1cac36..859dc3f 100644 --- a/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt @@ -1,6 +1,8 @@ CMake Error at BadSourceExpression1.cmake:1 \(add_library\): - Unrecognized generator expression: + Error evaluating generator expression: \$ + + Expression did not evaluate to a known generator expression Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) -- cgit v0.12 From c355d10865ba0dbaef06d0eafe678627c875a5f5 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 18 Mar 2014 17:04:46 +0100 Subject: cmComputeTargetDepends: Track object library depends. Relieve cmGeneratorTarget of that responsibility. --- Source/cmComputeTargetDepends.cxx | 29 +++++++++++++++++++++++++++++ Source/cmGeneratorTarget.cxx | 1 - 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index b4dbce7..db8b7f3 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -16,6 +16,7 @@ #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmSystemTools.h" +#include "cmSourceFile.h" #include "cmTarget.h" #include "cmake.h" @@ -213,6 +214,34 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) { std::set emitted; { + cmGeneratorTarget* gt = depender->GetMakefile()->GetLocalGenerator() + ->GetGlobalGenerator() + ->GetGeneratorTarget(depender); + std::vector objectFiles; + gt->GetExternalObjects(objectFiles); + for(std::vector::const_iterator + it = objectFiles.begin(); it != objectFiles.end(); ++it) + { + std::string objLib = (*it)->GetObjectLibrary(); + if (!objLib.empty() && emitted.insert(objLib).second) + { + if(depender->GetType() != cmTarget::EXECUTABLE && + depender->GetType() != cmTarget::STATIC_LIBRARY && + depender->GetType() != cmTarget::SHARED_LIBRARY && + depender->GetType() != cmTarget::MODULE_LIBRARY) + { + this->GlobalGenerator->GetCMakeInstance() + ->IssueMessage(cmake::FATAL_ERROR, + "Only executables and non-OBJECT libraries may " + "reference target objects.", + depender->GetBacktrace()); + return; + } + const_cast(depender)->AddUtility(objLib); + } + } + } + { std::vector tlibs; depender->GetDirectLinkLibraries("", tlibs, depender); // A target should not depend on itself. diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 834f9fd..66f6bdf 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -528,7 +528,6 @@ void cmGeneratorTarget::LookupObjectLibraries() this->Target->GetBacktrace()); return; } - this->Target->AddUtility(objLib->GetName()); this->ObjectLibraries.push_back(objLib); } else -- cgit v0.12 From fdcefe3c42fefdfcd27e6cf7b679f39cb99db4b9 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 18 Mar 2014 17:07:56 +0100 Subject: cmGeneratorTarget: Compute consumed object libraries on demand. Remove up-front object library computation from cmGlobalGenerator. Adjust tests for message coming from the generator expression evaluation. --- Source/cmGeneratorTarget.cxx | 72 ++++++---------------- Source/cmGeneratorTarget.h | 3 - Source/cmGlobalGenerator.cxx | 1 - .../ObjectLibrary/BadSourceExpression2-stderr.txt | 4 ++ .../ObjectLibrary/BadSourceExpression3-stderr.txt | 4 ++ 5 files changed, 27 insertions(+), 57 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 66f6bdf..64ca863 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -504,57 +504,6 @@ void cmGeneratorTarget::GetSourceFiles(std::vector &files) const } //---------------------------------------------------------------------------- -void cmGeneratorTarget::LookupObjectLibraries() -{ - std::vector const& objLibs = - this->Target->GetObjectLibraries(); - for(std::vector::const_iterator oli = objLibs.begin(); - oli != objLibs.end(); ++oli) - { - std::string const& objLibName = *oli; - if(cmTarget* objLib = this->Makefile->FindTargetToUse(objLibName)) - { - if(objLib->GetType() == cmTarget::OBJECT_LIBRARY) - { - if(this->Target->GetType() != cmTarget::EXECUTABLE && - this->Target->GetType() != cmTarget::STATIC_LIBRARY && - this->Target->GetType() != cmTarget::SHARED_LIBRARY && - this->Target->GetType() != cmTarget::MODULE_LIBRARY) - { - this->GlobalGenerator->GetCMakeInstance() - ->IssueMessage(cmake::FATAL_ERROR, - "Only executables and non-OBJECT libraries may " - "reference target objects.", - this->Target->GetBacktrace()); - return; - } - this->ObjectLibraries.push_back(objLib); - } - else - { - cmOStringStream e; - e << "Objects of target \"" << objLibName - << "\" referenced but is not an OBJECT library."; - this->GlobalGenerator->GetCMakeInstance() - ->IssueMessage(cmake::FATAL_ERROR, e.str(), - this->Target->GetBacktrace()); - return; - } - } - else - { - cmOStringStream e; - e << "Objects of target \"" << objLibName - << "\" referenced but no such target exists."; - this->GlobalGenerator->GetCMakeInstance() - ->IssueMessage(cmake::FATAL_ERROR, e.str(), - this->Target->GetBacktrace()); - return; - } - } -} - -//---------------------------------------------------------------------------- std::string cmGeneratorTarget::GetModuleDefinitionFile() const { std::string data; @@ -566,9 +515,26 @@ std::string cmGeneratorTarget::GetModuleDefinitionFile() const void cmGeneratorTarget::UseObjectLibraries(std::vector& objs) const { + std::vector objectFiles; + this->GetExternalObjects(objectFiles); + std::vector objectLibraries; + std::set emitted; + for(std::vector::const_iterator + it = objectFiles.begin(); it != objectFiles.end(); ++it) + { + std::string objLib = (*it)->GetObjectLibrary(); + if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib)) + { + if (emitted.insert(tgt).second) + { + objectLibraries.push_back(tgt); + } + } + } + for(std::vector::const_iterator - ti = this->ObjectLibraries.begin(); - ti != this->ObjectLibraries.end(); ++ti) + ti = objectLibraries.begin(); + ti != objectLibraries.end(); ++ti) { cmTarget* objLib = *ti; cmGeneratorTarget* ogt = diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 53e27c5..cb59783 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -84,8 +84,6 @@ public: */ void TraceDependencies(); - void LookupObjectLibraries(); - /** Get sources that must be built before the given source. */ std::vector const* GetSourceDepends(cmSourceFile const* sf) const; @@ -127,7 +125,6 @@ private: std::map Objects; std::set ExplicitObjectName; - std::vector ObjectLibraries; mutable std::map > SystemIncludesCache; void ConstructSourceFileFlags() const; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 2f3c6c9..6caaee3 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1457,7 +1457,6 @@ void cmGlobalGenerator::ComputeGeneratorTargetObjects() continue; } cmGeneratorTarget* gt = ti->second; - gt->LookupObjectLibraries(); this->ComputeTargetObjects(gt); } } diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt index f1fcbe8..7060c61 100644 --- a/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt @@ -1,4 +1,8 @@ CMake Error at BadSourceExpression2.cmake:1 \(add_library\): + Error evaluating generator expression: + + \$ + Objects of target "DoesNotExist" referenced but no such target exists. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt index ad14a35..838b3d8 100644 --- a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt @@ -1,4 +1,8 @@ CMake Error at BadSourceExpression3.cmake:2 \(add_library\): + Error evaluating generator expression: + + \$ + Objects of target "NotObjLib" referenced but is not an OBJECT library. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) -- cgit v0.12 From 042c1c834e69ee60b605b02bad8be87b2193a7d2 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 18 Mar 2014 19:23:45 +0100 Subject: cmTarget: Compute languages from object libraries on demand. --- Source/cmTarget.cxx | 67 +++++++++++++++++++++++++++++++++++++---------------- Source/cmTarget.h | 5 ---- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index aea6446..61260be 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -608,13 +608,6 @@ void cmTarget::AddSources(std::vector const& srcs) if(src[0] == '$' && src[1] == '<') { this->AddSource(src); - - if(cmHasLiteralPrefix(i->c_str(), "$size()-1] == '>') - { - std::string objLibName = i->substr(17, i->size()-18); - this->ObjectLibraries.push_back(objLibName); - } } else { @@ -5013,6 +5006,53 @@ void cmTarget::GetLanguages(std::set& languages) const languages.insert(lang); } } + + std::vector objectLibraries; + std::vector externalObjects; + if (this->Makefile->GetGeneratorTargets().empty()) + { + // At configure-time, this method can be called as part of getting the + // LOCATION property or to export() a file to be include()d. However + // there is no cmGeneratorTarget at configure-time, so search the SOURCES + // for TARGET_OBJECTS instead for backwards compatibility with OLD + // behavior of CMP0024 and CMP0026 only. + std::vector srcs; + cmSystemTools::ExpandListArgument(this->GetProperty("SOURCES"), srcs); + for(std::vector::const_iterator it = srcs.begin(); + it != srcs.end(); ++it) + { + if (cmHasLiteralPrefix(*it, "$")) + { + std::string objLibName = it->substr(17, it->size()-18); + if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLibName)) + { + objectLibraries.push_back(tgt); + } + } + } + } + else + { + cmGeneratorTarget* gt = this->Makefile->GetLocalGenerator() + ->GetGlobalGenerator() + ->GetGeneratorTarget(this); + gt->GetExternalObjects(externalObjects); + for(std::vector::const_iterator + i = externalObjects.begin(); i != externalObjects.end(); ++i) + { + std::string objLib = (*i)->GetObjectLibrary(); + if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib)) + { + objectLibraries.push_back(tgt); + } + } + } + for(std::vector::const_iterator + i = objectLibraries.begin(); i != objectLibraries.end(); ++i) + { + (*i)->GetLanguages(languages); + } } //---------------------------------------------------------------------------- @@ -6077,19 +6117,6 @@ cmTarget::ComputeLinkImplementationLanguages(LinkImplementation& impl) const std::set languages; // Get languages used in our source files. this->GetLanguages(languages); - // Get languages used in object library sources. - for(std::vector::const_iterator - i = this->ObjectLibraries.begin(); - i != this->ObjectLibraries.end(); ++i) - { - if(cmTarget* objLib = this->Makefile->FindTargetToUse(*i)) - { - if(objLib->GetType() == cmTarget::OBJECT_LIBRARY) - { - objLib->GetLanguages(languages); - } - } - } // Copy the set of langauges to the link implementation. for(std::set::iterator li = languages.begin(); li != languages.end(); ++li) diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 45fca53..fcbff93 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -137,10 +137,6 @@ public: */ void GetSourceFiles(std::vector &files) const; void GetSourceFiles(std::vector &files) const; - std::vector const& GetObjectLibraries() const - { - return this->ObjectLibraries; - } /** * Add sources to the target. @@ -686,7 +682,6 @@ private: std::vector PreLinkCommands; std::vector PostBuildCommands; TargetType TargetTypeValue; - std::vector ObjectLibraries; LinkLibraryVectorType LinkLibraries; LinkLibraryVectorType PrevLinkedLibraries; bool LinkLibrariesAnalyzed; -- cgit v0.12 From aa0a3562dd47bdd6d9ca3058bd1dfd525e79d36d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 14 Mar 2014 13:21:26 +0100 Subject: cmGeneratorTarget: Compute target objects on demand Add a ComputeObjectMapping method to compute the object names. It takes mapping to populate as an out-parameter so that it can be extended in the future with parameters relevant to generator expression evaluation. Remove the supporting cmGeneratorTarget::AddObject method. It is no longer needed as the container member is populated directly. The ComputeObjectMapping method is called whenever objects are requested from the cmGeneratorTarget. Because the Xcode generator makes no such request, explicitly invoke the method from that generator so that the logic of checking for bad sources in object libraries is executed. In a follow-up, the UseObjectLibraries usage may be replaced by a true generator expression evaluator for TARGET_OBJECTS. That will require generators to use cmGeneratorTarget::GetExternalObjects which is not currently the case for Xcode and VS generators. --- Source/cmGeneratorTarget.cxx | 31 +++++++++++++++++++++----- Source/cmGeneratorTarget.h | 5 +++-- Source/cmGlobalGenerator.cxx | 46 --------------------------------------- Source/cmGlobalGenerator.h | 2 -- Source/cmGlobalXCodeGenerator.cxx | 2 ++ 5 files changed, 30 insertions(+), 56 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 64ca863..321dd42 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -311,18 +311,36 @@ cmGeneratorTarget ::GetObjectSources(std::vector &data) const { IMPLEMENT_VISIT(ObjectSources); + + if (!this->Objects.empty()) + { + return; + } + + for(std::vector::const_iterator it = data.begin(); + it != data.end(); ++it) + { + this->Objects[*it]; + } + + this->LocalGenerator->ComputeObjectFilenames(this->Objects, this); } -//---------------------------------------------------------------------------- -const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file) +void cmGeneratorTarget::ComputeObjectMapping() { - return this->Objects[file]; + if(!this->Objects.empty()) + { + return; + } + std::vector sourceFiles; + this->GetObjectSources(sourceFiles); } -void cmGeneratorTarget::AddObject(cmSourceFile const* sf, - std::string const&name) +//---------------------------------------------------------------------------- +const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file) { - this->Objects[sf] = name; + this->ComputeObjectMapping(); + return this->Objects[file]; } //---------------------------------------------------------------------------- @@ -334,6 +352,7 @@ void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf) //---------------------------------------------------------------------------- bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const { + const_cast(this)->ComputeObjectMapping(); std::set::const_iterator it = this->ExplicitObjectName.find(file); return it != this->ExplicitObjectName.end(); diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index cb59783..38e6510 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -35,7 +35,6 @@ public: void GetObjectSources(std::vector &) const; const std::string& GetObjectName(cmSourceFile const* file); - void AddObject(cmSourceFile const* sf, std::string const&name); bool HasExplicitObjectName(cmSourceFile const* file) const; void AddExplicitObjectName(cmSourceFile const* sf); @@ -47,6 +46,8 @@ public: void GetCustomCommands(std::vector&) const; void GetExpectedResxHeaders(std::set&) const; + void ComputeObjectMapping(); + cmTarget* Target; cmMakefile* Makefile; cmLocalGenerator* LocalGenerator; @@ -123,7 +124,7 @@ private: typedef std::map SourceEntriesType; SourceEntriesType SourceEntries; - std::map Objects; + mutable std::map Objects; std::set ExplicitObjectName; mutable std::map > SystemIncludesCache; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 6caaee3..66ccf39 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1222,8 +1222,6 @@ void cmGlobalGenerator::Generate() this->LocalGenerators[i]->GenerateTargetManifest(); } - this->ComputeGeneratorTargetObjects(); - this->ProcessEvaluationFiles(); // Compute the inter-target dependencies. @@ -1440,27 +1438,6 @@ void cmGlobalGenerator::CreateGeneratorTargets() } } -//---------------------------------------------------------------------------- -void cmGlobalGenerator::ComputeGeneratorTargetObjects() -{ - // Construct per-target generator information. - for(unsigned int i=0; i < this->LocalGenerators.size(); ++i) - { - cmMakefile *mf = this->LocalGenerators[i]->GetMakefile(); - cmGeneratorTargetsType targets = mf->GetGeneratorTargets(); - for(cmGeneratorTargetsType::iterator ti = targets.begin(); - ti != targets.end(); ++ti) - { - if (ti->second->Target->IsImported() - || ti->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY) - { - continue; - } - cmGeneratorTarget* gt = ti->second; - this->ComputeTargetObjects(gt); - } - } -} //---------------------------------------------------------------------------- void cmGlobalGenerator::ClearGeneratorMembers() @@ -1522,29 +1499,6 @@ cmGlobalGenerator::GetGeneratorTarget(cmTarget const* t) const } //---------------------------------------------------------------------------- -void cmGlobalGenerator::ComputeTargetObjects(cmGeneratorTarget* gt) const -{ - std::vector objectSources; - gt->GetObjectSources(objectSources); - - std::map mapping; - for(std::vector::const_iterator it - = objectSources.begin(); it != objectSources.end(); ++it) - { - mapping[*it]; - } - - gt->LocalGenerator->ComputeObjectFilenames(mapping, gt); - - for(std::map::const_iterator it - = mapping.begin(); it != mapping.end(); ++it) - { - assert(!it->second.empty()); - gt->AddObject(it->first, it->second); - } -} - -//---------------------------------------------------------------------------- void cmGlobalGenerator::ComputeTargetObjectDirectory(cmGeneratorTarget*) const { } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 668bb6b..54f5f3b 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -444,8 +444,6 @@ private: friend class cmake; void CreateGeneratorTargets(cmMakefile* mf); void CreateGeneratorTargets(); - void ComputeGeneratorTargetObjects(); - void ComputeTargetObjects(cmGeneratorTarget* gt) const; void ClearGeneratorMembers(); diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 2a6e522..d9d4927 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -987,6 +987,8 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen, cmtarget.GetSourceFiles(classes); std::sort(classes.begin(), classes.end(), cmSourceFilePathCompare()); + gtgt->ComputeObjectMapping(); + std::vector externalObjFiles; std::vector headerFiles; std::vector resourceFiles; -- cgit v0.12 From 5de63265e3a22d9a8aa5ad437a5030ccfcbcd02d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 20 Mar 2014 15:37:12 +0100 Subject: Genex: Only evaluate TARGET_OBJECTS to determine target sources. The output of this expression may contain macros for IDEs to replace such as $(Configuration), $(CURRENT_ARCH) etc. To avoid generating content which is not usable in other contexts, report an error if there is an attempt to use it in other contexts. This commit may be reverted in the future if a solution to the above difference is implemented. --- Help/manual/cmake-generator-expressions.7.rst | 4 +- Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst | 6 --- Source/cmGeneratorExpression.cxx | 4 +- Source/cmGeneratorExpression.h | 6 +++ Source/cmGeneratorExpressionEvaluator.cxx | 10 +++++ Source/cmGeneratorExpressionEvaluator.h | 1 + Source/cmTarget.cxx | 1 + Tests/GeneratorExpression/CMakeLists.txt | 14 ------- Tests/GeneratorExpression/check_object_files.cmake | 48 ---------------------- Tests/GeneratorExpression/objlib1.c | 5 --- Tests/GeneratorExpression/objlib2.c | 5 --- Tests/RunCMake/TargetObjects/BadContext-result.txt | 1 + Tests/RunCMake/TargetObjects/BadContext-stderr.txt | 17 ++++++++ Tests/RunCMake/TargetObjects/BadContext.cmake | 4 ++ Tests/RunCMake/TargetObjects/NoTarget-result.txt | 1 - Tests/RunCMake/TargetObjects/NoTarget-stderr.txt | 8 ---- Tests/RunCMake/TargetObjects/NoTarget.cmake | 2 - .../TargetObjects/NotObjlibTarget-result.txt | 1 - .../TargetObjects/NotObjlibTarget-stderr.txt | 8 ---- Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake | 4 -- Tests/RunCMake/TargetObjects/RunCMakeTest.cmake | 3 +- Tests/RunCMake/TargetObjects/empty.cpp | 7 ---- 22 files changed, 47 insertions(+), 113 deletions(-) delete mode 100644 Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst delete mode 100644 Tests/GeneratorExpression/check_object_files.cmake delete mode 100644 Tests/GeneratorExpression/objlib1.c delete mode 100644 Tests/GeneratorExpression/objlib2.c create mode 100644 Tests/RunCMake/TargetObjects/BadContext-result.txt create mode 100644 Tests/RunCMake/TargetObjects/BadContext-stderr.txt create mode 100644 Tests/RunCMake/TargetObjects/BadContext.cmake delete mode 100644 Tests/RunCMake/TargetObjects/NoTarget-result.txt delete mode 100644 Tests/RunCMake/TargetObjects/NoTarget-stderr.txt delete mode 100644 Tests/RunCMake/TargetObjects/NoTarget.cmake delete mode 100644 Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt delete mode 100644 Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt delete mode 100644 Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake delete mode 100644 Tests/RunCMake/TargetObjects/empty.cpp diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index 17263d4..dfda8dc 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -190,4 +190,6 @@ property is non-empty:: Content of ``...`` converted to a C identifier. ``$`` List of objects resulting from build of ``objLib``. ``objLib`` must be an - object of type ``OBJECT_LIBRARY``. + object of type ``OBJECT_LIBRARY``. This expression may only be used in + the sources of :command:`add_library` and :command:`add_executable` + commands. diff --git a/Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst b/Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst deleted file mode 100644 index 853a803..0000000 --- a/Help/release/dev/file-GENERATE-TARGET_OBJECTS.rst +++ /dev/null @@ -1,6 +0,0 @@ -file-GENERATE-TARGET_OBJECTS ----------------------------- - -* The :command:`file(GENERATE)` subcommand learned to evaluate the - ``TARGET_OBJECTS`` - :manual:`generator expression `. diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index e127f3a..d09e950 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -90,6 +90,7 @@ const char *cmCompiledGeneratorExpression::Evaluate( context.HadError = false; context.HadContextSensitiveCondition = false; context.HeadTarget = headTarget; + context.EvaluateForBuildsystem = this->EvaluateForBuildsystem; context.CurrentTarget = currentTarget ? currentTarget : headTarget; context.Backtrace = this->Backtrace; @@ -124,7 +125,8 @@ cmCompiledGeneratorExpression::cmCompiledGeneratorExpression( cmListFileBacktrace const& backtrace, const std::string& input) : Backtrace(backtrace), Input(input), - HadContextSensitiveCondition(false) + HadContextSensitiveCondition(false), + EvaluateForBuildsystem(false) { cmGeneratorExpressionLexer l; std::vector tokens = diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index d0a6aef..da64515 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -112,6 +112,11 @@ public: return this->HadContextSensitiveCondition; } + void SetEvaluateForBuildsystem(bool eval) + { + this->EvaluateForBuildsystem = eval; + } + private: cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace, const std::string& input); @@ -131,6 +136,7 @@ private: mutable std::set SeenTargetProperties; mutable std::string Output; mutable bool HadContextSensitiveCondition; + bool EvaluateForBuildsystem; }; #endif diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 669694c..95227d2 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -1251,6 +1251,16 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode const GeneratorExpressionContent *content, cmGeneratorExpressionDAGChecker *) const { + if (!context->EvaluateForBuildsystem) + { + cmOStringStream e; + e << "The evaluation of the TARGET_OBJECTS generator expression " + "is only suitable for consumption by CMake. It is not suitable " + "for writing out elsewhere."; + reportError(context, content->GetOriginalExpression(), e.str()); + return std::string(); + } + std::string tgtName = parameters.front(); cmGeneratorTarget* gt = context->Makefile->FindGeneratorTargetToUse(tgtName.c_str()); diff --git a/Source/cmGeneratorExpressionEvaluator.h b/Source/cmGeneratorExpressionEvaluator.h index a7099cb..54a2548 100644 --- a/Source/cmGeneratorExpressionEvaluator.h +++ b/Source/cmGeneratorExpressionEvaluator.h @@ -34,6 +34,7 @@ struct cmGeneratorExpressionContext bool Quiet; bool HadError; bool HadContextSensitiveCondition; + bool EvaluateForBuildsystem; }; struct cmGeneratorExpressionDAGChecker; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 61260be..aeb477d 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -732,6 +732,7 @@ cmSourceFile* cmTarget::AddSource(const std::string& src) this->Makefile->GetBacktrace(lfbt); cmGeneratorExpression ge(lfbt); cmsys::auto_ptr cge = ge.Parse(src); + cge->SetEvaluateForBuildsystem(true); this->Internal->SourceEntries.push_back( new cmTargetInternals::TargetPropertyEntry(cge)); } diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt index b506853..758165c 100644 --- a/Tests/GeneratorExpression/CMakeLists.txt +++ b/Tests/GeneratorExpression/CMakeLists.txt @@ -258,17 +258,3 @@ set(CMP0044_TYPE NEW) add_subdirectory(CMP0044 ${CMAKE_BINARY_DIR}/CMP0044-NEW) set(CMP0044_TYPE OLD) add_subdirectory(CMP0044 ${CMAKE_BINARY_DIR}/CMP0044-OLD) - -add_library(objlib OBJECT objlib1.c objlib2.c) -file(GENERATE - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/objlib_files" - CONTENT "$,\n>\n" -) -add_custom_target(check_object_files ALL - COMMAND ${CMAKE_COMMAND} - "-DOBJLIB_LISTFILE=${CMAKE_CURRENT_BINARY_DIR}/objlib_files" - -DTEST_CONFIGURATION=${CMAKE_BUILD_TYPE} - -DEXPECTED_NUM_OBJECTFILES=2 - -P "${CMAKE_CURRENT_SOURCE_DIR}/check_object_files.cmake" - DEPENDS objlib -) diff --git a/Tests/GeneratorExpression/check_object_files.cmake b/Tests/GeneratorExpression/check_object_files.cmake deleted file mode 100644 index 889fe80..0000000 --- a/Tests/GeneratorExpression/check_object_files.cmake +++ /dev/null @@ -1,48 +0,0 @@ - -if (NOT EXISTS ${OBJLIB_LISTFILE}) - message(SEND_ERROR "Object listing file \"${OBJLIB_LISTFILE}\" not found!") -endif() - -file(STRINGS ${OBJLIB_LISTFILE} objlib_files) - -list(LENGTH objlib_files num_objectfiles) -if (NOT EXPECTED_NUM_OBJECTFILES EQUAL num_objectfiles) - message(SEND_ERROR "Unexpected number of entries in object list file (${num_objectfiles} instead of ${EXPECTED_NUM_OBJECTFILES})") -endif() - -foreach(objlib_file ${objlib_files}) - set(file_exists False) - if (EXISTS ${objlib_file}) - set(file_exists True) - endif() - - if (NOT file_exists) - if (objlib_file MATCHES ".(CURRENT_ARCH)") - string(REPLACE "$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)" "*" config_file "${objlib_file}") - string(REPLACE "$(PROJECT_NAME)" "GeneratorExpression" config_file "${config_file}") - string(REPLACE "$(CURRENT_ARCH)" "*" config_file "${config_file}") - file(GLOB_RECURSE files "${config_file}") - list(LENGTH files num_files) - if (NOT files) - message(SEND_ERROR "Got no files for expression ${config_file}") - endif() - set(file_exists True) - else() - foreach(config_macro "$(Configuration)" "$(OutDir)" "$(IntDir)") - string(REPLACE "${config_macro}" "${TEST_CONFIGURATION}" config_file "${objlib_file}") - list(APPEND attempts ${config_file}) - if (EXISTS ${config_file}) - set(file_exists True) - endif() - endforeach() - endif() - endif() - - if (NOT file_exists) - if(attempts) - list(REMOVE_DUPLICATES attempts) - set(tried " Tried ${attempts}") - endif() - message(SEND_ERROR "File \"${objlib_file}\" does not exist!${tried}") - endif() -endforeach() diff --git a/Tests/GeneratorExpression/objlib1.c b/Tests/GeneratorExpression/objlib1.c deleted file mode 100644 index aa8de0a..0000000 --- a/Tests/GeneratorExpression/objlib1.c +++ /dev/null @@ -1,5 +0,0 @@ - -void objlib1() -{ - -} diff --git a/Tests/GeneratorExpression/objlib2.c b/Tests/GeneratorExpression/objlib2.c deleted file mode 100644 index 3c7307a..0000000 --- a/Tests/GeneratorExpression/objlib2.c +++ /dev/null @@ -1,5 +0,0 @@ - -void objlib2() -{ - -} diff --git a/Tests/RunCMake/TargetObjects/BadContext-result.txt b/Tests/RunCMake/TargetObjects/BadContext-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetObjects/BadContext-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetObjects/BadContext-stderr.txt b/Tests/RunCMake/TargetObjects/BadContext-stderr.txt new file mode 100644 index 0000000..92f2c91 --- /dev/null +++ b/Tests/RunCMake/TargetObjects/BadContext-stderr.txt @@ -0,0 +1,17 @@ +CMake Error at BadContext.cmake:2 \(file\): + Error evaluating generator expression: + + \$ + + The evaluation of the TARGET_OBJECTS generator expression is only suitable + for consumption by CMake. It is not suitable for writing out elsewhere. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) ++ +CMake Error: + Error evaluating generator expression: + + \$ + + The evaluation of the TARGET_OBJECTS generator expression is only suitable + for consumption by CMake. It is not suitable for writing out elsewhere. diff --git a/Tests/RunCMake/TargetObjects/BadContext.cmake b/Tests/RunCMake/TargetObjects/BadContext.cmake new file mode 100644 index 0000000..67962a4 --- /dev/null +++ b/Tests/RunCMake/TargetObjects/BadContext.cmake @@ -0,0 +1,4 @@ + +file(GENERATE OUTPUT test_output CONTENT $) + +install(FILES $ DESTINATION objects) diff --git a/Tests/RunCMake/TargetObjects/NoTarget-result.txt b/Tests/RunCMake/TargetObjects/NoTarget-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/TargetObjects/NoTarget-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/TargetObjects/NoTarget-stderr.txt b/Tests/RunCMake/TargetObjects/NoTarget-stderr.txt deleted file mode 100644 index 2c4f877..0000000 --- a/Tests/RunCMake/TargetObjects/NoTarget-stderr.txt +++ /dev/null @@ -1,8 +0,0 @@ -CMake Error at NoTarget.cmake:2 \(file\): - Error evaluating generator expression: - - \$ - - Objects of target "NoTarget" referenced but no such target exists. -Call Stack \(most recent call first\): - CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/TargetObjects/NoTarget.cmake b/Tests/RunCMake/TargetObjects/NoTarget.cmake deleted file mode 100644 index f203c23..0000000 --- a/Tests/RunCMake/TargetObjects/NoTarget.cmake +++ /dev/null @@ -1,2 +0,0 @@ - -file(GENERATE OUTPUT test_output CONTENT $) diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt b/Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/TargetObjects/NotObjlibTarget-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt b/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt deleted file mode 100644 index bb83934..0000000 --- a/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt +++ /dev/null @@ -1,8 +0,0 @@ -CMake Error at NotObjlibTarget.cmake:4 \(file\): - Error evaluating generator expression: - - \$ - - Objects of target "StaticLib" referenced but is not an OBJECT library. -Call Stack \(most recent call first\): - CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake b/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake deleted file mode 100644 index c7f8a71..0000000 --- a/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake +++ /dev/null @@ -1,4 +0,0 @@ - -add_library(StaticLib empty.cpp) - -file(GENERATE OUTPUT test_output CONTENT $) diff --git a/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake b/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake index 30b9fee..85c76e2 100644 --- a/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake +++ b/Tests/RunCMake/TargetObjects/RunCMakeTest.cmake @@ -1,4 +1,3 @@ include(RunCMake) -run_cmake(NoTarget) -run_cmake(NotObjlibTarget) +run_cmake(BadContext) diff --git a/Tests/RunCMake/TargetObjects/empty.cpp b/Tests/RunCMake/TargetObjects/empty.cpp deleted file mode 100644 index bfbbdde..0000000 --- a/Tests/RunCMake/TargetObjects/empty.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#ifdef _WIN32 -__declspec(dllexport) -#endif -int empty() -{ - return 0; -} -- cgit v0.12