2011-11-11 05:00:49 +00: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"
|
2016-04-29 13:40:20 +00:00
|
|
|
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmAlgorithms.h"
|
2016-08-23 22:29:15 +00:00
|
|
|
#include "cmCustomCommand.h"
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmCustomCommandGenerator.h"
|
2011-11-11 05:00:49 +00:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmGeneratorTarget.h"
|
|
|
|
#include "cmGlobalNinjaGenerator.h"
|
2016-08-23 22:29:15 +00:00
|
|
|
#include "cmLocalGenerator.h"
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmLocalNinjaGenerator.h"
|
2011-11-11 05:00:49 +00:00
|
|
|
#include "cmMakefile.h"
|
2016-08-23 22:29:15 +00:00
|
|
|
#include "cmNinjaTypes.h"
|
2012-07-07 17:54:16 +00:00
|
|
|
#include "cmOSXBundleGenerator.h"
|
2016-08-23 22:29:15 +00:00
|
|
|
#include "cmOutputConverter.h"
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmSourceFile.h"
|
2016-08-23 22:29:15 +00:00
|
|
|
#include "cmState.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmake.h"
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2012-07-11 06:55:00 +00:00
|
|
|
#include <algorithm>
|
2016-04-29 14:53:13 +00:00
|
|
|
#include <assert.h>
|
2016-08-23 22:29:15 +00:00
|
|
|
#include <iterator>
|
2015-01-14 18:11:44 +00:00
|
|
|
#include <limits>
|
2016-08-23 22:29:15 +00:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stddef.h>
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2012-07-11 08:15:53 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator(
|
|
|
|
cmGeneratorTarget* target)
|
2015-06-06 12:02:24 +00:00
|
|
|
: cmNinjaTargetGenerator(target)
|
2011-11-11 05:00:49 +00:00
|
|
|
, TargetNameOut()
|
|
|
|
, TargetNameSO()
|
|
|
|
, TargetNameReal()
|
|
|
|
, TargetNameImport()
|
|
|
|
, TargetNamePDB()
|
2014-02-04 02:20:56 +00:00
|
|
|
, TargetLinkLanguage("")
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2015-08-04 17:19:49 +00:00
|
|
|
this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName());
|
2016-06-10 16:36:24 +00:00
|
|
|
if (target->GetType() == cmState::EXECUTABLE) {
|
2016-05-16 14:34:04 +00:00
|
|
|
this->GetGeneratorTarget()->GetExecutableNames(
|
|
|
|
this->TargetNameOut, this->TargetNameReal, this->TargetNameImport,
|
|
|
|
this->TargetNamePDB, GetLocalGenerator()->GetConfigName());
|
2016-06-10 16:36:24 +00:00
|
|
|
} else {
|
2016-05-16 14:34:04 +00:00
|
|
|
this->GetGeneratorTarget()->GetLibraryNames(
|
|
|
|
this->TargetNameOut, this->TargetNameSO, this->TargetNameReal,
|
|
|
|
this->TargetNameImport, this->TargetNamePDB,
|
|
|
|
GetLocalGenerator()->GetConfigName());
|
2016-06-10 16:36:24 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
|
|
|
|
if (target->GetType() != cmState::OBJECT_LIBRARY) {
|
2012-03-13 14:05:07 +00:00
|
|
|
// on Windows the output dir is already needed at compile time
|
|
|
|
// ensure the directory exists (OutDir test)
|
2014-10-20 18:31:47 +00:00
|
|
|
EnsureDirectoryExists(target->GetDirectory(this->GetConfigName()));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-07-03 20:22:17 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
this->OSXBundleGenerator =
|
|
|
|
new cmOSXBundleGenerator(target, this->GetConfigName());
|
2012-07-07 17:54:16 +00:00
|
|
|
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator()
|
|
|
|
{
|
2012-07-07 17:54:16 +00:00
|
|
|
delete this->OSXBundleGenerator;
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmNinjaNormalTargetGenerator::Generate()
|
|
|
|
{
|
2014-02-04 02:20:56 +00:00
|
|
|
if (this->TargetLinkLanguage.empty()) {
|
2013-06-21 11:51:58 +00:00
|
|
|
cmSystemTools::Error("CMake can not determine linker language for "
|
|
|
|
"target: ",
|
2015-10-16 18:09:43 +00:00
|
|
|
this->GetGeneratorTarget()->GetName().c_str());
|
2011-11-11 05:00:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the rules for each language.
|
|
|
|
this->WriteLanguagesRules();
|
|
|
|
|
|
|
|
// Write the build statements
|
|
|
|
this->WriteObjectBuildStatements();
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->GetGeneratorTarget()->GetType() == cmState::OBJECT_LIBRARY) {
|
2012-03-13 14:05:07 +00:00
|
|
|
this->WriteObjectLibStatement();
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2012-03-13 14:05:07 +00:00
|
|
|
this->WriteLinkStatement();
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
|
|
|
|
{
|
2012-06-10 18:20:29 +00:00
|
|
|
#ifdef NINJA_GEN_VERBOSE_FILES
|
2011-11-11 05:00:49 +00:00
|
|
|
cmGlobalNinjaGenerator::WriteDivider(this->GetRulesFileStream());
|
|
|
|
this->GetRulesFileStream()
|
|
|
|
<< "# Rules for each languages for "
|
2015-10-07 22:26:50 +00:00
|
|
|
<< cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType())
|
2016-05-16 14:34:04 +00:00
|
|
|
<< " target " << this->GetTargetName() << "\n\n";
|
2012-06-10 18:20:29 +00:00
|
|
|
#endif
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2014-12-23 00:41:17 +00:00
|
|
|
// Write rules for languages compiled in this target.
|
2014-02-10 05:21:34 +00:00
|
|
|
std::set<std::string> languages;
|
2014-12-23 00:41:17 +00:00
|
|
|
std::vector<cmSourceFile*> sourceFiles;
|
2016-05-16 14:34:04 +00:00
|
|
|
this->GetGeneratorTarget()->GetSourceFiles(
|
|
|
|
sourceFiles, this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"));
|
|
|
|
for (std::vector<cmSourceFile*>::const_iterator i = sourceFiles.begin();
|
|
|
|
i != sourceFiles.end(); ++i) {
|
2014-12-23 00:41:17 +00:00
|
|
|
const std::string& lang = (*i)->GetLanguage();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!lang.empty()) {
|
2014-12-23 00:41:17 +00:00
|
|
|
languages.insert(lang);
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
for (std::set<std::string>::const_iterator l = languages.begin();
|
|
|
|
l != languages.end(); ++l) {
|
2011-11-11 05:00:49 +00:00
|
|
|
this->WriteLanguageRules(*l);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* cmNinjaNormalTargetGenerator::GetVisibleTypeName() const
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2015-10-14 21:14:43 +00:00
|
|
|
switch (this->GetGeneratorTarget()->GetType()) {
|
2015-10-07 22:21:51 +00:00
|
|
|
case cmState::STATIC_LIBRARY:
|
2011-11-11 05:00:49 +00:00
|
|
|
return "static library";
|
2015-10-07 22:21:51 +00:00
|
|
|
case cmState::SHARED_LIBRARY:
|
2011-11-11 05:00:49 +00:00
|
|
|
return "shared library";
|
2015-10-07 22:21:51 +00:00
|
|
|
case cmState::MODULE_LIBRARY:
|
2016-06-10 16:36:24 +00:00
|
|
|
if (this->GetGeneratorTarget()->IsCFBundleOnApple()) {
|
2012-07-11 10:58:01 +00:00
|
|
|
return "CFBundle shared module";
|
2016-06-10 16:36:24 +00:00
|
|
|
} else {
|
2012-07-11 10:58:01 +00:00
|
|
|
return "shared module";
|
2016-06-10 16:36:24 +00:00
|
|
|
}
|
2015-10-07 22:21:51 +00:00
|
|
|
case cmState::EXECUTABLE:
|
2011-11-11 05:00:49 +00:00
|
|
|
return "executable";
|
|
|
|
default:
|
2016-06-27 20:44:16 +00:00
|
|
|
return CM_NULLPTR;
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string cmNinjaNormalTargetGenerator::LanguageLinkerRule() const
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
return this->TargetLinkLanguage + "_" +
|
|
|
|
cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) +
|
|
|
|
"_LINKER__" + cmGlobalNinjaGenerator::EncodeRuleName(
|
|
|
|
this->GetGeneratorTarget()->GetName());
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 14:15:29 +00:00
|
|
|
struct cmNinjaRemoveNoOpCommands
|
|
|
|
{
|
|
|
|
bool operator()(std::string const& cmd)
|
|
|
|
{
|
|
|
|
return cmd.empty() || cmd[0] == ':';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
cmState::TargetType targetType = this->GetGeneratorTarget()->GetType();
|
2011-11-11 05:00:49 +00:00
|
|
|
std::string ruleName = this->LanguageLinkerRule();
|
|
|
|
|
2012-06-05 20:39:42 +00:00
|
|
|
// Select whether to use a response file for objects.
|
|
|
|
std::string rspfile;
|
2012-07-10 07:56:11 +00:00
|
|
|
std::string rspcontent;
|
2011-11-11 05:00:49 +00:00
|
|
|
|
|
|
|
if (!this->GetGlobalGenerator()->HasRule(ruleName)) {
|
|
|
|
cmLocalGenerator::RuleVariables vars;
|
|
|
|
vars.RuleLauncher = "RULE_LAUNCH_LINK";
|
2015-10-09 20:19:57 +00:00
|
|
|
vars.CMTarget = this->GetGeneratorTarget();
|
2014-02-04 02:20:56 +00:00
|
|
|
vars.Language = this->TargetLinkLanguage.c_str();
|
2012-06-05 20:39:42 +00:00
|
|
|
|
|
|
|
std::string responseFlag;
|
|
|
|
if (!useResponseFile) {
|
|
|
|
vars.Objects = "$in";
|
2012-09-27 09:45:25 +00:00
|
|
|
vars.LinkLibraries = "$LINK_PATH $LINK_LIBRARIES";
|
2012-06-05 20:39:42 +00:00
|
|
|
} else {
|
2016-05-16 14:34:04 +00:00
|
|
|
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);
|
|
|
|
if (flag) {
|
|
|
|
responseFlag = flag;
|
|
|
|
} else {
|
|
|
|
responseFlag = "@";
|
|
|
|
}
|
|
|
|
rspfile = "$RSP_FILE";
|
|
|
|
responseFlag += rspfile;
|
|
|
|
|
|
|
|
// build response file content
|
|
|
|
if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
|
|
|
|
rspcontent = "$in";
|
|
|
|
} else {
|
|
|
|
rspcontent = "$in_newline";
|
|
|
|
}
|
|
|
|
rspcontent += " $LINK_PATH $LINK_LIBRARIES";
|
|
|
|
vars.Objects = responseFlag.c_str();
|
|
|
|
vars.LinkLibraries = "";
|
2012-06-05 20:39:42 +00:00
|
|
|
}
|
2012-06-12 02:17:55 +00:00
|
|
|
|
|
|
|
vars.ObjectDir = "$OBJECT_DIR";
|
2012-07-17 09:21:03 +00:00
|
|
|
|
2014-11-13 20:29:51 +00:00
|
|
|
vars.Target = "$TARGET_FILE";
|
2012-07-17 09:21:03 +00:00
|
|
|
|
2012-04-22 13:42:55 +00:00
|
|
|
vars.SONameFlag = "$SONAME_FLAG";
|
2011-11-11 05:00:49 +00:00
|
|
|
vars.TargetSOName = "$SONAME";
|
|
|
|
vars.TargetInstallNameDir = "$INSTALLNAME_DIR";
|
2012-02-21 20:18:05 +00:00
|
|
|
vars.TargetPDB = "$TARGET_PDB";
|
2011-11-11 05:00:49 +00:00
|
|
|
|
|
|
|
// Setup the target version.
|
|
|
|
std::string targetVersionMajor;
|
|
|
|
std::string targetVersionMinor;
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
std::ostringstream majorStream;
|
|
|
|
std::ostringstream minorStream;
|
|
|
|
int major;
|
|
|
|
int minor;
|
|
|
|
this->GetGeneratorTarget()->GetTargetVersion(major, minor);
|
|
|
|
majorStream << major;
|
|
|
|
minorStream << minor;
|
|
|
|
targetVersionMajor = majorStream.str();
|
|
|
|
targetVersionMinor = minorStream.str();
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
vars.TargetVersionMajor = targetVersionMajor.c_str();
|
|
|
|
vars.TargetVersionMinor = targetVersionMinor.c_str();
|
|
|
|
|
2013-07-12 13:44:38 +00:00
|
|
|
vars.Flags = "$FLAGS";
|
2011-11-11 05:00:49 +00:00
|
|
|
vars.LinkFlags = "$LINK_FLAGS";
|
2015-09-16 14:24:16 +00:00
|
|
|
vars.Manifests = "$MANIFESTS";
|
2011-11-11 05:00:49 +00:00
|
|
|
|
|
|
|
std::string langFlags;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (targetType != cmState::EXECUTABLE) {
|
2014-04-13 12:29:20 +00:00
|
|
|
langFlags += "$LANGUAGE_COMPILE_FLAGS $ARCH_FLAGS";
|
2012-04-30 03:25:37 +00:00
|
|
|
vars.LanguageCompileFlags = langFlags.c_str();
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2012-06-05 20:39:42 +00:00
|
|
|
// Rule for linking library/executable.
|
2011-11-11 05:00:49 +00:00
|
|
|
std::vector<std::string> linkCmds = this->ComputeLinkCmd();
|
2016-05-16 14:34:04 +00:00
|
|
|
for (std::vector<std::string>::iterator i = linkCmds.begin();
|
|
|
|
i != linkCmds.end(); ++i) {
|
2011-11-11 05:00:49 +00:00
|
|
|
this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2016-06-08 14:15:29 +00:00
|
|
|
{
|
|
|
|
// If there is no ranlib the command will be ":". Skip it.
|
|
|
|
std::vector<std::string>::iterator newEnd = std::remove_if(
|
|
|
|
linkCmds.begin(), linkCmds.end(), cmNinjaRemoveNoOpCommands());
|
|
|
|
linkCmds.erase(newEnd, linkCmds.end());
|
|
|
|
}
|
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
linkCmds.insert(linkCmds.begin(), "$PRE_LINK");
|
|
|
|
linkCmds.push_back("$POST_BUILD");
|
|
|
|
std::string linkCmd =
|
|
|
|
this->GetLocalGenerator()->BuildCommandLine(linkCmds);
|
|
|
|
|
2012-06-05 20:39:42 +00:00
|
|
|
// Write the linker rule with response file if needed.
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream comment;
|
2011-11-11 05:00:49 +00:00
|
|
|
comment << "Rule for linking " << this->TargetLinkLanguage << " "
|
|
|
|
<< this->GetVisibleTypeName() << ".";
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream description;
|
2011-11-11 05:00:49 +00:00
|
|
|
description << "Linking " << this->TargetLinkLanguage << " "
|
2014-11-13 20:29:51 +00:00
|
|
|
<< this->GetVisibleTypeName() << " $TARGET_FILE";
|
2016-05-16 14:34:04 +00:00
|
|
|
this->GetGlobalGenerator()->AddRule(ruleName, linkCmd, description.str(),
|
2012-06-05 20:39:42 +00:00
|
|
|
comment.str(),
|
|
|
|
/*depfile*/ "",
|
2016-05-16 14:34:04 +00:00
|
|
|
/*deptype*/ "", rspfile, rspcontent,
|
2014-11-13 23:54:52 +00:00
|
|
|
/*restat*/ "$RESTAT",
|
2013-10-18 10:59:47 +00:00
|
|
|
/*generator*/ false);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 05:01:50 +00:00
|
|
|
if (this->TargetNameOut != this->TargetNameReal &&
|
2016-05-16 14:34:04 +00:00
|
|
|
!this->GetGeneratorTarget()->IsFrameworkOnApple()) {
|
2011-11-11 05:00:49 +00:00
|
|
|
std::string cmakeCommand =
|
2012-02-19 03:07:09 +00:00
|
|
|
this->GetLocalGenerator()->ConvertToOutputFormat(
|
2016-05-19 21:11:40 +00:00
|
|
|
cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
|
2016-06-10 16:36:24 +00:00
|
|
|
if (targetType == cmState::EXECUTABLE) {
|
2016-05-16 14:34:04 +00:00
|
|
|
this->GetGlobalGenerator()->AddRule(
|
|
|
|
"CMAKE_SYMLINK_EXECUTABLE",
|
|
|
|
cmakeCommand + " -E cmake_symlink_executable"
|
|
|
|
" $in $out && $POST_BUILD",
|
|
|
|
"Creating executable symlink $out", "Rule for creating "
|
|
|
|
"executable symlink.",
|
|
|
|
/*depfile*/ "",
|
|
|
|
/*deptype*/ "",
|
|
|
|
/*rspfile*/ "",
|
|
|
|
/*rspcontent*/ "",
|
|
|
|
/*restat*/ "",
|
|
|
|
/*generator*/ false);
|
2016-06-10 16:36:24 +00:00
|
|
|
} else {
|
2016-05-16 14:34:04 +00:00
|
|
|
this->GetGlobalGenerator()->AddRule(
|
|
|
|
"CMAKE_SYMLINK_LIBRARY",
|
|
|
|
cmakeCommand + " -E cmake_symlink_library"
|
|
|
|
" $in $SONAME $out && $POST_BUILD",
|
|
|
|
"Creating library symlink $out", "Rule for creating "
|
|
|
|
"library symlink.",
|
|
|
|
/*depfile*/ "",
|
|
|
|
/*deptype*/ "",
|
|
|
|
/*rspfile*/ "",
|
|
|
|
/*rspcontent*/ "",
|
|
|
|
/*restat*/ "",
|
|
|
|
/*generator*/ false);
|
2016-06-10 16:36:24 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2012-02-27 04:05:31 +00:00
|
|
|
std::vector<std::string> linkCmds;
|
2014-03-30 22:25:11 +00:00
|
|
|
cmMakefile* mf = this->GetMakefile();
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string linkCmdVar = this->GetGeneratorTarget()->GetCreateRuleVariable(
|
|
|
|
this->TargetLinkLanguage, this->GetConfigName());
|
|
|
|
const char* linkCmd = mf->GetDefinition(linkCmdVar);
|
|
|
|
if (linkCmd) {
|
|
|
|
cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
|
2016-06-02 22:08:30 +00:00
|
|
|
if (this->GetGeneratorTarget()->GetProperty("LINK_WHAT_YOU_USE")) {
|
|
|
|
std::string cmakeCommand =
|
|
|
|
this->GetLocalGenerator()->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
|
|
|
|
cmakeCommand += " -E __run_iwyu --lwyu=";
|
|
|
|
cmGeneratorTarget& gt = *this->GetGeneratorTarget();
|
|
|
|
const std::string cfgName = this->GetConfigName();
|
|
|
|
std::string targetOutput = ConvertToNinjaPath(gt.GetFullPath(cfgName));
|
|
|
|
std::string targetOutputReal =
|
|
|
|
this->ConvertToNinjaPath(gt.GetFullPath(cfgName,
|
|
|
|
/*implib=*/false,
|
|
|
|
/*realpath=*/true));
|
|
|
|
cmakeCommand += targetOutputReal;
|
|
|
|
cmakeCommand += " || true";
|
|
|
|
linkCmds.push_back(cmakeCommand);
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
return linkCmds;
|
2014-03-30 22:25:11 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-14 21:14:43 +00:00
|
|
|
switch (this->GetGeneratorTarget()->GetType()) {
|
2015-10-07 22:21:51 +00:00
|
|
|
case cmState::STATIC_LIBRARY: {
|
2011-11-11 05:00:49 +00:00
|
|
|
// We have archive link commands set. First, delete the existing archive.
|
2014-03-30 22:25:11 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string cmakeCommand =
|
|
|
|
this->GetLocalGenerator()->ConvertToOutputFormat(
|
2016-05-19 21:11:40 +00:00
|
|
|
cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
|
2016-05-16 14:34:04 +00:00
|
|
|
linkCmds.push_back(cmakeCommand + " -E remove $TARGET_FILE");
|
2014-03-30 22:25:11 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
// TODO: Use ARCHIVE_APPEND for archives over a certain size.
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string linkCmdVar = "CMAKE_";
|
|
|
|
linkCmdVar += this->TargetLinkLanguage;
|
|
|
|
linkCmdVar += "_ARCHIVE_CREATE";
|
|
|
|
const char* linkCmd = mf->GetRequiredDefinition(linkCmdVar);
|
|
|
|
cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string linkCmdVar = "CMAKE_";
|
|
|
|
linkCmdVar += this->TargetLinkLanguage;
|
|
|
|
linkCmdVar += "_ARCHIVE_FINISH";
|
|
|
|
const char* linkCmd = mf->GetRequiredDefinition(linkCmdVar);
|
|
|
|
cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
return linkCmds;
|
|
|
|
}
|
2015-10-07 22:21:51 +00:00
|
|
|
case cmState::SHARED_LIBRARY:
|
|
|
|
case cmState::MODULE_LIBRARY:
|
|
|
|
case cmState::EXECUTABLE:
|
2014-03-30 22:25:11 +00:00
|
|
|
break;
|
2011-11-11 05:00:49 +00:00
|
|
|
default:
|
|
|
|
assert(0 && "Unexpected target type");
|
|
|
|
}
|
2012-02-05 01:48:08 +00:00
|
|
|
return std::vector<std::string>();
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-13 12:06:41 +00:00
|
|
|
static int calculateCommandLineLengthLimit(int linkRuleLength)
|
2011-11-11 05:00:49 +00:00
|
|
|
{
|
2015-01-14 18:11:44 +00:00
|
|
|
static int const limits[] = {
|
2014-04-13 12:06:41 +00:00
|
|
|
#ifdef _WIN32
|
2015-01-14 18:11:44 +00:00
|
|
|
8000,
|
2014-04-13 12:06:41 +00:00
|
|
|
#endif
|
2016-07-15 10:46:53 +00:00
|
|
|
#if defined(_SC_ARG_MAX)
|
2015-01-14 18:11:44 +00:00
|
|
|
// for instance ARG_MAX is 2096152 on Ubuntu or 262144 on Mac
|
|
|
|
((int)sysconf(_SC_ARG_MAX)) - 1000,
|
|
|
|
#endif
|
|
|
|
#if defined(__linux)
|
|
|
|
// #define MAX_ARG_STRLEN (PAGE_SIZE * 32) in Linux's binfmts.h
|
|
|
|
((int)sysconf(_SC_PAGESIZE) * 32) - 1000,
|
|
|
|
#endif
|
|
|
|
std::numeric_limits<int>::max()
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t const arrSz = cmArraySize(limits);
|
|
|
|
int const sz = *std::min_element(limits, limits + arrSz);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (sz == std::numeric_limits<int>::max()) {
|
2016-07-15 13:37:03 +00:00
|
|
|
return 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-01-14 18:11:44 +00:00
|
|
|
|
|
|
|
return sz - linkRuleLength;
|
2014-04-13 12:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmNinjaNormalTargetGenerator::WriteLinkStatement()
|
|
|
|
{
|
2012-10-06 16:30:43 +00:00
|
|
|
cmGeneratorTarget& gt = *this->GetGeneratorTarget();
|
2014-04-13 12:06:41 +00:00
|
|
|
const std::string cfgName = this->GetConfigName();
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string targetOutput = ConvertToNinjaPath(gt.GetFullPath(cfgName));
|
|
|
|
std::string targetOutputReal =
|
|
|
|
ConvertToNinjaPath(gt.GetFullPath(cfgName,
|
2014-04-13 12:06:41 +00:00
|
|
|
/*implib=*/false,
|
2014-10-15 12:54:05 +00:00
|
|
|
/*realpath=*/true));
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string targetOutputImplib =
|
|
|
|
ConvertToNinjaPath(gt.GetFullPath(cfgName,
|
|
|
|
/*implib=*/true));
|
2012-07-03 20:22:17 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (gt.IsAppBundleOnApple()) {
|
2012-07-03 20:22:17 +00:00
|
|
|
// Create the app bundle
|
2014-10-20 18:31:47 +00:00
|
|
|
std::string outpath = gt.GetDirectory(cfgName);
|
2012-07-07 17:54:16 +00:00
|
|
|
this->OSXBundleGenerator->CreateAppBundle(this->TargetNameOut, outpath);
|
2012-07-03 20:22:17 +00:00
|
|
|
|
|
|
|
// Calculate the output path
|
2013-05-06 02:19:05 +00:00
|
|
|
targetOutput = outpath;
|
|
|
|
targetOutput += "/";
|
|
|
|
targetOutput += this->TargetNameOut;
|
2014-10-15 12:54:05 +00:00
|
|
|
targetOutput = this->ConvertToNinjaPath(targetOutput);
|
2013-05-06 02:19:05 +00:00
|
|
|
targetOutputReal = outpath;
|
|
|
|
targetOutputReal += "/";
|
|
|
|
targetOutputReal += this->TargetNameReal;
|
2014-10-15 12:54:05 +00:00
|
|
|
targetOutputReal = this->ConvertToNinjaPath(targetOutputReal);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (gt.IsFrameworkOnApple()) {
|
2012-07-05 16:31:17 +00:00
|
|
|
// Create the library framework.
|
2014-04-13 12:06:41 +00:00
|
|
|
this->OSXBundleGenerator->CreateFramework(this->TargetNameOut,
|
2014-10-20 18:31:47 +00:00
|
|
|
gt.GetDirectory(cfgName));
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (gt.IsCFBundleOnApple()) {
|
2012-07-16 14:00:40 +00:00
|
|
|
// Create the core foundation bundle.
|
2014-04-13 12:06:41 +00:00
|
|
|
this->OSXBundleGenerator->CreateCFBundle(this->TargetNameOut,
|
2014-10-20 18:31:47 +00:00
|
|
|
gt.GetDirectory(cfgName));
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-07-03 20:22:17 +00:00
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
// Write comments.
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
|
2015-10-18 21:13:50 +00:00
|
|
|
const cmState::TargetType targetType = gt.GetType();
|
2016-05-16 14:34:04 +00:00
|
|
|
this->GetBuildFileStream() << "# Link build statements for "
|
|
|
|
<< cmState::GetTargetTypeName(targetType)
|
|
|
|
<< " target " << this->GetTargetName() << "\n\n";
|
2011-11-11 05:00:49 +00:00
|
|
|
|
|
|
|
cmNinjaDeps emptyDeps;
|
|
|
|
cmNinjaVars vars;
|
|
|
|
|
|
|
|
// Compute the comment.
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream comment;
|
2016-05-16 14:34:04 +00:00
|
|
|
comment << "Link the " << this->GetVisibleTypeName() << " "
|
|
|
|
<< targetOutputReal;
|
2011-11-11 05:00:49 +00:00
|
|
|
|
|
|
|
// Compute outputs.
|
|
|
|
cmNinjaDeps outputs;
|
|
|
|
outputs.push_back(targetOutputReal);
|
|
|
|
|
|
|
|
// Compute specific libraries to link with.
|
2012-07-11 06:55:00 +00:00
|
|
|
cmNinjaDeps explicitDeps = this->GetObjects();
|
|
|
|
cmNinjaDeps implicitDeps = this->ComputeLinkDeps();
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2014-03-30 22:25:11 +00:00
|
|
|
cmMakefile* mf = this->GetMakefile();
|
|
|
|
|
2012-09-26 12:38:15 +00:00
|
|
|
std::string frameworkPath;
|
|
|
|
std::string linkPath;
|
2014-04-13 12:06:41 +00:00
|
|
|
cmGeneratorTarget& genTarget = *this->GetGeneratorTarget();
|
2014-04-04 21:06:13 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string createRule = genTarget.GetCreateRuleVariable(
|
|
|
|
this->TargetLinkLanguage, this->GetConfigName());
|
|
|
|
bool useWatcomQuote = mf->IsOn(createRule + "_USE_WATCOM_QUOTE");
|
2014-04-13 12:06:41 +00:00
|
|
|
cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator();
|
2014-11-13 20:29:51 +00:00
|
|
|
|
|
|
|
vars["TARGET_FILE"] =
|
2016-05-19 21:11:40 +00:00
|
|
|
localGen.ConvertToOutputFormat(targetOutputReal, cmOutputConverter::SHELL);
|
2014-11-13 20:29:51 +00:00
|
|
|
|
2016-06-07 14:30:58 +00:00
|
|
|
localGen.GetTargetFlags(this->GetConfigName(), vars["LINK_LIBRARIES"],
|
|
|
|
vars["FLAGS"], vars["LINK_FLAGS"], frameworkPath,
|
|
|
|
linkPath, &genTarget, useWatcomQuote);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") &&
|
2016-07-10 17:24:43 +00:00
|
|
|
(gt.GetType() == cmState::SHARED_LIBRARY ||
|
|
|
|
gt.IsExecutableWithExports())) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) {
|
|
|
|
std::string name_of_def_file = gt.GetSupportDirectory();
|
2015-10-18 21:13:50 +00:00
|
|
|
name_of_def_file += "/" + gt.GetName();
|
2015-06-19 20:12:43 +00:00
|
|
|
name_of_def_file += ".def ";
|
|
|
|
vars["LINK_FLAGS"] += " /DEF:";
|
2016-05-16 14:34:04 +00:00
|
|
|
vars["LINK_FLAGS"] += this->GetLocalGenerator()->ConvertToOutputFormat(
|
2016-05-26 20:52:22 +00:00
|
|
|
name_of_def_file, cmOutputConverter::SHELL);
|
2015-06-19 20:12:43 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2016-02-20 19:35:18 +00:00
|
|
|
// Add OS X version flags, if any.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
|
|
|
|
this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY) {
|
2016-02-20 19:35:18 +00:00
|
|
|
this->AppendOSXVerFlag(vars["LINK_FLAGS"], this->TargetLinkLanguage,
|
|
|
|
"COMPATIBILITY", true);
|
|
|
|
this->AppendOSXVerFlag(vars["LINK_FLAGS"], this->TargetLinkLanguage,
|
|
|
|
"CURRENT", false);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2016-02-20 19:35:18 +00:00
|
|
|
|
2015-10-18 21:13:50 +00:00
|
|
|
this->addPoolNinjaVariable("JOB_POOL_LINK", >, vars);
|
2013-11-23 09:49:36 +00:00
|
|
|
|
2012-03-10 11:19:18 +00:00
|
|
|
this->AddModuleDefinitionFlag(vars["LINK_FLAGS"]);
|
2016-05-16 14:34:04 +00:00
|
|
|
vars["LINK_FLAGS"] =
|
|
|
|
cmGlobalNinjaGenerator::EncodeLiteral(vars["LINK_FLAGS"]);
|
2012-11-20 20:59:40 +00:00
|
|
|
|
2015-09-16 14:24:16 +00:00
|
|
|
vars["MANIFESTS"] = this->GetManifests();
|
|
|
|
|
2012-09-27 09:45:25 +00:00
|
|
|
vars["LINK_PATH"] = frameworkPath + linkPath;
|
2016-06-02 22:08:30 +00:00
|
|
|
std::string lwyuFlags;
|
|
|
|
if (genTarget.GetProperty("LINK_WHAT_YOU_USE")) {
|
|
|
|
lwyuFlags = " -Wl,--no-as-needed";
|
|
|
|
}
|
2012-03-10 11:19:18 +00:00
|
|
|
|
2011-11-11 05:00:49 +00: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.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (targetType == cmState::EXECUTABLE) {
|
2014-04-13 12:29:20 +00:00
|
|
|
std::string t = vars["FLAGS"];
|
|
|
|
localGen.AddArchitectureFlags(t, &genTarget, TargetLinkLanguage, cfgName);
|
2016-06-02 22:08:30 +00:00
|
|
|
t += lwyuFlags;
|
2014-04-13 12:29:20 +00:00
|
|
|
vars["FLAGS"] = t;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2014-04-13 12:29:20 +00:00
|
|
|
std::string t = vars["ARCH_FLAGS"];
|
|
|
|
localGen.AddArchitectureFlags(t, &genTarget, TargetLinkLanguage, cfgName);
|
|
|
|
vars["ARCH_FLAGS"] = t;
|
|
|
|
t = "";
|
2016-06-02 22:08:30 +00:00
|
|
|
t += lwyuFlags;
|
2014-04-13 12:29:20 +00:00
|
|
|
localGen.AddLanguageFlags(t, TargetLinkLanguage, cfgName);
|
|
|
|
vars["LANGUAGE_COMPILE_FLAGS"] = t;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (this->GetGeneratorTarget()->HasSOName(cfgName)) {
|
2014-04-13 12:06:41 +00:00
|
|
|
vars["SONAME_FLAG"] = mf->GetSONameFlag(this->TargetLinkLanguage);
|
2012-04-22 13:42:55 +00:00
|
|
|
vars["SONAME"] = this->TargetNameSO;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (targetType == cmState::SHARED_LIBRARY) {
|
2015-08-04 17:19:47 +00:00
|
|
|
std::string install_dir =
|
2016-05-16 14:34:04 +00:00
|
|
|
this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(cfgName);
|
|
|
|
if (!install_dir.empty()) {
|
|
|
|
vars["INSTALLNAME_DIR"] = localGen.Convert(
|
2016-05-19 21:11:40 +00:00
|
|
|
install_dir, cmOutputConverter::NONE, cmOutputConverter::SHELL);
|
2012-04-22 13:42:55 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2015-07-28 12:02:47 +00:00
|
|
|
cmNinjaDeps byproducts;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->TargetNameImport.empty()) {
|
2014-04-13 12:06:41 +00:00
|
|
|
const std::string impLibPath = localGen.ConvertToOutputFormat(
|
2016-05-19 21:11:40 +00:00
|
|
|
targetOutputImplib, cmOutputConverter::SHELL);
|
2012-08-22 10:26:56 +00:00
|
|
|
vars["TARGET_IMPLIB"] = impLibPath;
|
|
|
|
EnsureParentDirectoryExists(impLibPath);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (genTarget.HasImportLibrary()) {
|
2015-07-28 12:02:47 +00:00
|
|
|
byproducts.push_back(targetOutputImplib);
|
2014-04-13 12:06:41 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-02-19 21:38:10 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->SetMsvcTargetPdbVariable(vars)) {
|
2012-07-16 12:16:43 +00: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 08:50:57 +00:00
|
|
|
std::string prefix;
|
2012-07-17 09:21:03 +00:00
|
|
|
std::string base;
|
|
|
|
std::string suffix;
|
2015-08-04 17:19:47 +00:00
|
|
|
this->GetGeneratorTarget()->GetFullNameComponents(prefix, base, suffix);
|
2012-07-17 09:45:19 +00:00
|
|
|
std::string dbg_suffix = ".dbg";
|
|
|
|
// TODO: Where to document?
|
2016-05-16 14:34:04 +00:00
|
|
|
if (mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX")) {
|
2012-07-17 09:45:19 +00:00
|
|
|
dbg_suffix = mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX");
|
2012-07-16 12:16:43 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
vars["TARGET_PDB"] = base + suffix + dbg_suffix;
|
|
|
|
}
|
2012-06-12 02:17:55 +00:00
|
|
|
|
2015-10-09 22:29:47 +00:00
|
|
|
const std::string objPath = GetGeneratorTarget()->GetSupportDirectory();
|
2016-05-16 14:34:04 +00:00
|
|
|
vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
|
2016-05-19 21:11:40 +00:00
|
|
|
this->ConvertToNinjaPath(objPath), cmOutputConverter::SHELL);
|
2015-09-15 19:57:19 +00:00
|
|
|
EnsureDirectoryExists(objPath);
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
|
2012-11-07 16:13:09 +00:00
|
|
|
// ar.exe can't handle backslashes in rsp files (implicitly used by gcc)
|
2012-07-11 06:55:00 +00:00
|
|
|
std::string& linkLibraries = vars["LINK_LIBRARIES"];
|
|
|
|
std::replace(linkLibraries.begin(), linkLibraries.end(), '\\', '/');
|
2014-04-13 09:21:58 +00:00
|
|
|
std::string& link_path = vars["LINK_PATH"];
|
|
|
|
std::replace(link_path.begin(), link_path.end(), '\\', '/');
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-02-21 20:18:05 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
const std::vector<cmCustomCommand>* cmdLists[3] = {
|
|
|
|
>.GetPreBuildCommands(), >.GetPreLinkCommands(),
|
2015-10-22 22:42:58 +00:00
|
|
|
>.GetPostBuildCommands()
|
2011-11-11 05:00:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<std::string> preLinkCmdLines, postBuildCmdLines;
|
2016-05-16 14:34:04 +00:00
|
|
|
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) {
|
2015-07-25 15:52:10 +00:00
|
|
|
cmCustomCommandGenerator ccg(*ci, cfgName, this->GetLocalGenerator());
|
2014-04-13 12:06:41 +00:00
|
|
|
localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]);
|
2014-11-13 23:54:52 +00:00
|
|
|
std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
|
|
|
|
std::transform(ccByproducts.begin(), ccByproducts.end(),
|
|
|
|
std::back_inserter(byproducts), MapToNinjaPath());
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2015-06-19 20:12:43 +00:00
|
|
|
// maybe create .def file from list of objects
|
2016-07-10 17:24:43 +00:00
|
|
|
if ((gt.GetType() == cmState::SHARED_LIBRARY ||
|
|
|
|
gt.IsExecutableWithExports()) &&
|
2016-05-16 14:34:04 +00:00
|
|
|
this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) {
|
|
|
|
if (gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) {
|
2015-06-19 20:12:43 +00:00
|
|
|
std::string cmakeCommand =
|
2016-05-16 14:34:04 +00:00
|
|
|
this->GetLocalGenerator()->ConvertToOutputFormat(
|
2016-05-19 21:11:40 +00:00
|
|
|
cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string name_of_def_file = gt.GetSupportDirectory();
|
2015-10-18 21:13:50 +00:00
|
|
|
name_of_def_file += "/" + gt.GetName();
|
2015-06-19 20:12:43 +00:00
|
|
|
name_of_def_file += ".def";
|
|
|
|
std::string cmd = cmakeCommand;
|
|
|
|
cmd += " -E __create_def ";
|
2016-05-16 14:34:04 +00:00
|
|
|
cmd += this->GetLocalGenerator()->ConvertToOutputFormat(
|
2016-05-26 20:52:22 +00:00
|
|
|
name_of_def_file, cmOutputConverter::SHELL);
|
2015-06-19 20:12:43 +00:00
|
|
|
cmd += " ";
|
|
|
|
cmNinjaDeps objs = this->GetObjects();
|
|
|
|
std::string obj_list_file = name_of_def_file;
|
|
|
|
obj_list_file += ".objs";
|
2016-05-16 14:34:04 +00:00
|
|
|
cmd += this->GetLocalGenerator()->ConvertToOutputFormat(
|
2016-05-26 20:52:22 +00:00
|
|
|
obj_list_file, cmOutputConverter::SHELL);
|
2015-06-19 20:12:43 +00:00
|
|
|
preLinkCmdLines.push_back(cmd);
|
|
|
|
// create a list of obj files for the -E __create_def to read
|
|
|
|
cmGeneratedFileStream fout(obj_list_file.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
for (cmNinjaDeps::iterator i = objs.begin(); i != objs.end(); ++i) {
|
|
|
|
if (cmHasLiteralSuffix(*i, ".obj")) {
|
2015-06-19 20:12:43 +00:00
|
|
|
fout << *i << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
// If we have any PRE_LINK commands, we need to go back to HOME_OUTPUT for
|
|
|
|
// the link commands.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!preLinkCmdLines.empty()) {
|
2014-04-13 12:06:41 +00:00
|
|
|
const std::string homeOutDir = localGen.ConvertToOutputFormat(
|
2016-05-19 21:11:40 +00:00
|
|
|
localGen.GetBinaryDirectory(), cmOutputConverter::SHELL);
|
2012-08-22 10:26:56 +00:00
|
|
|
preLinkCmdLines.push_back("cd " + homeOutDir);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-11-11 05:00:49 +00:00
|
|
|
|
2014-04-13 12:06:41 +00:00
|
|
|
vars["PRE_LINK"] = localGen.BuildCommandLine(preLinkCmdLines);
|
|
|
|
std::string postBuildCmdLine = localGen.BuildCommandLine(postBuildCmdLines);
|
2011-11-11 05:00:49 +00:00
|
|
|
|
|
|
|
cmNinjaVars symlinkVars;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (targetOutput == targetOutputReal) {
|
2011-11-11 05:00:49 +00:00
|
|
|
vars["POST_BUILD"] = postBuildCmdLine;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2011-11-11 05:00:49 +00:00
|
|
|
vars["POST_BUILD"] = ":";
|
|
|
|
symlinkVars["POST_BUILD"] = postBuildCmdLine;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-04-13 12:06:41 +00:00
|
|
|
cmGlobalNinjaGenerator& globalGen = *this->GetGlobalGenerator();
|
2012-09-27 09:45:25 +00:00
|
|
|
|
2016-04-06 10:55:15 +00:00
|
|
|
int commandLineLengthLimit = -1;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->ForceResponseFile()) {
|
2014-04-13 12:06:41 +00:00
|
|
|
commandLineLengthLimit = calculateCommandLineLengthLimit(
|
2016-05-16 14:34:04 +00:00
|
|
|
globalGen.GetRuleCmdLength(this->LanguageLinkerRule()));
|
|
|
|
}
|
2013-06-07 18:25:33 +00:00
|
|
|
|
2014-04-13 12:06:41 +00:00
|
|
|
const std::string rspfile =
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string(cmake::GetCMakeFilesDirectoryPostSlash()) + gt.GetName() +
|
|
|
|
".rsp";
|
2012-09-26 08:07:25 +00:00
|
|
|
|
2014-07-01 14:14:27 +00:00
|
|
|
// Gather order-only dependencies.
|
|
|
|
cmNinjaDeps orderOnlyDeps;
|
2015-10-18 21:13:50 +00:00
|
|
|
this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(),
|
2016-05-16 14:34:04 +00:00
|
|
|
orderOnlyDeps);
|
2014-07-01 14:14:27 +00:00
|
|
|
|
2014-11-13 23:54:52 +00:00
|
|
|
// Ninja should restat after linking if and only if there are byproducts.
|
2016-05-16 14:34:04 +00:00
|
|
|
vars["RESTAT"] = byproducts.empty() ? "" : "1";
|
2014-11-13 23:54:52 +00:00
|
|
|
|
|
|
|
for (cmNinjaDeps::const_iterator oi = byproducts.begin(),
|
2016-05-16 14:34:04 +00:00
|
|
|
oe = byproducts.end();
|
|
|
|
oi != oe; ++oi) {
|
2014-11-13 23:54:52 +00:00
|
|
|
this->GetGlobalGenerator()->SeenCustomCommandOutput(*oi);
|
|
|
|
outputs.push_back(*oi);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2014-11-13 23:54:52 +00:00
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
// Write the build statement for this target.
|
2015-05-18 17:31:11 +00:00
|
|
|
bool usedResponseFile = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
globalGen.WriteBuild(this->GetBuildFileStream(), comment.str(),
|
|
|
|
this->LanguageLinkerRule(), outputs, explicitDeps,
|
|
|
|
implicitDeps, orderOnlyDeps, vars, rspfile,
|
|
|
|
commandLineLengthLimit, &usedResponseFile);
|
2015-05-18 17:31:11 +00:00
|
|
|
this->WriteLinkRule(usedResponseFile);
|
2014-04-13 12:06:41 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (targetOutput != targetOutputReal && !gt.IsFrameworkOnApple()) {
|
|
|
|
if (targetType == cmState::EXECUTABLE) {
|
|
|
|
globalGen.WriteBuild(
|
|
|
|
this->GetBuildFileStream(),
|
|
|
|
"Create executable symlink " + targetOutput,
|
|
|
|
"CMAKE_SYMLINK_EXECUTABLE", cmNinjaDeps(1, targetOutput),
|
|
|
|
cmNinjaDeps(1, targetOutputReal), emptyDeps, emptyDeps, symlinkVars);
|
|
|
|
} else {
|
2012-07-06 08:16:45 +00:00
|
|
|
cmNinjaDeps symlinks;
|
2016-05-13 23:18:20 +00:00
|
|
|
std::string const soName =
|
|
|
|
this->ConvertToNinjaPath(this->GetTargetFilePath(this->TargetNameSO));
|
2012-04-02 10:35:55 +00:00
|
|
|
// If one link has to be created.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (targetOutputReal == soName || targetOutput == soName) {
|
2012-04-02 10:35:55 +00:00
|
|
|
symlinkVars["SONAME"] = soName;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2012-04-02 10:35:55 +00:00
|
|
|
symlinkVars["SONAME"] = "";
|
2012-07-06 08:16:45 +00:00
|
|
|
symlinks.push_back(soName);
|
2014-04-13 12:06:41 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
symlinks.push_back(targetOutput);
|
|
|
|
globalGen.WriteBuild(
|
|
|
|
this->GetBuildFileStream(), "Create library symlink " + targetOutput,
|
|
|
|
"CMAKE_SYMLINK_LIBRARY", symlinks, cmNinjaDeps(1, targetOutputReal),
|
|
|
|
emptyDeps, emptyDeps, symlinkVars);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-02-19 21:38:10 +00:00
|
|
|
|
2011-11-11 05:00:49 +00:00
|
|
|
// Add aliases for the file name and the target name.
|
2015-10-18 21:13:50 +00:00
|
|
|
globalGen.AddTargetAlias(this->TargetNameOut, >);
|
|
|
|
globalGen.AddTargetAlias(this->GetTargetName(), >);
|
2011-11-11 05:00:49 +00:00
|
|
|
}
|
2012-03-13 14:05:07 +00:00
|
|
|
|
|
|
|
void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
|
|
|
|
{
|
|
|
|
// Write a phony output that depends on all object files.
|
|
|
|
cmNinjaDeps outputs;
|
2015-10-18 21:13:50 +00:00
|
|
|
this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(),
|
|
|
|
outputs);
|
2012-03-13 14:05:07 +00:00
|
|
|
cmNinjaDeps depends = this->GetObjects();
|
2016-05-16 14:34:04 +00:00
|
|
|
this->GetGlobalGenerator()->WritePhonyBuild(
|
|
|
|
this->GetBuildFileStream(), "Object library " + this->GetTargetName(),
|
|
|
|
outputs, depends);
|
2012-03-13 14:05:07 +00:00
|
|
|
|
|
|
|
// Add aliases for the target name.
|
|
|
|
this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
|
2015-10-18 21:13:50 +00:00
|
|
|
this->GetGeneratorTarget());
|
2012-03-13 14:05:07 +00:00
|
|
|
}
|