diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2018-09-19 12:12:35 (GMT) |
---|---|---|
committer | Craig Scott <craig.scott@crascit.com> | 2018-09-25 13:59:59 (GMT) |
commit | f9717725f9d4c7f4a1da52b0184365cd757bc076 (patch) | |
tree | ee805f2e0fbd53cc0b2b72728e08496f0df57372 /Source | |
parent | b5915744ebccd086891f1fab0ae91af54deb3a86 (diff) | |
download | CMake-f9717725f9d4c7f4a1da52b0184365cd757bc076.zip CMake-f9717725f9d4c7f4a1da52b0184365cd757bc076.tar.gz CMake-f9717725f9d4c7f4a1da52b0184365cd757bc076.tar.bz2 |
link_directories(): enhance capabilities
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmLinkDirectoriesCommand.cxx | 25 | ||||
-rw-r--r-- | Source/cmLinkDirectoriesCommand.h | 3 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 11 | ||||
-rw-r--r-- | Source/cmMakefile.h | 2 | ||||
-rw-r--r-- | Source/cmStateDirectory.cxx | 27 | ||||
-rw-r--r-- | Source/cmStateDirectory.h | 2 |
6 files changed, 62 insertions, 8 deletions
diff --git a/Source/cmLinkDirectoriesCommand.cxx b/Source/cmLinkDirectoriesCommand.cxx index 5c52c76..10425fd 100644 --- a/Source/cmLinkDirectoriesCommand.cxx +++ b/Source/cmLinkDirectoriesCommand.cxx @@ -4,6 +4,7 @@ #include <sstream> +#include "cmAlgorithms.h" #include "cmGeneratorExpression.h" #include "cmMakefile.h" #include "cmPolicies.h" @@ -20,13 +21,29 @@ bool cmLinkDirectoriesCommand::InitialPass( return true; } - for (std::string const& i : args) { - this->AddLinkDir(i); + bool before = this->Makefile->IsOn("CMAKE_LINK_DIRECTORIES_BEFORE"); + + auto i = args.cbegin(); + if ((*i) == "BEFORE") { + before = true; + ++i; + } else if ((*i) == "AFTER") { + before = false; + ++i; + } + + std::vector<std::string> directories; + for (; i != args.cend(); ++i) { + this->AddLinkDir(*i, directories); } + + this->Makefile->AddLinkDirectory(cmJoin(directories, ";"), before); + return true; } -void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir) +void cmLinkDirectoriesCommand::AddLinkDir( + std::string const& dir, std::vector<std::string>& directories) { std::string unixPath = dir; cmSystemTools::ConvertToUnixSlashes(unixPath); @@ -64,5 +81,5 @@ void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir) unixPath = tmp; } } - this->Makefile->AddLinkDirectory(unixPath); + directories.push_back(unixPath); } diff --git a/Source/cmLinkDirectoriesCommand.h b/Source/cmLinkDirectoriesCommand.h index 3fd4e50..ae4fb7f 100644 --- a/Source/cmLinkDirectoriesCommand.h +++ b/Source/cmLinkDirectoriesCommand.h @@ -36,7 +36,8 @@ public: cmExecutionStatus& status) override; private: - void AddLinkDir(std::string const& dir); + void AddLinkDir(std::string const& dir, + std::vector<std::string>& directories); }; #endif diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 963bb44..8d163b7 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1248,9 +1248,16 @@ void cmMakefile::AddLinkOption(std::string const& option) this->AppendProperty("LINK_OPTIONS", option.c_str()); } -void cmMakefile::AddLinkDirectory(std::string const& directory) +void cmMakefile::AddLinkDirectory(std::string const& directory, bool before) { - this->AppendProperty("LINK_DIRECTORIES", directory.c_str()); + cmListFileBacktrace lfbt = this->GetBacktrace(); + if (before) { + this->StateSnapshot.GetDirectory().PrependLinkDirectoriesEntry(directory, + lfbt); + } else { + this->StateSnapshot.GetDirectory().AppendLinkDirectoriesEntry(directory, + lfbt); + } } bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove) diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index cde661b..b30f281 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -182,7 +182,7 @@ public: void AddCompileDefinition(std::string const& definition); void AddCompileOption(std::string const& option); void AddLinkOption(std::string const& option); - void AddLinkDirectory(std::string const& directory); + void AddLinkDirectory(std::string const& directory, bool before = false); /** Create a new imported target with the name and type given. */ cmTarget* AddImportedTarget(const std::string& name, diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx index 5160f51..f94e714 100644 --- a/Source/cmStateDirectory.cxx +++ b/Source/cmStateDirectory.cxx @@ -417,6 +417,33 @@ void cmStateDirectory::AppendLinkDirectoriesEntry( this->DirectoryState->LinkDirectoriesBacktraces, this->Snapshot_.Position->LinkDirectoriesPosition, vec, lfbt); } +void cmStateDirectory::PrependLinkDirectoriesEntry( + const std::string& vec, const cmListFileBacktrace& lfbt) +{ + std::vector<std::string>::iterator entryEnd = + this->DirectoryState->LinkDirectories.begin() + + this->Snapshot_.Position->LinkDirectoriesPosition; + + std::vector<std::string>::reverse_iterator rend = + this->DirectoryState->LinkDirectories.rend(); + std::vector<std::string>::reverse_iterator rbegin = + cmMakeReverseIterator(entryEnd); + rbegin = std::find(rbegin, rend, cmPropertySentinal); + + std::vector<std::string>::iterator entryIt = rbegin.base(); + std::vector<std::string>::iterator entryBegin = + this->DirectoryState->LinkDirectories.begin(); + + std::vector<cmListFileBacktrace>::iterator btIt = + this->DirectoryState->LinkDirectoriesBacktraces.begin() + + std::distance(entryBegin, entryIt); + + this->DirectoryState->LinkDirectories.insert(entryIt, vec); + this->DirectoryState->LinkDirectoriesBacktraces.insert(btIt, lfbt); + + this->Snapshot_.Position->LinkDirectoriesPosition = + this->DirectoryState->LinkDirectories.size(); +} void cmStateDirectory::SetLinkDirectories(const std::string& vec, const cmListFileBacktrace& lfbt) diff --git a/Source/cmStateDirectory.h b/Source/cmStateDirectory.h index 06345e2..e5f4d05 100644 --- a/Source/cmStateDirectory.h +++ b/Source/cmStateDirectory.h @@ -62,6 +62,8 @@ public: cmBacktraceRange GetLinkOptionsEntryBacktraces() const; void AppendLinkOptionsEntry(std::string const& vec, cmListFileBacktrace const& lfbt); + void PrependLinkDirectoriesEntry(std::string const& vec, + cmListFileBacktrace const& lfbt); void SetLinkOptions(std::string const& vec, cmListFileBacktrace const& lfbt); void ClearLinkOptions(); |