diff options
author | Fred Baksik <frodak17@gmail.com> | 2019-01-05 16:01:21 (GMT) |
---|---|---|
committer | Fred Baksik <frodak17@gmail.com> | 2019-01-16 15:41:27 (GMT) |
commit | 595932c4f0570ab6bdef0a50a321877ffa9c50e4 (patch) | |
tree | 1f104faee6672e08eaa34fcc179a21a614bb7848 | |
parent | 2ed2d6b46f9fb8f0742ce60bef16f1d636008136 (diff) | |
download | CMake-595932c4f0570ab6bdef0a50a321877ffa9c50e4.zip CMake-595932c4f0570ab6bdef0a50a321877ffa9c50e4.tar.gz CMake-595932c4f0570ab6bdef0a50a321877ffa9c50e4.tar.bz2 |
GHS: Update the link line processing
-- add missing executable linker libs from:
CMAKE_C_STANDARD_LIBRARIES
-- add missed transitive link libraries
-- add skipped library linker options
-- The linker expects -l../relative/path/to/lib.a to be relative to the top-level project
Because there can be multiple top-level projects convert the path to an absolute path to target
-rw-r--r-- | Modules/Compiler/GHS.cmake | 4 | ||||
-rw-r--r-- | Source/cmGhsMultiTargetGenerator.cxx | 98 | ||||
-rw-r--r-- | Source/cmGhsMultiTargetGenerator.h | 3 |
3 files changed, 49 insertions, 56 deletions
diff --git a/Modules/Compiler/GHS.cmake b/Modules/Compiler/GHS.cmake index 0583a23..b41c3eb 100644 --- a/Modules/Compiler/GHS.cmake +++ b/Modules/Compiler/GHS.cmake @@ -4,5 +4,5 @@ endif() set(__COMPILER_GHS 1) set(CMAKE_EXECUTABLE_SUFFIX "") -set(CMAKE_LIBRARY_PATH_TERMINATOR "\n") -set(CMAKE_LIBRARY_PATH_FLAG " -L") +set(CMAKE_LIBRARY_PATH_TERMINATOR "") +set(CMAKE_LIBRARY_PATH_FLAG "") diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 7d2af09..a58e59a 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -212,9 +212,7 @@ void cmGhsMultiTargetGenerator::GenerateTarget() this->WriteCompilerFlags(fout, config, language); this->WriteCompilerDefinitions(fout, config, language); this->WriteIncludes(fout, config, language); - if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) { - this->WriteTargetLinkLibraries(fout, config, language); - } + this->WriteTargetLinkLine(fout, config); this->WriteCustomCommands(fout); this->WriteSources(fout); @@ -367,59 +365,55 @@ void cmGhsMultiTargetGenerator::WriteIncludes(std::ostream& fout, } } -void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries( - std::ostream& fout, std::string const& config, std::string const& language) +void cmGhsMultiTargetGenerator::WriteTargetLinkLine(std::ostream& fout, + std::string const& config) { - // library directories - cmTargetDependSet tds = - this->GetGlobalGenerator()->GetTargetDirectDepends(this->GeneratorTarget); - for (cmTargetDependSet::iterator tdsI = tds.begin(); tdsI != tds.end(); - ++tdsI) { - const cmGeneratorTarget* tg = *tdsI; - fout << " -L\"" << GetAbsBuildFilePath(tg) << "\"" << std::endl; - } - // library targets - cmTarget::LinkLibraryVectorType llv = - this->GeneratorTarget->Target->GetOriginalLinkLibraries(); - for (cmTarget::LinkLibraryVectorType::const_iterator llvI = llv.begin(); - llvI != llv.end(); ++llvI) { - std::string libName = llvI->first; - // if it is a user defined target get the full path to the lib - cmTarget* tg(GetGlobalGenerator()->FindTarget(libName)); - if (NULL != tg) { - libName = tg->GetName() + ".a"; - } - fout << " -l\"" << libName << "\"" << std::endl; + if (this->TagType == GhsMultiGpj::INTERGRITY_APPLICATION) { + return; } - if (!this->TargetGroup) { - std::string linkLibraries; - std::string flags; - std::string linkFlags; - std::string frameworkPath; - std::string linkPath; - std::string createRule = - this->GeneratorTarget->GetCreateRuleVariable(language, config); - bool useWatcomQuote = - this->Makefile->IsOn(createRule + "_USE_WATCOM_QUOTE"); - std::unique_ptr<cmLinkLineComputer> linkLineComputer( - this->GetGlobalGenerator()->CreateLinkLineComputer( - this->LocalGenerator, - this->LocalGenerator->GetStateSnapshot().GetDirectory())); - linkLineComputer->SetUseWatcomQuote(useWatcomQuote); - - this->LocalGenerator->GetTargetFlags( - linkLineComputer.get(), config, linkLibraries, flags, linkFlags, - frameworkPath, linkPath, this->GeneratorTarget); - linkFlags = cmSystemTools::TrimWhitespace(linkFlags); - - if (!linkPath.empty()) { - linkPath = " " + linkPath.substr(0U, linkPath.size() - 1U); - fout << linkPath; - } + std::string linkLibraries; + std::string flags; + std::string linkFlags; + std::string frameworkPath; + std::string linkPath; + + std::unique_ptr<cmLinkLineComputer> linkLineComputer( + this->GetGlobalGenerator()->CreateLinkLineComputer( + this->LocalGenerator, + this->LocalGenerator->GetStateSnapshot().GetDirectory())); + + this->LocalGenerator->GetTargetFlags( + linkLineComputer.get(), config, linkLibraries, flags, linkFlags, + frameworkPath, linkPath, this->GeneratorTarget); - if (!linkFlags.empty()) { - fout << " " << linkFlags << std::endl; + // write out link options + std::vector<std::string> lopts = + cmSystemTools::ParseArguments(linkFlags.c_str()); + for (auto& l : lopts) { + fout << " " << l << std::endl; + } + + // write out link search paths + // must be quoted for paths that contain spaces + std::vector<std::string> lpath = + cmSystemTools::ParseArguments(linkPath.c_str()); + for (auto& l : lpath) { + fout << " -L\"" << l << "\"" << std::endl; + } + + // write out link libs + // must be quoted for filepaths that contains spaces + std::string cbd = this->LocalGenerator->GetCurrentBinaryDirectory(); + + std::vector<std::string> llibs = + cmSystemTools::ParseArguments(linkLibraries.c_str()); + for (auto& l : llibs) { + if (l.compare(0, 2, "-l") == 0) { + fout << " \"" << l << "\"" << std::endl; + } else { + std::string rl = cmSystemTools::CollapseCombinedPath(cbd, l); + fout << " -l\"" << rl << "\"" << std::endl; } } } diff --git a/Source/cmGhsMultiTargetGenerator.h b/Source/cmGhsMultiTargetGenerator.h index 4523498..df1c683 100644 --- a/Source/cmGhsMultiTargetGenerator.h +++ b/Source/cmGhsMultiTargetGenerator.h @@ -74,8 +74,7 @@ private: void WriteIncludes(std::ostream& fout, const std::string& config, const std::string& language); - void WriteTargetLinkLibraries(std::ostream& fout, std::string const& config, - std::string const& language); + void WriteTargetLinkLine(std::ostream& fout, std::string const& config); void WriteCustomCommands(std::ostream& fout); void WriteCustomCommandsHelper( std::ostream& fout, std::vector<cmCustomCommand> const& commandsSet, |