2011-11-11 09:00:49 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
|
|
|
|
Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmNinjaNormalTargetGenerator.h"
|
|
|
|
#include "cmLocalNinjaGenerator.h"
|
|
|
|
#include "cmGlobalNinjaGenerator.h"
|
|
|
|
#include "cmSourceFile.h"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmMakefile.h"
|
2012-07-07 21:54:16 +04:00
|
|
|
#include "cmOSXBundleGenerator.h"
|
2012-10-10 23:32:37 +04:00
|
|
|
#include "cmGeneratorTarget.h"
|
2014-03-10 23:47:19 +04:00
|
|
|
#include "cmCustomCommandGenerator.h"
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
#include <assert.h>
|
2012-07-11 10:55:00 +04:00
|
|
|
#include <algorithm>
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2012-07-11 12:15:53 +04:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
cmNinjaNormalTargetGenerator::
|
2012-10-10 23:32:37 +04:00
|
|
|
cmNinjaNormalTargetGenerator(cmGeneratorTarget* target)
|
|
|
|
: cmNinjaTargetGenerator(target->Target)
|
2011-11-11 09:00:49 +04:00
|
|
|
, TargetNameOut()
|
|
|
|
, TargetNameSO()
|
|
|
|
, TargetNameReal()
|
|
|
|
, TargetNameImport()
|
|
|
|
, TargetNamePDB()
|
2014-02-04 06:20:56 +04:00
|
|
|
, TargetLinkLanguage("")
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2012-10-10 23:32:37 +04:00
|
|
|
this->TargetLinkLanguage = target->Target
|
|
|
|
->GetLinkerLanguage(this->GetConfigName());
|
2011-11-11 09:00:49 +04:00
|
|
|
if (target->GetType() == cmTarget::EXECUTABLE)
|
2012-10-10 23:32:37 +04:00
|
|
|
target->Target->GetExecutableNames(this->TargetNameOut,
|
2011-11-11 09:00:49 +04:00
|
|
|
this->TargetNameReal,
|
|
|
|
this->TargetNameImport,
|
|
|
|
this->TargetNamePDB,
|
|
|
|
GetLocalGenerator()->GetConfigName());
|
|
|
|
else
|
2012-10-10 23:32:37 +04:00
|
|
|
target->Target->GetLibraryNames(this->TargetNameOut,
|
2011-11-11 09:00:49 +04:00
|
|
|
this->TargetNameSO,
|
|
|
|
this->TargetNameReal,
|
|
|
|
this->TargetNameImport,
|
|
|
|
this->TargetNamePDB,
|
|
|
|
GetLocalGenerator()->GetConfigName());
|
2012-02-23 22:39:54 +04:00
|
|
|
|
2012-03-13 18:05:07 +04:00
|
|
|
if(target->GetType() != cmTarget::OBJECT_LIBRARY)
|
|
|
|
{
|
|
|
|
// on Windows the output dir is already needed at compile time
|
|
|
|
// ensure the directory exists (OutDir test)
|
2012-10-10 23:32:37 +04:00
|
|
|
EnsureDirectoryExists(target->Target->GetDirectory(this->GetConfigName()));
|
2012-03-13 18:05:07 +04:00
|
|
|
}
|
2012-07-04 00:22:17 +04:00
|
|
|
|
2012-07-07 21:54:16 +04:00
|
|
|
this->OSXBundleGenerator = new cmOSXBundleGenerator(target,
|
|
|
|
this->GetConfigName());
|
|
|
|
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator()
|
|
|
|
{
|
2012-07-07 21:54:16 +04:00
|
|
|
delete this->OSXBundleGenerator;
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmNinjaNormalTargetGenerator::Generate()
|
|
|
|
{
|
2014-02-04 06:20:56 +04:00
|
|
|
if (this->TargetLinkLanguage.empty()) {
|
2013-06-21 15:51:58 +04:00
|
|
|
cmSystemTools::Error("CMake can not determine linker language for "
|
|
|
|
"target: ",
|
2014-02-07 02:31:47 +04:00
|
|
|
this->GetTarget()->GetName().c_str());
|
2011-11-11 09:00:49 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the rules for each language.
|
|
|
|
this->WriteLanguagesRules();
|
|
|
|
|
|
|
|
// Write the build statements
|
|
|
|
this->WriteObjectBuildStatements();
|
|
|
|
|
2012-03-13 18:05:07 +04:00
|
|
|
if(this->GetTarget()->GetType() == cmTarget::OBJECT_LIBRARY)
|
|
|
|
{
|
|
|
|
this->WriteObjectLibStatement();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-10 11:56:11 +04:00
|
|
|
this->WriteLinkRule(false); // write rule without rspfile support
|
|
|
|
this->WriteLinkRule(true); // write rule with rspfile support
|
2012-03-13 18:05:07 +04:00
|
|
|
this->WriteLinkStatement();
|
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
|
|
|
|
{
|
2012-06-10 22:20:29 +04:00
|
|
|
#ifdef NINJA_GEN_VERBOSE_FILES
|
2011-11-11 09:00:49 +04:00
|
|
|
cmGlobalNinjaGenerator::WriteDivider(this->GetRulesFileStream());
|
|
|
|
this->GetRulesFileStream()
|
|
|
|
<< "# Rules for each languages for "
|
|
|
|
<< cmTarget::GetTargetTypeName(this->GetTarget()->GetType())
|
|
|
|
<< " target "
|
|
|
|
<< this->GetTargetName()
|
|
|
|
<< "\n\n";
|
2012-06-10 22:20:29 +04:00
|
|
|
#endif
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> languages;
|
2011-11-11 09:00:49 +04:00
|
|
|
this->GetTarget()->GetLanguages(languages);
|
2014-02-10 09:21:34 +04:00
|
|
|
for(std::set<std::string>::const_iterator l = languages.begin();
|
2011-11-11 09:00:49 +04:00
|
|
|
l != languages.end();
|
|
|
|
++l)
|
|
|
|
this->WriteLanguageRules(*l);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *cmNinjaNormalTargetGenerator::GetVisibleTypeName() const
|
|
|
|
{
|
|
|
|
switch (this->GetTarget()->GetType()) {
|
|
|
|
case cmTarget::STATIC_LIBRARY:
|
|
|
|
return "static library";
|
|
|
|
case cmTarget::SHARED_LIBRARY:
|
|
|
|
return "shared library";
|
|
|
|
case cmTarget::MODULE_LIBRARY:
|
2012-07-11 14:58:01 +04:00
|
|
|
if (this->GetTarget()->IsCFBundleOnApple())
|
|
|
|
return "CFBundle shared module";
|
|
|
|
else
|
|
|
|
return "shared module";
|
2011-11-11 09:00:49 +04:00
|
|
|
case cmTarget::EXECUTABLE:
|
|
|
|
return "executable";
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
cmNinjaNormalTargetGenerator
|
|
|
|
::LanguageLinkerRule() const
|
|
|
|
{
|
2014-02-04 06:20:56 +04:00
|
|
|
return this->TargetLinkLanguage
|
2011-11-11 09:00:49 +04:00
|
|
|
+ "_"
|
|
|
|
+ cmTarget::GetTargetTypeName(this->GetTarget()->GetType())
|
|
|
|
+ "_LINKER";
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmNinjaNormalTargetGenerator
|
2012-06-06 00:39:42 +04:00
|
|
|
::WriteLinkRule(bool useResponseFile)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
cmTarget::TargetType targetType = this->GetTarget()->GetType();
|
|
|
|
std::string ruleName = this->LanguageLinkerRule();
|
2012-06-06 01:40:42 +04:00
|
|
|
if (useResponseFile)
|
2012-09-26 12:07:25 +04:00
|
|
|
ruleName += "_RSP_FILE";
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2012-06-06 00:39:42 +04:00
|
|
|
// Select whether to use a response file for objects.
|
|
|
|
std::string rspfile;
|
2012-07-10 11:56:11 +04:00
|
|
|
std::string rspcontent;
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
if (!this->GetGlobalGenerator()->HasRule(ruleName)) {
|
|
|
|
cmLocalGenerator::RuleVariables vars;
|
|
|
|
vars.RuleLauncher = "RULE_LAUNCH_LINK";
|
|
|
|
vars.CMTarget = this->GetTarget();
|
2014-02-04 06:20:56 +04:00
|
|
|
vars.Language = this->TargetLinkLanguage.c_str();
|
2012-06-06 00:39:42 +04:00
|
|
|
|
|
|
|
std::string responseFlag;
|
|
|
|
if (!useResponseFile) {
|
|
|
|
vars.Objects = "$in";
|
2012-09-27 13:45:25 +04:00
|
|
|
vars.LinkLibraries = "$LINK_PATH $LINK_LIBRARIES";
|
2012-06-06 00:39:42 +04:00
|
|
|
} else {
|
2012-09-27 13:45:25 +04:00
|
|
|
std::string cmakeVarLang = "CMAKE_";
|
|
|
|
cmakeVarLang += this->TargetLinkLanguage;
|
|
|
|
|
|
|
|
// build response file name
|
|
|
|
std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_LINK_FLAG";
|
2014-03-11 03:04:11 +04:00
|
|
|
const char * flag = GetMakefile()->GetDefinition(cmakeLinkVar);
|
2012-06-06 00:39:42 +04:00
|
|
|
if(flag) {
|
|
|
|
responseFlag = flag;
|
|
|
|
} else {
|
|
|
|
responseFlag = "@";
|
|
|
|
}
|
2012-09-26 12:07:25 +04:00
|
|
|
rspfile = "$RSP_FILE";
|
2012-06-06 00:39:42 +04:00
|
|
|
responseFlag += rspfile;
|
2012-09-27 13:45:25 +04:00
|
|
|
|
|
|
|
// build response file content
|
|
|
|
std::string linkOptionVar = cmakeVarLang;
|
|
|
|
linkOptionVar += "_COMPILER_LINKER_OPTION_FLAG_";
|
|
|
|
linkOptionVar += cmTarget::GetTargetTypeName(targetType);
|
|
|
|
const std::string linkOption =
|
2014-03-11 03:04:11 +04:00
|
|
|
GetMakefile()->GetSafeDefinition(linkOptionVar);
|
2013-02-02 02:02:55 +04:00
|
|
|
rspcontent = "$in_newline "+linkOption+" $LINK_PATH $LINK_LIBRARIES";
|
2012-06-06 00:39:42 +04:00
|
|
|
vars.Objects = responseFlag.c_str();
|
2012-07-10 11:56:11 +04:00
|
|
|
vars.LinkLibraries = "";
|
2012-06-06 00:39:42 +04:00
|
|
|
}
|
2012-06-12 06:17:55 +04:00
|
|
|
|
|
|
|
vars.ObjectDir = "$OBJECT_DIR";
|
2012-07-17 13:21:03 +04:00
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// Makefile generator expands <TARGET> to the plain target name
|
|
|
|
// with suffix. $out expands to a relative path. This difference
|
|
|
|
// could make trouble when switching to Ninja generator. Maybe
|
|
|
|
// using TARGET_NAME and RuleVariables::TargetName is a fix.
|
2011-11-11 09:00:49 +04:00
|
|
|
vars.Target = "$out";
|
2012-07-17 13:21:03 +04:00
|
|
|
|
2012-04-22 17:42:55 +04:00
|
|
|
vars.SONameFlag = "$SONAME_FLAG";
|
2011-11-11 09:00:49 +04:00
|
|
|
vars.TargetSOName = "$SONAME";
|
|
|
|
vars.TargetInstallNameDir = "$INSTALLNAME_DIR";
|
2012-02-22 00:18:05 +04:00
|
|
|
vars.TargetPDB = "$TARGET_PDB";
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
// Setup the target version.
|
|
|
|
std::string targetVersionMajor;
|
|
|
|
std::string targetVersionMinor;
|
|
|
|
{
|
|
|
|
cmOStringStream majorStream;
|
|
|
|
cmOStringStream minorStream;
|
|
|
|
int major;
|
|
|
|
int minor;
|
|
|
|
this->GetTarget()->GetTargetVersion(major, minor);
|
|
|
|
majorStream << major;
|
|
|
|
minorStream << minor;
|
|
|
|
targetVersionMajor = majorStream.str();
|
|
|
|
targetVersionMinor = minorStream.str();
|
|
|
|
}
|
|
|
|
vars.TargetVersionMajor = targetVersionMajor.c_str();
|
|
|
|
vars.TargetVersionMinor = targetVersionMinor.c_str();
|
|
|
|
|
2013-07-12 17:44:38 +04:00
|
|
|
vars.Flags = "$FLAGS";
|
2011-11-11 09:00:49 +04:00
|
|
|
vars.LinkFlags = "$LINK_FLAGS";
|
|
|
|
|
|
|
|
std::string langFlags;
|
2012-04-30 07:25:37 +04:00
|
|
|
if (targetType != cmTarget::EXECUTABLE) {
|
|
|
|
this->GetLocalGenerator()->AddLanguageFlags(langFlags,
|
|
|
|
this->TargetLinkLanguage,
|
|
|
|
this->GetConfigName());
|
2011-11-11 09:00:49 +04:00
|
|
|
langFlags += " $ARCH_FLAGS";
|
2012-04-30 07:25:37 +04:00
|
|
|
vars.LanguageCompileFlags = langFlags.c_str();
|
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2012-06-06 00:39:42 +04:00
|
|
|
// Rule for linking library/executable.
|
2011-11-11 09:00:49 +04:00
|
|
|
std::vector<std::string> linkCmds = this->ComputeLinkCmd();
|
|
|
|
for(std::vector<std::string>::iterator i = linkCmds.begin();
|
|
|
|
i != linkCmds.end();
|
|
|
|
++i)
|
|
|
|
{
|
|
|
|
this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
|
|
|
|
}
|
|
|
|
linkCmds.insert(linkCmds.begin(), "$PRE_LINK");
|
|
|
|
linkCmds.push_back("$POST_BUILD");
|
|
|
|
std::string linkCmd =
|
|
|
|
this->GetLocalGenerator()->BuildCommandLine(linkCmds);
|
|
|
|
|
2012-06-06 00:39:42 +04:00
|
|
|
// Write the linker rule with response file if needed.
|
2012-06-06 23:14:40 +04:00
|
|
|
cmOStringStream comment;
|
2011-11-11 09:00:49 +04:00
|
|
|
comment << "Rule for linking " << this->TargetLinkLanguage << " "
|
|
|
|
<< this->GetVisibleTypeName() << ".";
|
2012-06-06 23:14:40 +04:00
|
|
|
cmOStringStream description;
|
2011-11-11 09:00:49 +04:00
|
|
|
description << "Linking " << this->TargetLinkLanguage << " "
|
|
|
|
<< this->GetVisibleTypeName() << " $out";
|
|
|
|
this->GetGlobalGenerator()->AddRule(ruleName,
|
|
|
|
linkCmd,
|
|
|
|
description.str(),
|
2012-06-06 00:39:42 +04:00
|
|
|
comment.str(),
|
|
|
|
/*depfile*/ "",
|
2013-10-18 14:59:47 +04:00
|
|
|
/*deptype*/ "",
|
2012-07-10 11:56:11 +04:00
|
|
|
rspfile,
|
2013-10-18 14:59:47 +04:00
|
|
|
rspcontent,
|
|
|
|
/*restat*/ false,
|
|
|
|
/*generator*/ false);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2013-07-17 09:01:50 +04:00
|
|
|
if (this->TargetNameOut != this->TargetNameReal &&
|
|
|
|
!this->GetTarget()->IsFrameworkOnApple()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
std::string cmakeCommand =
|
2012-02-19 07:07:09 +04:00
|
|
|
this->GetLocalGenerator()->ConvertToOutputFormat(
|
|
|
|
this->GetMakefile()->GetRequiredDefinition("CMAKE_COMMAND"),
|
|
|
|
cmLocalGenerator::SHELL);
|
2011-11-11 09:00:49 +04:00
|
|
|
if (targetType == cmTarget::EXECUTABLE)
|
|
|
|
this->GetGlobalGenerator()->AddRule("CMAKE_SYMLINK_EXECUTABLE",
|
|
|
|
cmakeCommand +
|
|
|
|
" -E cmake_symlink_executable"
|
|
|
|
" $in $out && $POST_BUILD",
|
|
|
|
"Creating executable symlink $out",
|
2013-10-18 14:59:47 +04:00
|
|
|
"Rule for creating "
|
|
|
|
"executable symlink.",
|
|
|
|
/*depfile*/ "",
|
|
|
|
/*deptype*/ "",
|
|
|
|
/*rspfile*/ "",
|
|
|
|
/*rspcontent*/ "",
|
|
|
|
/*restat*/ false,
|
|
|
|
/*generator*/ false);
|
2011-11-11 09:00:49 +04:00
|
|
|
else
|
|
|
|
this->GetGlobalGenerator()->AddRule("CMAKE_SYMLINK_LIBRARY",
|
|
|
|
cmakeCommand +
|
|
|
|
" -E cmake_symlink_library"
|
|
|
|
" $in $SONAME $out && $POST_BUILD",
|
|
|
|
"Creating library symlink $out",
|
2013-10-18 14:59:47 +04:00
|
|
|
"Rule for creating "
|
|
|
|
"library symlink.",
|
|
|
|
/*depfile*/ "",
|
|
|
|
/*deptype*/ "",
|
|
|
|
/*rspfile*/ "",
|
|
|
|
/*rspcontent*/ "",
|
|
|
|
/*restat*/ false,
|
|
|
|
/*generator*/ false);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string>
|
|
|
|
cmNinjaNormalTargetGenerator
|
|
|
|
::ComputeLinkCmd()
|
|
|
|
{
|
2012-02-27 08:05:31 +04:00
|
|
|
std::vector<std::string> linkCmds;
|
2014-03-31 02:25:11 +04:00
|
|
|
cmMakefile* mf = this->GetMakefile();
|
|
|
|
{
|
|
|
|
std::string linkCmdVar = "CMAKE_";
|
|
|
|
linkCmdVar += this->TargetLinkLanguage;
|
|
|
|
linkCmdVar += this->GetGeneratorTarget()->GetCreateRuleVariable();
|
|
|
|
const char *linkCmd = mf->GetDefinition(linkCmdVar);
|
|
|
|
if (linkCmd)
|
|
|
|
{
|
|
|
|
cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
|
|
|
|
return linkCmds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (this->GetTarget()->GetType()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
case cmTarget::STATIC_LIBRARY: {
|
|
|
|
// We have archive link commands set. First, delete the existing archive.
|
2014-03-31 02:25:11 +04:00
|
|
|
{
|
2011-11-11 09:00:49 +04:00
|
|
|
std::string cmakeCommand =
|
2012-02-19 07:07:09 +04:00
|
|
|
this->GetLocalGenerator()->ConvertToOutputFormat(
|
2014-03-31 02:25:11 +04:00
|
|
|
mf->GetRequiredDefinition("CMAKE_COMMAND"),
|
2012-02-19 07:07:09 +04:00
|
|
|
cmLocalGenerator::SHELL);
|
2011-11-11 09:00:49 +04:00
|
|
|
linkCmds.push_back(cmakeCommand + " -E remove $out");
|
2014-03-31 02:25:11 +04:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
// TODO: Use ARCHIVE_APPEND for archives over a certain size.
|
|
|
|
{
|
|
|
|
std::string linkCmdVar = "CMAKE_";
|
|
|
|
linkCmdVar += this->TargetLinkLanguage;
|
|
|
|
linkCmdVar += "_ARCHIVE_CREATE";
|
2014-03-31 02:25:11 +04:00
|
|
|
const char *linkCmd = mf->GetRequiredDefinition(linkCmdVar);
|
2012-02-27 08:05:31 +04:00
|
|
|
cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
{
|
|
|
|
std::string linkCmdVar = "CMAKE_";
|
|
|
|
linkCmdVar += this->TargetLinkLanguage;
|
|
|
|
linkCmdVar += "_ARCHIVE_FINISH";
|
2014-03-31 02:25:11 +04:00
|
|
|
const char *linkCmd = mf->GetRequiredDefinition(linkCmdVar);
|
2012-02-27 08:05:31 +04:00
|
|
|
cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
return linkCmds;
|
|
|
|
}
|
|
|
|
case cmTarget::SHARED_LIBRARY:
|
|
|
|
case cmTarget::MODULE_LIBRARY:
|
2014-03-31 02:25:11 +04:00
|
|
|
case cmTarget::EXECUTABLE:
|
|
|
|
break;
|
2011-11-11 09:00:49 +04:00
|
|
|
default:
|
|
|
|
assert(0 && "Unexpected target type");
|
|
|
|
}
|
2012-02-05 05:48:08 +04:00
|
|
|
return std::vector<std::string>();
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmNinjaNormalTargetGenerator::WriteLinkStatement()
|
|
|
|
{
|
|
|
|
cmTarget::TargetType targetType = this->GetTarget()->GetType();
|
|
|
|
|
2012-07-04 00:22:17 +04:00
|
|
|
std::string targetOutput = ConvertToNinjaPath(
|
|
|
|
this->GetTarget()->GetFullPath(this->GetConfigName()).c_str());
|
|
|
|
std::string targetOutputReal = ConvertToNinjaPath(
|
|
|
|
this->GetTarget()->GetFullPath(this->GetConfigName(),
|
|
|
|
/*implib=*/false,
|
|
|
|
/*realpath=*/true).c_str());
|
|
|
|
std::string targetOutputImplib = ConvertToNinjaPath(
|
|
|
|
this->GetTarget()->GetFullPath(this->GetConfigName(),
|
|
|
|
/*implib=*/true).c_str());
|
|
|
|
|
|
|
|
if (this->GetTarget()->IsAppBundleOnApple())
|
|
|
|
{
|
|
|
|
// Create the app bundle
|
2013-05-06 06:19:05 +04:00
|
|
|
std::string outpath =
|
|
|
|
this->GetTarget()->GetDirectory(this->GetConfigName());
|
2012-07-07 21:54:16 +04:00
|
|
|
this->OSXBundleGenerator->CreateAppBundle(this->TargetNameOut, outpath);
|
2012-07-04 00:22:17 +04:00
|
|
|
|
|
|
|
// Calculate the output path
|
2013-05-06 06:19:05 +04:00
|
|
|
targetOutput = outpath;
|
|
|
|
targetOutput += "/";
|
|
|
|
targetOutput += this->TargetNameOut;
|
2012-07-04 00:22:17 +04:00
|
|
|
targetOutput = this->ConvertToNinjaPath(targetOutput.c_str());
|
2013-05-06 06:19:05 +04:00
|
|
|
targetOutputReal = outpath;
|
|
|
|
targetOutputReal += "/";
|
|
|
|
targetOutputReal += this->TargetNameReal;
|
2012-07-04 00:22:17 +04:00
|
|
|
targetOutputReal = this->ConvertToNinjaPath(targetOutputReal.c_str());
|
|
|
|
}
|
2012-07-05 20:31:17 +04:00
|
|
|
else if (this->GetTarget()->IsFrameworkOnApple())
|
|
|
|
{
|
|
|
|
// Create the library framework.
|
2013-05-06 06:19:05 +04:00
|
|
|
std::string outpath =
|
|
|
|
this->GetTarget()->GetDirectory(this->GetConfigName());
|
|
|
|
this->OSXBundleGenerator->CreateFramework(this->TargetNameOut, outpath);
|
2012-07-05 20:31:17 +04:00
|
|
|
}
|
2012-07-11 13:19:25 +04:00
|
|
|
else if(this->GetTarget()->IsCFBundleOnApple())
|
|
|
|
{
|
2012-07-16 18:00:40 +04:00
|
|
|
// Create the core foundation bundle.
|
2013-05-06 06:19:05 +04:00
|
|
|
std::string outpath =
|
|
|
|
this->GetTarget()->GetDirectory(this->GetConfigName());
|
2012-07-16 18:00:40 +04:00
|
|
|
this->OSXBundleGenerator->CreateCFBundle(this->TargetNameOut, outpath);
|
2012-07-11 13:19:25 +04:00
|
|
|
}
|
2012-07-04 00:22:17 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// Write comments.
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
|
|
|
|
this->GetBuildFileStream()
|
|
|
|
<< "# Link build statements for "
|
|
|
|
<< cmTarget::GetTargetTypeName(targetType)
|
|
|
|
<< " target "
|
|
|
|
<< this->GetTargetName()
|
|
|
|
<< "\n\n";
|
|
|
|
|
|
|
|
cmNinjaDeps emptyDeps;
|
|
|
|
cmNinjaVars vars;
|
|
|
|
|
|
|
|
// Compute the comment.
|
2012-06-06 23:14:40 +04:00
|
|
|
cmOStringStream comment;
|
2011-11-11 09:00:49 +04:00
|
|
|
comment << "Link the " << this->GetVisibleTypeName() << " "
|
|
|
|
<< targetOutputReal;
|
|
|
|
|
|
|
|
// Compute outputs.
|
|
|
|
cmNinjaDeps outputs;
|
|
|
|
outputs.push_back(targetOutputReal);
|
|
|
|
|
|
|
|
// Compute specific libraries to link with.
|
2012-07-11 10:55:00 +04:00
|
|
|
cmNinjaDeps explicitDeps = this->GetObjects();
|
|
|
|
cmNinjaDeps implicitDeps = this->ComputeLinkDeps();
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2014-03-31 02:25:11 +04:00
|
|
|
cmMakefile* mf = this->GetMakefile();
|
|
|
|
|
2012-09-26 16:38:15 +04:00
|
|
|
std::string frameworkPath;
|
|
|
|
std::string linkPath;
|
2014-03-31 02:25:11 +04:00
|
|
|
cmGeneratorTarget* gtarget = this->GetGeneratorTarget();
|
2011-11-11 09:00:49 +04:00
|
|
|
this->GetLocalGenerator()->GetTargetFlags(vars["LINK_LIBRARIES"],
|
|
|
|
vars["FLAGS"],
|
|
|
|
vars["LINK_FLAGS"],
|
2012-09-26 16:38:15 +04:00
|
|
|
frameworkPath,
|
|
|
|
linkPath,
|
2014-03-31 02:25:11 +04:00
|
|
|
gtarget);
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2013-11-23 13:49:36 +04:00
|
|
|
this->addPoolNinjaVariable("JOB_POOL_LINK", this->GetTarget(), vars);
|
|
|
|
|
2012-03-10 15:19:18 +04:00
|
|
|
this->AddModuleDefinitionFlag(vars["LINK_FLAGS"]);
|
2012-11-21 00:59:40 +04:00
|
|
|
vars["LINK_FLAGS"] = cmGlobalNinjaGenerator
|
|
|
|
::EncodeLiteral(vars["LINK_FLAGS"]);
|
|
|
|
|
2012-09-27 13:45:25 +04:00
|
|
|
vars["LINK_PATH"] = frameworkPath + linkPath;
|
2012-03-10 15:19:18 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// Compute architecture specific link flags. Yes, these go into a different
|
|
|
|
// variable for executables, probably due to a mistake made when duplicating
|
|
|
|
// code between the Makefile executable and library generators.
|
2012-06-14 21:39:39 +04:00
|
|
|
std::string flags = (targetType == cmTarget::EXECUTABLE
|
2011-11-11 09:00:49 +04:00
|
|
|
? vars["FLAGS"]
|
2012-06-14 21:39:39 +04:00
|
|
|
: vars["ARCH_FLAGS"]);
|
2012-06-15 03:43:08 +04:00
|
|
|
this->GetLocalGenerator()->AddArchitectureFlags(flags,
|
2014-03-31 02:25:11 +04:00
|
|
|
gtarget,
|
2011-11-11 09:00:49 +04:00
|
|
|
this->TargetLinkLanguage,
|
|
|
|
this->GetConfigName());
|
2012-06-14 21:39:39 +04:00
|
|
|
if (targetType == cmTarget::EXECUTABLE) {
|
|
|
|
vars["FLAGS"] = flags;
|
|
|
|
} else {
|
|
|
|
vars["ARCH_FLAGS"] = flags;
|
|
|
|
}
|
2012-04-22 17:42:55 +04:00
|
|
|
if (this->GetTarget()->HasSOName(this->GetConfigName())) {
|
|
|
|
vars["SONAME_FLAG"] =
|
2014-03-31 02:25:11 +04:00
|
|
|
mf->GetSONameFlag(this->TargetLinkLanguage);
|
2012-04-22 17:42:55 +04:00
|
|
|
vars["SONAME"] = this->TargetNameSO;
|
|
|
|
if (targetType == cmTarget::SHARED_LIBRARY) {
|
|
|
|
std::string install_name_dir = this->GetTarget()
|
|
|
|
->GetInstallNameDirForBuildTree(this->GetConfigName());
|
|
|
|
|
|
|
|
if (!install_name_dir.empty()) {
|
|
|
|
vars["INSTALLNAME_DIR"] =
|
2014-03-11 03:04:11 +04:00
|
|
|
this->GetLocalGenerator()->Convert(install_name_dir,
|
2012-04-22 17:42:55 +04:00
|
|
|
cmLocalGenerator::NONE,
|
|
|
|
cmLocalGenerator::SHELL, false);
|
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-20 01:38:10 +04:00
|
|
|
if (!this->TargetNameImport.empty()) {
|
2012-08-22 14:26:56 +04:00
|
|
|
const std::string impLibPath = this->GetLocalGenerator()
|
2014-03-11 03:04:11 +04:00
|
|
|
->ConvertToOutputFormat(targetOutputImplib,
|
2012-08-22 14:26:56 +04:00
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
vars["TARGET_IMPLIB"] = impLibPath;
|
|
|
|
EnsureParentDirectoryExists(impLibPath);
|
2012-02-20 01:38:10 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 14:37:55 +04:00
|
|
|
if (!this->SetMsvcTargetPdbVariable(vars))
|
2012-07-16 16:16:43 +04:00
|
|
|
{
|
|
|
|
// It is common to place debug symbols at a specific place,
|
|
|
|
// so we need a plain target name in the rule available.
|
2012-07-18 12:50:57 +04:00
|
|
|
std::string prefix;
|
2012-07-17 13:21:03 +04:00
|
|
|
std::string base;
|
|
|
|
std::string suffix;
|
2012-07-18 12:50:57 +04:00
|
|
|
this->GetTarget()->GetFullNameComponents(prefix, base, suffix);
|
2012-07-17 13:45:19 +04:00
|
|
|
std::string dbg_suffix = ".dbg";
|
|
|
|
// TODO: Where to document?
|
|
|
|
if (mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX"))
|
|
|
|
dbg_suffix = mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX");
|
|
|
|
vars["TARGET_PDB"] = base + suffix + dbg_suffix;
|
2012-07-16 16:16:43 +04:00
|
|
|
}
|
2012-06-12 06:17:55 +04:00
|
|
|
|
|
|
|
if (mf->IsOn("CMAKE_COMPILER_IS_MINGW"))
|
|
|
|
{
|
2012-08-22 14:26:56 +04:00
|
|
|
const std::string objPath = GetTarget()->GetSupportDirectory();
|
|
|
|
vars["OBJECT_DIR"] = ConvertToNinjaPath(objPath.c_str());
|
|
|
|
EnsureDirectoryExists(objPath);
|
2012-11-07 20:13:09 +04:00
|
|
|
// ar.exe can't handle backslashes in rsp files (implicitly used by gcc)
|
2012-07-11 10:55:00 +04:00
|
|
|
std::string& linkLibraries = vars["LINK_LIBRARIES"];
|
|
|
|
std::replace(linkLibraries.begin(), linkLibraries.end(), '\\', '/');
|
2012-06-12 06:17:55 +04:00
|
|
|
}
|
2012-02-22 00:18:05 +04:00
|
|
|
|
2013-11-19 14:05:47 +04:00
|
|
|
const std::vector<cmCustomCommand> *cmdLists[3] = {
|
2011-11-11 09:00:49 +04:00
|
|
|
&this->GetTarget()->GetPreBuildCommands(),
|
|
|
|
&this->GetTarget()->GetPreLinkCommands(),
|
|
|
|
&this->GetTarget()->GetPostBuildCommands()
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<std::string> preLinkCmdLines, postBuildCmdLines;
|
|
|
|
std::vector<std::string> *cmdLineLists[3] = {
|
|
|
|
&preLinkCmdLines,
|
|
|
|
&preLinkCmdLines,
|
|
|
|
&postBuildCmdLines
|
|
|
|
};
|
|
|
|
|
|
|
|
for (unsigned i = 0; i != 3; ++i) {
|
|
|
|
for (std::vector<cmCustomCommand>::const_iterator
|
|
|
|
ci = cmdLists[i]->begin();
|
|
|
|
ci != cmdLists[i]->end(); ++ci) {
|
2014-03-31 02:25:11 +04:00
|
|
|
cmCustomCommandGenerator ccg(*ci, this->GetConfigName(), mf);
|
2014-03-10 23:47:19 +04:00
|
|
|
this->GetLocalGenerator()->AppendCustomCommandLines(ccg,
|
2011-11-11 09:00:49 +04:00
|
|
|
*cmdLineLists[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have any PRE_LINK commands, we need to go back to HOME_OUTPUT for
|
|
|
|
// the link commands.
|
2012-02-19 06:46:37 +04:00
|
|
|
if (!preLinkCmdLines.empty()) {
|
2012-08-22 14:26:56 +04:00
|
|
|
const std::string homeOutDir = this->GetLocalGenerator()
|
2014-03-31 02:25:11 +04:00
|
|
|
->ConvertToOutputFormat(mf->GetHomeOutputDirectory(),
|
2012-08-22 14:26:56 +04:00
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
preLinkCmdLines.push_back("cd " + homeOutDir);
|
2012-02-19 06:46:37 +04:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
vars["PRE_LINK"] =
|
|
|
|
this->GetLocalGenerator()->BuildCommandLine(preLinkCmdLines);
|
|
|
|
std::string postBuildCmdLine =
|
|
|
|
this->GetLocalGenerator()->BuildCommandLine(postBuildCmdLines);
|
|
|
|
|
|
|
|
cmNinjaVars symlinkVars;
|
|
|
|
if (targetOutput == targetOutputReal) {
|
|
|
|
vars["POST_BUILD"] = postBuildCmdLine;
|
|
|
|
} else {
|
|
|
|
vars["POST_BUILD"] = ":";
|
|
|
|
symlinkVars["POST_BUILD"] = postBuildCmdLine;
|
|
|
|
}
|
|
|
|
|
2012-07-10 11:56:11 +04:00
|
|
|
int linkRuleLength = this->GetGlobalGenerator()->
|
2012-07-02 12:30:29 +04:00
|
|
|
GetRuleCmdLength(this->LanguageLinkerRule());
|
2012-09-27 13:45:25 +04:00
|
|
|
|
2012-09-28 00:29:17 +04:00
|
|
|
int commandLineLengthLimit = 1;
|
|
|
|
const char* forceRspFile = "CMAKE_NINJA_FORCE_RESPONSE_FILE";
|
2014-03-31 02:25:11 +04:00
|
|
|
if (!mf->IsDefinitionSet(forceRspFile) &&
|
2012-09-28 00:29:17 +04:00
|
|
|
cmSystemTools::GetEnv(forceRspFile) == 0) {
|
2012-07-10 11:56:11 +04:00
|
|
|
#ifdef _WIN32
|
2012-09-27 13:45:25 +04:00
|
|
|
commandLineLengthLimit = 8000 - linkRuleLength;
|
2014-03-03 18:47:08 +04:00
|
|
|
#elif defined(__linux) || defined(__APPLE__) || defined(__HAIKU__)
|
2012-09-27 13:45:25 +04:00
|
|
|
// for instance ARG_MAX is 2096152 on Ubuntu or 262144 on Mac
|
|
|
|
commandLineLengthLimit = ((int)sysconf(_SC_ARG_MAX))-linkRuleLength-1000;
|
2012-06-06 00:39:42 +04:00
|
|
|
#else
|
2012-11-07 16:45:30 +04:00
|
|
|
(void)linkRuleLength;
|
2012-09-27 13:45:25 +04:00
|
|
|
commandLineLengthLimit = -1;
|
2012-06-06 00:39:42 +04:00
|
|
|
#endif
|
2012-09-27 13:45:25 +04:00
|
|
|
}
|
2012-06-15 03:45:18 +04:00
|
|
|
|
2013-06-07 22:25:33 +04:00
|
|
|
//Get the global generator as we are going to be call WriteBuild numerous
|
|
|
|
//times in the following section
|
|
|
|
cmGlobalNinjaGenerator* globalGenerator = this->GetGlobalGenerator();
|
|
|
|
|
|
|
|
|
2012-09-26 12:07:25 +04:00
|
|
|
const std::string rspfile = std::string
|
|
|
|
(cmake::GetCMakeFilesDirectoryPostSlash()) +
|
|
|
|
this->GetTarget()->GetName() + ".rsp";
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// Write the build statement for this target.
|
2013-06-07 22:25:33 +04:00
|
|
|
globalGenerator->WriteBuild(this->GetBuildFileStream(),
|
|
|
|
comment.str(),
|
|
|
|
this->LanguageLinkerRule(),
|
|
|
|
outputs,
|
|
|
|
explicitDeps,
|
|
|
|
implicitDeps,
|
|
|
|
emptyDeps,
|
|
|
|
vars,
|
|
|
|
rspfile,
|
|
|
|
commandLineLengthLimit);
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2013-07-17 09:01:50 +04:00
|
|
|
if (targetOutput != targetOutputReal &&
|
|
|
|
!this->GetTarget()->IsFrameworkOnApple()) {
|
2011-11-11 09:00:49 +04:00
|
|
|
if (targetType == cmTarget::EXECUTABLE) {
|
2013-06-07 22:25:33 +04:00
|
|
|
globalGenerator->WriteBuild(this->GetBuildFileStream(),
|
2011-11-11 09:00:49 +04:00
|
|
|
"Create executable symlink " + targetOutput,
|
2013-06-07 22:25:33 +04:00
|
|
|
"CMAKE_SYMLINK_EXECUTABLE",
|
|
|
|
cmNinjaDeps(1, targetOutput),
|
|
|
|
cmNinjaDeps(1, targetOutputReal),
|
|
|
|
emptyDeps,
|
|
|
|
emptyDeps,
|
|
|
|
symlinkVars);
|
2011-11-11 09:00:49 +04:00
|
|
|
} else {
|
2012-07-06 12:16:45 +04:00
|
|
|
cmNinjaDeps symlinks;
|
2012-04-02 14:35:55 +04:00
|
|
|
const std::string soName = this->GetTargetFilePath(this->TargetNameSO);
|
|
|
|
// If one link has to be created.
|
|
|
|
if (targetOutputReal == soName || targetOutput == soName) {
|
|
|
|
symlinkVars["SONAME"] = soName;
|
|
|
|
} else {
|
|
|
|
symlinkVars["SONAME"] = "";
|
2012-07-06 12:16:45 +04:00
|
|
|
symlinks.push_back(soName);
|
2012-04-02 14:35:55 +04:00
|
|
|
}
|
2012-07-06 12:16:45 +04:00
|
|
|
symlinks.push_back(targetOutput);
|
2013-06-07 22:25:33 +04:00
|
|
|
globalGenerator->WriteBuild(this->GetBuildFileStream(),
|
|
|
|
"Create library symlink " + targetOutput,
|
|
|
|
"CMAKE_SYMLINK_LIBRARY",
|
|
|
|
symlinks,
|
|
|
|
cmNinjaDeps(1, targetOutputReal),
|
|
|
|
emptyDeps,
|
|
|
|
emptyDeps,
|
|
|
|
symlinkVars);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-20 01:38:10 +04:00
|
|
|
if (!this->TargetNameImport.empty()) {
|
|
|
|
// Since using multiple outputs would mess up the $out variable, use an
|
|
|
|
// alias for the import library.
|
2013-06-07 22:25:33 +04:00
|
|
|
globalGenerator->WritePhonyBuild(this->GetBuildFileStream(),
|
|
|
|
"Alias for import library.",
|
|
|
|
cmNinjaDeps(1, targetOutputImplib),
|
|
|
|
cmNinjaDeps(1, targetOutputReal));
|
2012-02-20 01:38:10 +04:00
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// Add aliases for the file name and the target name.
|
2013-06-07 22:25:33 +04:00
|
|
|
globalGenerator->AddTargetAlias(this->TargetNameOut,
|
2011-11-11 09:00:49 +04:00
|
|
|
this->GetTarget());
|
2013-06-07 22:25:33 +04:00
|
|
|
globalGenerator->AddTargetAlias(this->GetTargetName(),
|
2011-11-11 09:00:49 +04:00
|
|
|
this->GetTarget());
|
|
|
|
}
|
2012-03-13 18:05:07 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
|
|
|
|
{
|
|
|
|
// Write a phony output that depends on all object files.
|
|
|
|
cmNinjaDeps outputs;
|
|
|
|
this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs);
|
|
|
|
cmNinjaDeps depends = this->GetObjects();
|
2013-06-07 22:25:33 +04:00
|
|
|
this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
|
|
|
|
"Object library "
|
|
|
|
+ this->GetTargetName(),
|
|
|
|
outputs,
|
|
|
|
depends);
|
2012-03-13 18:05:07 +04:00
|
|
|
|
|
|
|
// Add aliases for the target name.
|
|
|
|
this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
|
|
|
|
this->GetTarget());
|
|
|
|
}
|