diff options
author | Brad King <brad.king@kitware.com> | 2012-10-02 14:07:32 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2012-10-02 14:07:32 (GMT) |
commit | 47e50423bfbbb277e60b578d1a7174f1fc24b01c (patch) | |
tree | a4c46d3a4e0d9a08e6b2b83b783385392d182ece /Source | |
parent | 851a3a0b750cde77ae6cb0895fac1e19e020c05e (diff) | |
parent | 1e47ccb5542954e1258affe36e0089f13618d23d (diff) | |
download | CMake-47e50423bfbbb277e60b578d1a7174f1fc24b01c.zip CMake-47e50423bfbbb277e60b578d1a7174f1fc24b01c.tar.gz CMake-47e50423bfbbb277e60b578d1a7174f1fc24b01c.tar.bz2 |
Merge topic 'ninja-LIBPATH'
1e47ccb Ninja: add option to enforce usage of response files
e31df03 Ninja: move <OBJECTS> in front of the first linker option
8d674e7 Ninja: move -LIBPATH behind -link option
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmLocalGenerator.cxx | 41 | ||||
-rw-r--r-- | Source/cmLocalGenerator.h | 7 | ||||
-rw-r--r-- | Source/cmMakefileExecutableTargetGenerator.cxx | 12 | ||||
-rw-r--r-- | Source/cmMakefileLibraryTargetGenerator.cxx | 11 | ||||
-rw-r--r-- | Source/cmNinjaNormalTargetGenerator.cxx | 39 | ||||
-rw-r--r-- | Source/cmake.cxx | 6 |
6 files changed, 79 insertions, 37 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 6079ba8..c7995a3 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -676,9 +676,13 @@ void cmLocalGenerator::AddBuildTargetRule(const char* llang, // Static Library: // Shared Module: std::string linkLibs; // should be set + std::string frameworkPath; + std::string linkPath; std::string flags; // should be set std::string linkFlags; // should be set - this->GetTargetFlags(linkLibs, flags, linkFlags, &target); + this->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags, + &target); + linkLibs = frameworkPath + linkPath + linkLibs; cmLocalGenerator::RuleVariables vars; vars.Language = llang; vars.Objects = objs.c_str(); @@ -1453,6 +1457,8 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs, void cmLocalGenerator::GetTargetFlags(std::string& linkLibs, std::string& flags, std::string& linkFlags, + std::string& frameworkPath, + std::string& linkPath, cmGeneratorTarget* target) { std::string buildType = @@ -1534,9 +1540,8 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs, linkFlags += " "; } } - cmOStringStream linklibsStr; - this->OutputLinkLibraries(linklibsStr, *target, false); - linkLibs = linklibsStr.str(); + this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath, + *target, false); } break; case cmTarget::EXECUTABLE: @@ -1560,9 +1565,8 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs, return; } this->AddLanguageFlags(flags, linkLanguage, buildType.c_str()); - cmOStringStream linklibs; - this->OutputLinkLibraries(linklibs, *target, false); - linkLibs = linklibs.str(); + this->OutputLinkLibraries(linkLibs, frameworkPath, linkPath, + *target, false); if(cmSystemTools::IsOn (this->Makefile->GetDefinition("BUILD_SHARED_LIBS"))) { @@ -1654,10 +1658,13 @@ std::string cmLocalGenerator::ConvertToLinkReference(std::string const& lib) * targetLibrary should be a NULL pointer. For libraries, it should point * to the name of the library. This will not link a library against itself. */ -void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, - cmGeneratorTarget& tgt, +void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries, + std::string& frameworkPath, + std::string& linkPath, + cmGeneratorTarget &tgt, bool relink) { + cmOStringStream fout; const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"); cmComputeLinkInformation* pcli = tgt.GetLinkInformation(config); if(!pcli) @@ -1691,9 +1698,9 @@ void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, for(std::vector<std::string>::const_iterator fdi = fwDirs.begin(); fdi != fwDirs.end(); ++fdi) { - linkLibs += "-F"; - linkLibs += this->Convert(fdi->c_str(), NONE, SHELL, false); - linkLibs += " "; + frameworkPath = " -F"; + frameworkPath += this->Convert(fdi->c_str(), NONE, SHELL, false); + frameworkPath += " "; } // Append the library search path flags. @@ -1702,10 +1709,10 @@ void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, libDir != libDirs.end(); ++libDir) { std::string libpath = this->ConvertToOutputForExisting(libDir->c_str()); - linkLibs += libPathFlag; - linkLibs += libpath; - linkLibs += libPathTerminator; - linkLibs += " "; + linkPath += " " + libPathFlag; + linkPath += libpath; + linkPath += libPathTerminator; + linkPath += " "; } // Append the link items. @@ -1777,6 +1784,8 @@ void cmLocalGenerator::OutputLinkLibraries(std::ostream& fout, { fout << stdLibs << " "; } + + linkLibraries = fout.str(); } diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 9aaacf7..49bce38 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -340,11 +340,16 @@ public: void GetTargetFlags(std::string& linkLibs, std::string& flags, std::string& linkFlags, + std::string& frameworkPath, + std::string& linkPath, cmGeneratorTarget* target); protected: ///! put all the libraries for a target on into the given stream - virtual void OutputLinkLibraries(std::ostream&, cmGeneratorTarget&, + virtual void OutputLinkLibraries(std::string& linkLibraries, + std::string& frameworkPath, + std::string& linkPath, + cmGeneratorTarget &, bool relink); // Expand rule variables in CMake of the type found in language rules diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 761cb26..b7a454b 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -323,10 +323,13 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) this->LocalGenerator->SetLinkScriptShell(useLinkScript); // Collect up flags to link in needed libraries. - cmOStringStream linklibs; - this->LocalGenerator->OutputLinkLibraries(linklibs, *this->GeneratorTarget, + std::string linkLibs; + std::string frameworkPath; + std::string linkPath; + this->LocalGenerator->OutputLinkLibraries(linkLibs, frameworkPath, linkPath, + *this->GeneratorTarget, relink); - + linkLibs = frameworkPath + linkPath + linkLibs; // Construct object file lists that may be needed to expand the // rule. std::string buildObjs; @@ -365,8 +368,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink) vars.TargetVersionMajor = targetVersionMajor.c_str(); vars.TargetVersionMinor = targetVersionMinor.c_str(); - std::string linkString = linklibs.str(); - vars.LinkLibraries = linkString.c_str(); + vars.LinkLibraries = linkLibs.c_str(); vars.Flags = flags.c_str(); vars.LinkFlags = linkFlags.c_str(); // Expand placeholders in the commands. diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index cb2b8c8..e7004d6 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -546,11 +546,15 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules this->LocalGenerator->SetLinkScriptShell(useLinkScript); // Collect up flags to link in needed libraries. - cmOStringStream linklibs; + std::string linkLibs; if(this->Target->GetType() != cmTarget::STATIC_LIBRARY) { + std::string frameworkPath; + std::string linkPath; this->LocalGenerator - ->OutputLinkLibraries(linklibs, *this->GeneratorTarget, relink); + ->OutputLinkLibraries(linkLibs, frameworkPath, linkPath, + *this->GeneratorTarget, relink); + linkLibs = frameworkPath + linkPath + linkLibs; } // Construct object file lists that may be needed to expand the @@ -591,8 +595,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules cmLocalGenerator::SHELL); vars.ObjectDir = objdir.c_str(); vars.Target = targetOutPathReal.c_str(); - std::string linkString = linklibs.str(); - vars.LinkLibraries = linkString.c_str(); + vars.LinkLibraries = linkLibs.c_str(); vars.ObjectsQuoted = buildObjs.c_str(); if (this->Target->HasSOName(this->ConfigName)) { diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index a13e1f0..6c54ced 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -168,11 +168,13 @@ cmNinjaNormalTargetGenerator std::string responseFlag; if (!useResponseFile) { vars.Objects = "$in"; - vars.LinkLibraries = "$LINK_LIBRARIES"; + vars.LinkLibraries = "$LINK_PATH $LINK_LIBRARIES"; } else { - // handle response file - std::string cmakeLinkVar = std::string("CMAKE_") + - this->TargetLinkLanguage + "_RESPONSE_FILE_LINK_FLAG"; + std::string cmakeVarLang = "CMAKE_"; + cmakeVarLang += this->TargetLinkLanguage; + + // build response file name + std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG"; const char * flag = GetMakefile()->GetDefinition(cmakeLinkVar.c_str()); if(flag) { responseFlag = flag; @@ -181,7 +183,14 @@ cmNinjaNormalTargetGenerator } rspfile = "$RSP_FILE"; responseFlag += rspfile; - rspcontent = "$in $LINK_LIBRARIES"; + + // build response file content + std::string linkOptionVar = cmakeVarLang; + linkOptionVar += "_COMPILER_LINKER_OPTION_FLAG_"; + linkOptionVar += cmTarget::GetTargetTypeName(targetType); + const std::string linkOption = + GetMakefile()->GetSafeDefinition(linkOptionVar.c_str()); + rspcontent = "$in " + linkOption + " $LINK_PATH $LINK_LIBRARIES"; vars.Objects = responseFlag.c_str(); vars.LinkLibraries = ""; } @@ -420,12 +429,17 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() cmNinjaDeps explicitDeps = this->GetObjects(); cmNinjaDeps implicitDeps = this->ComputeLinkDeps(); + std::string frameworkPath; + std::string linkPath; this->GetLocalGenerator()->GetTargetFlags(vars["LINK_LIBRARIES"], vars["FLAGS"], vars["LINK_FLAGS"], + frameworkPath, + linkPath, this->GetGeneratorTarget()); this->AddModuleDefinitionFlag(vars["LINK_FLAGS"]); + vars["LINK_PATH"] = frameworkPath + linkPath; // Compute architecture specific link flags. Yes, these go into a different // variable for executables, probably due to a mistake made when duplicating @@ -539,15 +553,20 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() int linkRuleLength = this->GetGlobalGenerator()-> GetRuleCmdLength(this->LanguageLinkerRule()); + + int commandLineLengthLimit = 1; + const char* forceRspFile = "CMAKE_NINJA_FORCE_RESPONSE_FILE"; + if (!this->GetMakefile()->IsDefinitionSet(forceRspFile) && + cmSystemTools::GetEnv(forceRspFile) == 0) { #ifdef _WIN32 - int commandLineLengthLimit = 8000 - linkRuleLength; + commandLineLengthLimit = 8000 - linkRuleLength; #elif defined(__linux) || defined(__APPLE__) - // for instance ARG_MAX is 2096152 on Ubuntu or 262144 on Mac - int commandLineLengthLimit = ((int)sysconf(_SC_ARG_MAX)) - - linkRuleLength - 1000; + // for instance ARG_MAX is 2096152 on Ubuntu or 262144 on Mac + commandLineLengthLimit = ((int)sysconf(_SC_ARG_MAX))-linkRuleLength-1000; #else - int commandLineLengthLimit = -1; + commandLineLengthLimit = -1; #endif + } const std::string rspfile = std::string (cmake::GetCMakeFilesDirectoryPostSlash()) + diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 745d513..0123427 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -628,10 +628,14 @@ bool cmake::FindPackage(const std::vector<std::string>& args) std::string linkLibs; + std::string frameworkPath; + std::string linkPath; std::string flags; std::string linkFlags; cmGeneratorTarget gtgt(tgt); - lg->GetTargetFlags(linkLibs, flags, linkFlags, >gt); + lg->GetTargetFlags(linkLibs, frameworkPath, linkPath, flags, linkFlags, + >gt); + linkLibs = frameworkPath + linkPath + linkLibs; printf("%s\n", linkLibs.c_str() ); |