2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2006-02-14 18:36:04 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2006-02-14 18:36:04 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
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.
|
|
|
|
============================================================================*/
|
2006-02-14 18:36:04 +03:00
|
|
|
#include "cmMakefileTargetGenerator.h"
|
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmAlgorithms.h"
|
|
|
|
#include "cmComputeLinkInformation.h"
|
2016-08-24 01:29:15 +03:00
|
|
|
#include "cmCustomCommand.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmCustomCommandGenerator.h"
|
2006-02-14 18:36:04 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGeneratorExpression.h"
|
|
|
|
#include "cmGeneratorTarget.h"
|
2006-04-11 19:06:19 +04:00
|
|
|
#include "cmGlobalUnixMakefileGenerator3.h"
|
2016-08-24 01:29:15 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
2006-02-14 18:36:04 +03:00
|
|
|
#include "cmLocalUnixMakefileGenerator3.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmMakefileExecutableTargetGenerator.h"
|
|
|
|
#include "cmMakefileLibraryTargetGenerator.h"
|
|
|
|
#include "cmMakefileUtilityTargetGenerator.h"
|
2016-08-24 01:29:15 +03:00
|
|
|
#include "cmOutputConverter.h"
|
|
|
|
#include "cmSourceFile.h"
|
|
|
|
#include "cmState.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cm_auto_ptr.hxx"
|
|
|
|
#include "cmake.h"
|
2006-02-14 18:36:04 +03:00
|
|
|
|
2016-08-24 01:29:15 +03:00
|
|
|
#include <algorithm>
|
2013-11-16 00:41:11 +04:00
|
|
|
#include <ctype.h>
|
2016-08-24 01:29:15 +03:00
|
|
|
#include <sstream>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <utility>
|
2006-02-14 18:36:04 +03:00
|
|
|
|
2016-07-20 21:57:18 +03:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2015-06-06 15:57:26 +03:00
|
|
|
cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmGeneratorTarget* target)
|
2016-06-16 17:54:20 +03:00
|
|
|
: cmCommonTargetGenerator(target)
|
2016-06-27 23:44:16 +03:00
|
|
|
, OSXBundleGenerator(CM_NULLPTR)
|
|
|
|
, MacOSXContentGenerator(CM_NULLPTR)
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
2016-06-27 23:44:16 +03:00
|
|
|
this->BuildFileStream = CM_NULLPTR;
|
|
|
|
this->InfoFileStream = CM_NULLPTR;
|
|
|
|
this->FlagFileStream = CM_NULLPTR;
|
2007-05-01 21:51:25 +04:00
|
|
|
this->CustomCommandDriver = OnBuild;
|
2008-02-19 00:38:34 +03:00
|
|
|
this->LocalGenerator =
|
2015-06-06 15:57:26 +03:00
|
|
|
static_cast<cmLocalUnixMakefileGenerator3*>(target->GetLocalGenerator());
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GlobalGenerator = static_cast<cmGlobalUnixMakefileGenerator3*>(
|
|
|
|
this->LocalGenerator->GetGlobalGenerator());
|
2009-03-16 23:22:19 +03:00
|
|
|
cmake* cm = this->GlobalGenerator->GetCMakeInstance();
|
2009-03-16 23:55:58 +03:00
|
|
|
this->NoRuleMessages = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* ruleStatus =
|
|
|
|
cm->GetState()->GetGlobalProperty("RULE_MESSAGES")) {
|
2009-03-16 23:55:58 +03:00
|
|
|
this->NoRuleMessages = cmSystemTools::IsOff(ruleStatus);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-07-18 14:17:39 +04:00
|
|
|
MacOSXContentGenerator = new MacOSXContentGeneratorType(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmMakefileTargetGenerator::~cmMakefileTargetGenerator()
|
|
|
|
{
|
|
|
|
delete MacOSXContentGenerator;
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmMakefileTargetGenerator* cmMakefileTargetGenerator::New(
|
|
|
|
cmGeneratorTarget* tgt)
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
2016-06-27 23:44:16 +03:00
|
|
|
cmMakefileTargetGenerator* result = CM_NULLPTR;
|
2006-02-14 18:36:04 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (tgt->GetType()) {
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::EXECUTABLE:
|
2008-02-19 00:38:34 +03:00
|
|
|
result = new cmMakefileExecutableTargetGenerator(tgt);
|
2006-02-14 18:36:04 +03:00
|
|
|
break;
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::STATIC_LIBRARY:
|
|
|
|
case cmState::SHARED_LIBRARY:
|
|
|
|
case cmState::MODULE_LIBRARY:
|
|
|
|
case cmState::OBJECT_LIBRARY:
|
2008-02-19 00:38:34 +03:00
|
|
|
result = new cmMakefileLibraryTargetGenerator(tgt);
|
2006-02-14 18:36:04 +03:00
|
|
|
break;
|
2015-10-08 01:21:51 +03:00
|
|
|
case cmState::UTILITY:
|
2008-02-19 00:38:34 +03:00
|
|
|
result = new cmMakefileUtilityTargetGenerator(tgt);
|
2006-02-14 18:36:04 +03:00
|
|
|
break;
|
|
|
|
default:
|
2006-02-16 21:42:58 +03:00
|
|
|
return result;
|
2006-08-01 19:38:42 +04:00
|
|
|
// break; /* unreachable */
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefileTargetGenerator::CreateRuleFile()
|
|
|
|
{
|
|
|
|
// Create a directory for this target.
|
2006-07-10 15:52:35 +04:00
|
|
|
this->TargetBuildDirectory =
|
2015-10-09 23:27:46 +03:00
|
|
|
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
|
2006-07-10 15:52:35 +04:00
|
|
|
this->TargetBuildDirectoryFull =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->ConvertToFullPath(this->TargetBuildDirectory);
|
|
|
|
cmSystemTools::MakeDirectory(this->TargetBuildDirectoryFull.c_str());
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Construct the rule file name.
|
|
|
|
this->BuildFileName = this->TargetBuildDirectory;
|
|
|
|
this->BuildFileName += "/build.make";
|
|
|
|
this->BuildFileNameFull = this->TargetBuildDirectoryFull;
|
|
|
|
this->BuildFileNameFull += "/build.make";
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-07-11 17:55:27 +04:00
|
|
|
// Construct the rule file name.
|
|
|
|
this->ProgressFileNameFull = this->TargetBuildDirectoryFull;
|
|
|
|
this->ProgressFileNameFull += "/progress.make";
|
|
|
|
|
|
|
|
// reset the progress count
|
|
|
|
this->NumberOfProgressActions = 0;
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Open the rule file. This should be copy-if-different because the
|
|
|
|
// rules may depend on this file itself.
|
2006-07-10 15:52:35 +04:00
|
|
|
this->BuildFileStream =
|
2006-02-14 18:36:04 +03:00
|
|
|
new cmGeneratedFileStream(this->BuildFileNameFull.c_str());
|
|
|
|
this->BuildFileStream->SetCopyIfDifferent(true);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->BuildFileStream) {
|
2006-02-14 18:36:04 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->WriteDisclaimer(*this->BuildFileStream);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->GlobalGenerator->AllowDeleteOnError()) {
|
2015-03-30 23:32:26 +03:00
|
|
|
std::vector<std::string> no_depends;
|
|
|
|
std::vector<std::string> no_commands;
|
|
|
|
this->LocalGenerator->WriteMakeRule(
|
|
|
|
*this->BuildFileStream, "Delete rule output on recipe failure.",
|
|
|
|
".DELETE_ON_ERROR", no_depends, no_commands, false);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->WriteSpecialTargetsTop(*this->BuildFileStream);
|
|
|
|
}
|
|
|
|
|
2006-06-01 19:45:51 +04:00
|
|
|
void cmMakefileTargetGenerator::WriteTargetBuildRules()
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
2014-02-13 20:25:00 +04:00
|
|
|
const std::string& config =
|
|
|
|
this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
|
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// write the custom commands for this target
|
|
|
|
// Look for files registered for cleaning in this directory.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* additional_clean_files =
|
|
|
|
this->Makefile->GetProperty("ADDITIONAL_MAKE_CLEAN_FILES")) {
|
2014-05-23 22:59:11 +04:00
|
|
|
cmGeneratorExpression ge;
|
2016-06-28 17:17:52 +03:00
|
|
|
CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
|
2016-05-16 17:34:04 +03:00
|
|
|
ge.Parse(additional_clean_files);
|
|
|
|
|
|
|
|
cmSystemTools::ExpandListArgument(
|
|
|
|
cge->Evaluate(this->LocalGenerator, config, false, this->GeneratorTarget,
|
2016-06-27 23:44:16 +03:00
|
|
|
CM_NULLPTR, CM_NULLPTR),
|
2016-05-16 17:34:04 +03:00
|
|
|
this->CleanFiles);
|
|
|
|
}
|
2006-06-01 19:45:51 +04:00
|
|
|
|
|
|
|
// add custom commands to the clean rules?
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* clean_no_custom = this->Makefile->GetProperty("CLEAN_NO_CUSTOM");
|
2006-06-01 19:45:51 +04:00
|
|
|
bool clean = cmSystemTools::IsOff(clean_no_custom);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-06-01 19:45:51 +04:00
|
|
|
// First generate the object rule files. Save a list of all object
|
|
|
|
// files for this target.
|
2014-03-13 02:06:05 +04:00
|
|
|
std::vector<cmSourceFile const*> customCommands;
|
2014-02-13 20:25:00 +04:00
|
|
|
this->GeneratorTarget->GetCustomCommands(customCommands, config);
|
2016-09-07 00:52:42 +03:00
|
|
|
std::string currentBinDir =
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmSourceFile const*>::const_iterator si =
|
|
|
|
customCommands.begin();
|
|
|
|
si != customCommands.end(); ++si) {
|
|
|
|
cmCustomCommandGenerator ccg(*(*si)->GetCustomCommand(), this->ConfigName,
|
2015-07-25 18:52:10 +03:00
|
|
|
this->LocalGenerator);
|
2014-03-10 23:47:19 +04:00
|
|
|
this->GenerateCustomRuleFile(ccg);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (clean) {
|
2014-03-10 23:47:19 +04:00
|
|
|
const std::vector<std::string>& outputs = ccg.GetOutputs();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator o = outputs.begin();
|
|
|
|
o != outputs.end(); ++o) {
|
2016-09-07 00:52:42 +03:00
|
|
|
this->CleanFiles.push_back(
|
|
|
|
this->LocalGenerator->ConvertToRelativePath(currentBinDir, *o));
|
2006-06-01 19:45:51 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-13 02:06:05 +04:00
|
|
|
std::vector<cmSourceFile const*> headerSources;
|
2014-02-13 20:25:00 +04:00
|
|
|
this->GeneratorTarget->GetHeaderSources(headerSources, config);
|
2012-07-16 19:34:22 +04:00
|
|
|
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
|
2016-05-16 17:34:04 +03:00
|
|
|
headerSources, this->MacOSXContentGenerator);
|
2014-03-13 02:06:05 +04:00
|
|
|
std::vector<cmSourceFile const*> extraSources;
|
2014-02-13 20:25:00 +04:00
|
|
|
this->GeneratorTarget->GetExtraSources(extraSources, config);
|
2012-07-16 19:34:22 +04:00
|
|
|
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
|
2016-05-16 17:34:04 +03:00
|
|
|
extraSources, this->MacOSXContentGenerator);
|
2014-03-13 02:06:05 +04:00
|
|
|
std::vector<cmSourceFile const*> externalObjects;
|
2014-02-13 20:25:00 +04:00
|
|
|
this->GeneratorTarget->GetExternalObjects(externalObjects, config);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmSourceFile const*>::const_iterator si =
|
|
|
|
externalObjects.begin();
|
|
|
|
si != externalObjects.end(); ++si) {
|
2012-03-07 20:54:52 +04:00
|
|
|
this->ExternalObjects.push_back((*si)->GetFullPath());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-13 02:06:05 +04:00
|
|
|
std::vector<cmSourceFile const*> objectSources;
|
2014-02-13 20:25:00 +04:00
|
|
|
this->GeneratorTarget->GetObjectSources(objectSources, config);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmSourceFile const*>::const_iterator si =
|
|
|
|
objectSources.begin();
|
|
|
|
si != objectSources.end(); ++si) {
|
2012-03-07 20:54:52 +04:00
|
|
|
// Generate this object file's rule file.
|
|
|
|
this->WriteObjectRuleFiles(**si);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefileTargetGenerator::WriteCommonCodeRules()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* root = (this->Makefile->IsOn("CMAKE_MAKE_INCLUDE_FROM_ROOT")
|
|
|
|
? "$(CMAKE_BINARY_DIR)/"
|
|
|
|
: "");
|
2010-06-10 19:15:31 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Include the dependencies for the target.
|
|
|
|
std::string dependFileNameFull = this->TargetBuildDirectoryFull;
|
|
|
|
dependFileNameFull += "/depend.make";
|
|
|
|
*this->BuildFileStream
|
|
|
|
<< "# Include any dependencies generated for this target.\n"
|
2015-05-16 06:18:39 +03:00
|
|
|
<< this->GlobalGenerator->IncludeDirective << " " << root
|
2016-08-27 19:09:04 +03:00
|
|
|
<< cmSystemTools::ConvertToOutputPath(
|
|
|
|
this->LocalGenerator
|
|
|
|
->ConvertToRelativePath(this->LocalGenerator->GetBinaryDirectory(),
|
|
|
|
dependFileNameFull)
|
|
|
|
.c_str())
|
2006-07-11 17:55:27 +04:00
|
|
|
<< "\n\n";
|
2009-03-16 23:22:19 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->NoRuleMessages) {
|
2009-03-16 23:22:19 +03:00
|
|
|
// Include the progress variables for the target.
|
|
|
|
*this->BuildFileStream
|
|
|
|
<< "# Include the progress variables for this target.\n"
|
2015-05-16 06:18:39 +03:00
|
|
|
<< this->GlobalGenerator->IncludeDirective << " " << root
|
2016-08-27 19:09:04 +03:00
|
|
|
<< cmSystemTools::ConvertToOutputPath(
|
|
|
|
this->LocalGenerator
|
|
|
|
->ConvertToRelativePath(
|
|
|
|
this->LocalGenerator->GetBinaryDirectory(),
|
|
|
|
this->ProgressFileNameFull)
|
|
|
|
.c_str())
|
2009-03-16 23:22:19 +03:00
|
|
|
<< "\n\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// make sure the depend file exists
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileExists(dependFileNameFull.c_str())) {
|
2006-02-14 18:36:04 +03:00
|
|
|
// Write an empty dependency file.
|
|
|
|
cmGeneratedFileStream depFileStream(dependFileNameFull.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
depFileStream << "# Empty dependencies file for "
|
|
|
|
<< this->GeneratorTarget->GetName() << ".\n"
|
|
|
|
<< "# This may be replaced when dependencies are built."
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
// Open the flags file. This should be copy-if-different because the
|
|
|
|
// rules may depend on this file itself.
|
|
|
|
this->FlagFileNameFull = this->TargetBuildDirectoryFull;
|
|
|
|
this->FlagFileNameFull += "/flags.make";
|
2006-07-10 15:52:35 +04:00
|
|
|
this->FlagFileStream =
|
2006-02-14 18:36:04 +03:00
|
|
|
new cmGeneratedFileStream(this->FlagFileNameFull.c_str());
|
|
|
|
this->FlagFileStream->SetCopyIfDifferent(true);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->FlagFileStream) {
|
2006-02-14 18:36:04 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->WriteDisclaimer(*this->FlagFileStream);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Include the flags for the target.
|
|
|
|
*this->BuildFileStream
|
|
|
|
<< "# Include the compile flags for this target's objects.\n"
|
2015-05-16 06:18:39 +03:00
|
|
|
<< this->GlobalGenerator->IncludeDirective << " " << root
|
2016-08-27 19:09:04 +03:00
|
|
|
<< cmSystemTools::ConvertToOutputPath(
|
|
|
|
this->LocalGenerator
|
|
|
|
->ConvertToRelativePath(this->LocalGenerator->GetBinaryDirectory(),
|
|
|
|
this->FlagFileNameFull)
|
|
|
|
.c_str())
|
2006-02-14 18:36:04 +03:00
|
|
|
<< "\n\n";
|
2006-06-01 19:45:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
|
|
|
|
{
|
2006-02-14 18:36:04 +03:00
|
|
|
// write language flags for target
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> languages;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GeneratorTarget->GetLanguages(
|
|
|
|
languages, this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
|
2014-02-17 14:14:18 +04:00
|
|
|
// put the compiler in the rules.make file so that if it changes
|
2007-12-13 23:54:29 +03:00
|
|
|
// things rebuild
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator l = languages.begin();
|
|
|
|
l != languages.end(); ++l) {
|
2014-02-10 09:21:34 +04:00
|
|
|
std::string compiler = "CMAKE_";
|
2007-12-13 23:54:29 +03:00
|
|
|
compiler += *l;
|
|
|
|
compiler += "_COMPILER";
|
2016-05-16 17:34:04 +03:00
|
|
|
*this->FlagFileStream << "# compile " << *l << " with "
|
|
|
|
<< this->Makefile->GetSafeDefinition(compiler)
|
|
|
|
<< "\n";
|
|
|
|
}
|
2007-12-13 23:54:29 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator l = languages.begin();
|
|
|
|
l != languages.end(); ++l) {
|
2014-08-12 21:26:03 +04:00
|
|
|
std::string flags = this->GetFlags(*l);
|
|
|
|
std::string defines = this->GetDefines(*l);
|
2015-07-13 17:35:04 +03:00
|
|
|
std::string includes = this->GetIncludes(*l);
|
2014-08-12 21:26:03 +04:00
|
|
|
// Escape comment characters so they do not terminate assignment.
|
|
|
|
cmSystemTools::ReplaceString(flags, "#", "\\#");
|
|
|
|
cmSystemTools::ReplaceString(defines, "#", "\\#");
|
2015-07-13 17:35:04 +03:00
|
|
|
cmSystemTools::ReplaceString(includes, "#", "\\#");
|
2014-08-12 21:26:03 +04:00
|
|
|
*this->FlagFileStream << *l << "_FLAGS = " << flags << "\n\n";
|
|
|
|
*this->FlagFileStream << *l << "_DEFINES = " << defines << "\n\n";
|
2015-07-13 17:35:04 +03:00
|
|
|
*this->FlagFileStream << *l << "_INCLUDES = " << includes << "\n\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()(
|
|
|
|
cmSourceFile const& source, const char* pkgloc)
|
2008-02-15 19:22:23 +03:00
|
|
|
{
|
2008-02-19 00:38:34 +03:00
|
|
|
// Skip OS X content when not building a Framework or Bundle.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Generator->GetGeneratorTarget()->IsBundleOnApple()) {
|
2008-02-19 00:38:34 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-02-19 00:38:34 +03:00
|
|
|
|
2012-07-17 01:03:40 +04:00
|
|
|
std::string macdir =
|
|
|
|
this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc);
|
2008-04-08 08:06:47 +04:00
|
|
|
|
2008-02-15 19:22:23 +03:00
|
|
|
// Get the input file location.
|
2016-05-26 23:21:15 +03:00
|
|
|
std::string const& input = source.GetFullPath();
|
2008-02-15 19:22:23 +03:00
|
|
|
|
|
|
|
// Get the output file location.
|
|
|
|
std::string output = macdir;
|
|
|
|
output += "/";
|
|
|
|
output += cmSystemTools::GetFilenameName(input);
|
2012-07-16 19:34:22 +04:00
|
|
|
this->Generator->CleanFiles.push_back(
|
2016-08-27 14:44:56 +03:00
|
|
|
this->Generator->LocalGenerator->ConvertToRelativePath(
|
2016-08-27 14:50:29 +03:00
|
|
|
this->Generator->LocalGenerator->GetCurrentBinaryDirectory(), output));
|
2016-08-27 14:44:56 +03:00
|
|
|
output = this->Generator->LocalGenerator->ConvertToRelativePath(
|
2016-09-07 00:02:23 +03:00
|
|
|
this->Generator->LocalGenerator->GetBinaryDirectory(), output);
|
2008-02-15 19:22:23 +03:00
|
|
|
|
|
|
|
// Create a rule to copy the content into the bundle.
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
std::vector<std::string> commands;
|
|
|
|
depends.push_back(input);
|
2008-02-19 00:38:34 +03:00
|
|
|
std::string copyEcho = "Copying OS X content ";
|
2008-02-15 19:22:23 +03:00
|
|
|
copyEcho += output;
|
2012-07-16 19:34:22 +04:00
|
|
|
this->Generator->LocalGenerator->AppendEcho(
|
2016-05-26 23:52:22 +03:00
|
|
|
commands, copyEcho, cmLocalUnixMakefileGenerator3::EchoBuild);
|
2008-02-15 19:22:23 +03:00
|
|
|
std::string copyCommand = "$(CMAKE_COMMAND) -E copy ";
|
2016-08-27 14:44:55 +03:00
|
|
|
copyCommand += this->Generator->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
input, cmOutputConverter::SHELL);
|
2008-02-15 19:22:23 +03:00
|
|
|
copyCommand += " ";
|
2016-08-27 14:44:55 +03:00
|
|
|
copyCommand += this->Generator->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
output, cmOutputConverter::SHELL);
|
2008-02-15 19:22:23 +03:00
|
|
|
commands.push_back(copyCommand);
|
2012-07-16 19:34:22 +04:00
|
|
|
this->Generator->LocalGenerator->WriteMakeRule(
|
2016-06-27 23:44:16 +03:00
|
|
|
*this->Generator->BuildFileStream, CM_NULLPTR, output, depends, commands,
|
|
|
|
false);
|
2012-07-16 19:34:22 +04:00
|
|
|
this->Generator->ExtraFiles.insert(output);
|
2008-02-15 19:22:23 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::WriteObjectRuleFiles(
|
|
|
|
cmSourceFile const& source)
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
|
|
|
// Identify the language of the source file.
|
2014-02-04 06:20:56 +04:00
|
|
|
const std::string& lang =
|
|
|
|
this->LocalGenerator->GetSourceFileLanguage(source);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (lang.empty()) {
|
2006-04-21 05:54:35 +04:00
|
|
|
// don't know anything about this file so skip it
|
2006-02-14 18:36:04 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
// Get the full path name of the object file.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string const& objectName =
|
|
|
|
this->GeneratorTarget->GetObjectName(&source);
|
2015-10-09 23:27:46 +03:00
|
|
|
std::string obj =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
|
2012-03-07 23:01:46 +04:00
|
|
|
obj += "/";
|
|
|
|
obj += objectName;
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
// Avoid generating duplicate rules.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ObjectFiles.find(obj) == this->ObjectFiles.end()) {
|
2006-03-15 19:02:08 +03:00
|
|
|
this->ObjectFiles.insert(obj);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream err;
|
2016-05-16 17:34:04 +03:00
|
|
|
err << "Warning: Source file \"" << source.GetFullPath()
|
2006-07-10 15:52:35 +04:00
|
|
|
<< "\" is listed multiple times for target \""
|
2016-05-16 17:34:04 +03:00
|
|
|
<< this->GeneratorTarget->GetName() << "\".";
|
2006-02-14 18:36:04 +03:00
|
|
|
cmSystemTools::Message(err.str().c_str(), "Warning");
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Create the directory containing the object file. This may be a
|
|
|
|
// subdirectory under the target's directory.
|
2014-03-11 03:04:11 +04:00
|
|
|
std::string dir = cmSystemTools::GetFilenamePath(obj);
|
2016-05-16 17:34:04 +03:00
|
|
|
cmSystemTools::MakeDirectory(
|
|
|
|
this->LocalGenerator->ConvertToFullPath(dir).c_str());
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Save this in the target's list of object files.
|
|
|
|
this->Objects.push_back(obj);
|
2007-08-02 17:37:10 +04:00
|
|
|
this->CleanFiles.push_back(obj);
|
2006-07-07 00:04:49 +04:00
|
|
|
|
|
|
|
// TODO: Remove
|
2016-05-16 17:34:04 +03:00
|
|
|
// std::string relativeObj
|
2006-07-10 15:52:35 +04:00
|
|
|
//= this->LocalGenerator->GetHomeRelativeOutputPath();
|
2016-05-16 17:34:04 +03:00
|
|
|
// relativeObj += obj;
|
2006-07-07 00:04:49 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// we compute some depends when writing the depend.make that we will also
|
|
|
|
// use in the build.make, same with depMakeFile
|
|
|
|
std::vector<std::string> depends;
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// generate the build rule file
|
|
|
|
this->WriteObjectBuildFile(obj, lang, source, depends);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// The object file should be checked for dependency integrity.
|
2015-09-25 01:13:20 +03:00
|
|
|
std::string objFullPath = this->LocalGenerator->GetCurrentBinaryDirectory();
|
2007-08-07 21:57:13 +04:00
|
|
|
objFullPath += "/";
|
|
|
|
objFullPath += obj;
|
2016-08-27 14:44:55 +03:00
|
|
|
objFullPath = cmSystemTools::CollapseFullPath(objFullPath);
|
2007-08-07 21:57:13 +04:00
|
|
|
std::string srcFullPath =
|
2016-08-27 14:44:55 +03:00
|
|
|
cmSystemTools::CollapseFullPath(source.GetFullPath());
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerator->AddImplicitDepends(
|
|
|
|
this->GeneratorTarget, lang, objFullPath.c_str(), srcFullPath.c_str());
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::WriteObjectBuildFile(
|
|
|
|
std::string& obj, const std::string& lang, cmSourceFile const& source,
|
|
|
|
std::vector<std::string>& depends)
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
2006-07-10 15:52:35 +04:00
|
|
|
this->LocalGenerator->AppendRuleDepend(depends,
|
2006-05-12 20:29:09 +04:00
|
|
|
this->FlagFileNameFull.c_str());
|
2011-03-15 21:07:36 +03:00
|
|
|
this->LocalGenerator->AppendRuleDepends(depends,
|
|
|
|
this->FlagFileDepends[lang]);
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
// generate the depend scanning rule
|
|
|
|
this->WriteObjectDependRules(source, depends);
|
|
|
|
|
|
|
|
std::string relativeObj = this->LocalGenerator->GetHomeRelativeOutputPath();
|
|
|
|
relativeObj += obj;
|
|
|
|
// Write the build rule.
|
2006-02-20 20:48:56 +03:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Build the set of compiler flags.
|
|
|
|
std::string flags;
|
2006-02-20 20:48:56 +03:00
|
|
|
|
|
|
|
// Add language-specific flags.
|
|
|
|
std::string langFlags = "$(";
|
|
|
|
langFlags += lang;
|
|
|
|
langFlags += "_FLAGS)";
|
2014-05-02 00:07:26 +04:00
|
|
|
this->LocalGenerator->AppendFlags(flags, langFlags);
|
2006-02-20 20:48:56 +03:00
|
|
|
|
2013-05-16 16:59:04 +04:00
|
|
|
std::string configUpper =
|
2015-07-08 18:21:55 +03:00
|
|
|
cmSystemTools::UpperCase(this->LocalGenerator->GetConfigName());
|
2013-05-16 16:59:04 +04:00
|
|
|
|
2011-08-31 18:24:43 +04:00
|
|
|
// Add Fortran format flags.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (lang == "Fortran") {
|
2011-08-31 18:24:43 +04:00
|
|
|
this->AppendFortranFormatFlags(flags, source);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-08-31 18:24:43 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Add flags from source file properties.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (source.GetProperty("COMPILE_FLAGS")) {
|
|
|
|
this->LocalGenerator->AppendFlags(flags,
|
|
|
|
source.GetProperty("COMPILE_FLAGS"));
|
|
|
|
*this->FlagFileStream << "# Custom flags: " << relativeObj
|
|
|
|
<< "_FLAGS = " << source.GetProperty("COMPILE_FLAGS")
|
2006-02-14 18:36:04 +03:00
|
|
|
<< "\n"
|
|
|
|
<< "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2008-01-14 17:20:58 +03:00
|
|
|
// Add language-specific defines.
|
2012-08-09 11:44:15 +04:00
|
|
|
std::set<std::string> defines;
|
2008-01-14 17:20:58 +03:00
|
|
|
|
|
|
|
// Add source-sepcific preprocessor definitions.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* compile_defs = source.GetProperty("COMPILE_DEFINITIONS")) {
|
2012-08-09 11:44:15 +04:00
|
|
|
this->LocalGenerator->AppendDefines(defines, compile_defs);
|
2016-05-16 17:34:04 +03:00
|
|
|
*this->FlagFileStream << "# Custom defines: " << relativeObj
|
|
|
|
<< "_DEFINES = " << compile_defs << "\n"
|
2008-01-14 17:20:58 +03:00
|
|
|
<< "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-16 05:02:00 +03:00
|
|
|
std::string defPropName = "COMPILE_DEFINITIONS_";
|
|
|
|
defPropName += configUpper;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* config_compile_defs = source.GetProperty(defPropName)) {
|
2012-08-09 11:44:15 +04:00
|
|
|
this->LocalGenerator->AppendDefines(defines, config_compile_defs);
|
2016-05-16 17:34:04 +03:00
|
|
|
*this->FlagFileStream << "# Custom defines: " << relativeObj << "_DEFINES_"
|
|
|
|
<< configUpper << " = " << config_compile_defs
|
|
|
|
<< "\n"
|
|
|
|
<< "\n";
|
|
|
|
}
|
2008-01-14 17:20:58 +03:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Get the output paths for source and object files.
|
2016-08-27 14:44:55 +03:00
|
|
|
std::string sourceFile = this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
source.GetFullPath(), cmOutputConverter::SHELL);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Construct the build message.
|
|
|
|
std::vector<std::string> no_commands;
|
|
|
|
std::vector<std::string> commands;
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-05-23 17:11:46 +04:00
|
|
|
// add in a progress call if needed
|
2015-02-06 00:48:16 +03:00
|
|
|
this->NumberOfProgressActions++;
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->NoRuleMessages) {
|
2015-02-06 00:48:16 +03:00
|
|
|
cmLocalUnixMakefileGenerator3::EchoProgress progress;
|
|
|
|
this->MakeEchoProgress(progress);
|
2009-03-16 23:55:58 +03:00
|
|
|
std::string buildEcho = "Building ";
|
|
|
|
buildEcho += lang;
|
|
|
|
buildEcho += " object ";
|
|
|
|
buildEcho += relativeObj;
|
2016-05-26 23:52:22 +03:00
|
|
|
this->LocalGenerator->AppendEcho(commands, buildEcho,
|
2016-05-16 17:34:04 +03:00
|
|
|
cmLocalUnixMakefileGenerator3::EchoBuild,
|
|
|
|
&progress);
|
|
|
|
}
|
2006-06-12 20:18:59 +04:00
|
|
|
|
2013-03-21 22:31:57 +04:00
|
|
|
std::string targetOutPathReal;
|
2007-02-02 00:56:36 +03:00
|
|
|
std::string targetOutPathPDB;
|
2014-02-24 23:15:21 +04:00
|
|
|
std::string targetOutPathCompilePDB;
|
2007-02-02 00:56:36 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string targetFullPathReal;
|
|
|
|
std::string targetFullPathPDB;
|
|
|
|
std::string targetFullPathCompilePDB;
|
|
|
|
if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE ||
|
|
|
|
this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY ||
|
|
|
|
this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
|
|
|
|
this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY) {
|
|
|
|
targetFullPathReal =
|
|
|
|
this->GeneratorTarget->GetFullPath(this->ConfigName, false, true);
|
|
|
|
targetFullPathPDB =
|
2015-08-05 19:39:17 +03:00
|
|
|
this->GeneratorTarget->GetPDBDirectory(this->ConfigName);
|
2016-05-16 17:34:04 +03:00
|
|
|
targetFullPathPDB += "/";
|
|
|
|
targetFullPathPDB += this->GeneratorTarget->GetPDBName(this->ConfigName);
|
2007-02-02 00:56:36 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY) {
|
2015-10-10 01:29:47 +03:00
|
|
|
targetFullPathCompilePDB =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GeneratorTarget->GetCompilePDBPath(this->ConfigName);
|
|
|
|
if (targetFullPathCompilePDB.empty()) {
|
|
|
|
targetFullPathCompilePDB =
|
2015-10-10 01:29:47 +03:00
|
|
|
this->GeneratorTarget->GetSupportDirectory() + "/";
|
2014-02-24 23:15:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-27 19:52:40 +03:00
|
|
|
targetOutPathReal = this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
this->LocalGenerator->ConvertToRelativePath(
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathReal),
|
|
|
|
cmOutputConverter::SHELL);
|
2016-08-27 14:44:55 +03:00
|
|
|
targetOutPathPDB = this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
targetFullPathPDB, cmOutputConverter::SHELL);
|
2016-08-27 19:52:40 +03:00
|
|
|
targetOutPathCompilePDB = this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
this->LocalGenerator->ConvertToRelativePath(
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory(),
|
|
|
|
targetFullPathCompilePDB),
|
|
|
|
cmOutputConverter::SHELL);
|
2016-05-16 17:34:04 +03:00
|
|
|
|
|
|
|
if (this->LocalGenerator->IsMinGWMake() &&
|
|
|
|
cmHasLiteralSuffix(targetOutPathCompilePDB, "\\")) {
|
|
|
|
// mingw32-make incorrectly interprets 'a\ b c' as 'a b' and 'c'
|
|
|
|
// (but 'a\ b "c"' as 'a\', 'b', and 'c'!). Workaround this by
|
|
|
|
// avoiding a trailing backslash in the argument.
|
|
|
|
targetOutPathCompilePDB[targetOutPathCompilePDB.size() - 1] = '/';
|
2015-04-30 22:25:16 +03:00
|
|
|
}
|
2007-02-02 00:56:36 +03:00
|
|
|
}
|
2006-02-20 21:42:18 +03:00
|
|
|
cmLocalGenerator::RuleVariables vars;
|
2009-02-10 16:51:15 +03:00
|
|
|
vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
|
2015-10-09 23:19:57 +03:00
|
|
|
vars.CMTarget = this->GeneratorTarget;
|
2014-02-04 06:20:56 +04:00
|
|
|
vars.Language = lang.c_str();
|
2013-03-21 22:31:57 +04:00
|
|
|
vars.Target = targetOutPathReal.c_str();
|
2007-02-02 00:56:36 +03:00
|
|
|
vars.TargetPDB = targetOutPathPDB.c_str();
|
2014-02-24 23:15:21 +04:00
|
|
|
vars.TargetCompilePDB = targetOutPathCompilePDB.c_str();
|
2006-02-20 21:42:18 +03:00
|
|
|
vars.Source = sourceFile.c_str();
|
2007-11-21 21:37:14 +03:00
|
|
|
std::string shellObj =
|
2016-08-27 14:44:55 +03:00
|
|
|
this->LocalGenerator->ConvertToOutputFormat(obj, cmOutputConverter::SHELL);
|
2007-11-21 21:37:14 +03:00
|
|
|
vars.Object = shellObj.c_str();
|
2015-10-10 01:29:47 +03:00
|
|
|
std::string objectDir = this->GeneratorTarget->GetSupportDirectory();
|
2016-08-27 19:52:40 +03:00
|
|
|
objectDir = this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
this->LocalGenerator->ConvertToRelativePath(
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory(), objectDir),
|
|
|
|
cmOutputConverter::SHELL);
|
2006-04-17 22:01:22 +04:00
|
|
|
vars.ObjectDir = objectDir.c_str();
|
2014-06-05 16:57:17 +04:00
|
|
|
std::string objectFileDir = cmSystemTools::GetFilenamePath(obj);
|
2016-08-27 19:52:40 +03:00
|
|
|
objectFileDir = this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
this->LocalGenerator->ConvertToRelativePath(
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory(), objectFileDir),
|
|
|
|
cmOutputConverter::SHELL);
|
2014-06-05 16:57:17 +04:00
|
|
|
vars.ObjectFileDir = objectFileDir.c_str();
|
2006-02-20 21:42:18 +03:00
|
|
|
vars.Flags = flags.c_str();
|
2012-08-09 11:44:15 +04:00
|
|
|
|
|
|
|
std::string definesString = "$(";
|
|
|
|
definesString += lang;
|
|
|
|
definesString += "_DEFINES)";
|
|
|
|
|
|
|
|
this->LocalGenerator->JoinDefines(defines, definesString, lang);
|
|
|
|
|
|
|
|
vars.Defines = definesString.c_str();
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2015-07-13 17:35:04 +03:00
|
|
|
std::string const includesString = "$(" + lang + "_INCLUDES)";
|
|
|
|
vars.Includes = includesString.c_str();
|
|
|
|
|
2014-11-05 21:43:06 +03:00
|
|
|
// At the moment, it is assumed that C, C++, and Fortran have both
|
2014-11-05 21:37:25 +03:00
|
|
|
// assembly and preprocessor capabilities. The same is true for the
|
|
|
|
// ability to export compile commands
|
2016-05-16 17:34:04 +03:00
|
|
|
bool lang_has_preprocessor =
|
|
|
|
((lang == "C") || (lang == "CXX") || (lang == "Fortran"));
|
2014-11-05 21:37:25 +03:00
|
|
|
bool const lang_has_assembly = lang_has_preprocessor;
|
|
|
|
bool const lang_can_export_cmds = lang_has_preprocessor;
|
2011-01-13 07:39:13 +03:00
|
|
|
|
2009-02-02 21:28:17 +03:00
|
|
|
// Construct the compile rules.
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string compileRuleVar = "CMAKE_";
|
|
|
|
compileRuleVar += lang;
|
|
|
|
compileRuleVar += "_COMPILE_OBJECT";
|
|
|
|
std::string compileRule =
|
|
|
|
this->Makefile->GetRequiredDefinition(compileRuleVar);
|
|
|
|
std::vector<std::string> compileCommands;
|
|
|
|
cmSystemTools::ExpandListArgument(compileRule, compileCommands);
|
|
|
|
|
|
|
|
if (this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS") &&
|
|
|
|
lang_can_export_cmds && compileCommands.size() == 1) {
|
|
|
|
std::string compileCommand = compileCommands[0];
|
|
|
|
this->LocalGenerator->ExpandRuleVariables(compileCommand, vars);
|
2016-08-27 14:44:55 +03:00
|
|
|
std::string workingDirectory = cmSystemTools::CollapseFullPath(
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory());
|
2016-05-16 17:34:04 +03:00
|
|
|
compileCommand.replace(compileCommand.find(langFlags), langFlags.size(),
|
|
|
|
this->GetFlags(lang));
|
|
|
|
std::string langDefines = std::string("$(") + lang + "_DEFINES)";
|
|
|
|
compileCommand.replace(compileCommand.find(langDefines),
|
|
|
|
langDefines.size(), this->GetDefines(lang));
|
|
|
|
std::string langIncludes = std::string("$(") + lang + "_INCLUDES)";
|
|
|
|
compileCommand.replace(compileCommand.find(langIncludes),
|
|
|
|
langIncludes.size(), this->GetIncludes(lang));
|
|
|
|
this->GlobalGenerator->AddCXXCompileCommand(
|
|
|
|
source.GetFullPath(), workingDirectory, compileCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Maybe insert an include-what-you-use runner.
|
|
|
|
if (!compileCommands.empty() && (lang == "C" || lang == "CXX")) {
|
|
|
|
std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
|
|
|
|
const char* iwyu = this->GeneratorTarget->GetProperty(iwyu_prop);
|
|
|
|
std::string const tidy_prop = lang + "_CLANG_TIDY";
|
|
|
|
const char* tidy = this->GeneratorTarget->GetProperty(tidy_prop);
|
|
|
|
if ((iwyu && *iwyu) || (tidy && *tidy)) {
|
|
|
|
std::string run_iwyu = "$(CMAKE_COMMAND) -E __run_iwyu";
|
|
|
|
if (iwyu && *iwyu) {
|
|
|
|
run_iwyu += " --iwyu=";
|
|
|
|
run_iwyu += this->LocalGenerator->EscapeForShell(iwyu);
|
2016-04-08 23:09:27 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
if (tidy && *tidy) {
|
|
|
|
run_iwyu += " --tidy=";
|
|
|
|
run_iwyu += this->LocalGenerator->EscapeForShell(tidy);
|
|
|
|
run_iwyu += " --source=";
|
|
|
|
run_iwyu += sourceFile;
|
2016-04-08 23:09:27 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
run_iwyu += " -- ";
|
|
|
|
compileCommands.front().insert(0, run_iwyu);
|
2015-05-18 21:39:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// Maybe insert a compiler launcher like ccache or distcc
|
|
|
|
if (!compileCommands.empty() && (lang == "C" || lang == "CXX")) {
|
|
|
|
std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
|
|
|
|
const char* clauncher =
|
|
|
|
this->GeneratorTarget->GetProperty(clauncher_prop);
|
|
|
|
if (clauncher && *clauncher) {
|
|
|
|
std::vector<std::string> launcher_cmd;
|
|
|
|
cmSystemTools::ExpandListArgument(clauncher, launcher_cmd, true);
|
|
|
|
for (std::vector<std::string>::iterator i = launcher_cmd.begin(),
|
|
|
|
e = launcher_cmd.end();
|
|
|
|
i != e; ++i) {
|
|
|
|
*i = this->LocalGenerator->EscapeForShell(*i);
|
2015-06-04 22:56:56 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string const& run_launcher = cmJoin(launcher_cmd, " ") + " ";
|
|
|
|
compileCommands.front().insert(0, run_launcher);
|
2015-06-04 22:56:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// Expand placeholders in the commands.
|
|
|
|
for (std::vector<std::string>::iterator i = compileCommands.begin();
|
|
|
|
i != compileCommands.end(); ++i) {
|
|
|
|
this->LocalGenerator->ExpandRuleVariables(*i, vars);
|
2015-05-21 22:35:45 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// Change the command working directory to the local build tree.
|
|
|
|
this->LocalGenerator->CreateCDCommand(
|
|
|
|
compileCommands, this->LocalGenerator->GetCurrentBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->LocalGenerator->GetBinaryDirectory());
|
2016-05-16 17:34:04 +03:00
|
|
|
commands.insert(commands.end(), compileCommands.begin(),
|
|
|
|
compileCommands.end());
|
2009-02-02 21:28:17 +03:00
|
|
|
}
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2007-09-13 21:37:45 +04:00
|
|
|
// Check for extra outputs created by the compilation.
|
2014-12-05 17:55:49 +03:00
|
|
|
std::vector<std::string> outputs(1, relativeObj);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* extra_outputs_str = source.GetProperty("OBJECT_OUTPUTS")) {
|
2014-11-22 13:00:45 +03:00
|
|
|
// Register these as extra files to clean.
|
2014-12-05 17:55:49 +03:00
|
|
|
cmSystemTools::ExpandListArgument(extra_outputs_str, outputs);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->CleanFiles.insert(this->CleanFiles.end(), outputs.begin() + 1,
|
|
|
|
outputs.end());
|
|
|
|
}
|
2007-09-13 21:37:45 +04:00
|
|
|
|
2014-12-05 17:55:49 +03:00
|
|
|
// Write the rule.
|
2016-06-27 23:44:16 +03:00
|
|
|
this->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR, outputs, depends,
|
|
|
|
commands);
|
2014-12-05 17:55:49 +03:00
|
|
|
|
2014-11-05 21:37:25 +03:00
|
|
|
bool do_preprocess_rules = lang_has_preprocessor &&
|
2006-08-08 07:25:21 +04:00
|
|
|
this->LocalGenerator->GetCreatePreprocessedSourceRules();
|
2016-05-16 17:34:04 +03:00
|
|
|
bool do_assembly_rules =
|
|
|
|
lang_has_assembly && this->LocalGenerator->GetCreateAssemblySourceRules();
|
|
|
|
if (do_preprocess_rules || do_assembly_rules) {
|
2006-08-08 07:25:21 +04:00
|
|
|
std::vector<std::string> force_depends;
|
|
|
|
force_depends.push_back("cmake_force");
|
2016-05-24 22:24:10 +03:00
|
|
|
std::string::size_type dot_pos = relativeObj.rfind('.');
|
2006-08-08 07:25:21 +04:00
|
|
|
std::string relativeObjBase = relativeObj.substr(0, dot_pos);
|
2016-05-24 22:24:10 +03:00
|
|
|
dot_pos = obj.rfind('.');
|
2007-11-21 21:37:14 +03:00
|
|
|
std::string objBase = obj.substr(0, dot_pos);
|
2006-08-08 07:25:21 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (do_preprocess_rules) {
|
2006-08-08 07:25:21 +04:00
|
|
|
commands.clear();
|
2006-08-09 19:43:35 +04:00
|
|
|
std::string relativeObjI = relativeObjBase + ".i";
|
2007-11-21 21:37:14 +03:00
|
|
|
std::string objI = objBase + ".i";
|
2006-08-08 07:25:21 +04:00
|
|
|
|
|
|
|
std::string preprocessEcho = "Preprocessing ";
|
|
|
|
preprocessEcho += lang;
|
|
|
|
preprocessEcho += " source to ";
|
2007-11-21 21:37:14 +03:00
|
|
|
preprocessEcho += objI;
|
2006-08-08 07:25:21 +04:00
|
|
|
this->LocalGenerator->AppendEcho(
|
2016-05-26 23:52:22 +03:00
|
|
|
commands, preprocessEcho, cmLocalUnixMakefileGenerator3::EchoBuild);
|
2006-08-08 07:25:21 +04:00
|
|
|
|
|
|
|
std::string preprocessRuleVar = "CMAKE_";
|
|
|
|
preprocessRuleVar += lang;
|
|
|
|
preprocessRuleVar += "_CREATE_PREPROCESSED_SOURCE";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* preprocessRule =
|
|
|
|
this->Makefile->GetDefinition(preprocessRuleVar)) {
|
2007-11-21 21:37:14 +03:00
|
|
|
std::vector<std::string> preprocessCommands;
|
|
|
|
cmSystemTools::ExpandListArgument(preprocessRule, preprocessCommands);
|
2009-02-02 21:28:17 +03:00
|
|
|
|
2016-08-27 14:44:55 +03:00
|
|
|
std::string shellObjI = this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
objI, cmOutputConverter::SHELL);
|
2009-02-02 22:36:53 +03:00
|
|
|
vars.PreprocessedSource = shellObjI.c_str();
|
|
|
|
|
2009-02-02 21:28:17 +03:00
|
|
|
// Expand placeholders in the commands.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator i = preprocessCommands.begin();
|
|
|
|
i != preprocessCommands.end(); ++i) {
|
2009-02-02 21:28:17 +03:00
|
|
|
this->LocalGenerator->ExpandRuleVariables(*i, vars);
|
2006-08-08 07:25:21 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
|
|
|
|
this->LocalGenerator->CreateCDCommand(
|
|
|
|
preprocessCommands,
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->LocalGenerator->GetBinaryDirectory());
|
2016-05-16 17:34:04 +03:00
|
|
|
commands.insert(commands.end(), preprocessCommands.begin(),
|
|
|
|
preprocessCommands.end());
|
|
|
|
} else {
|
2006-08-08 07:25:21 +04:00
|
|
|
std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
|
|
|
|
cmd += preprocessRuleVar;
|
|
|
|
commands.push_back(cmd);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-08-08 07:25:21 +04:00
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
|
2016-05-16 17:34:04 +03:00
|
|
|
relativeObjI, force_depends,
|
|
|
|
commands, false);
|
|
|
|
}
|
2006-08-08 07:25:21 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (do_assembly_rules) {
|
2006-08-08 07:25:21 +04:00
|
|
|
commands.clear();
|
2006-08-09 19:43:35 +04:00
|
|
|
std::string relativeObjS = relativeObjBase + ".s";
|
2007-11-21 21:37:14 +03:00
|
|
|
std::string objS = objBase + ".s";
|
2006-08-08 07:25:21 +04:00
|
|
|
|
|
|
|
std::string assemblyEcho = "Compiling ";
|
|
|
|
assemblyEcho += lang;
|
|
|
|
assemblyEcho += " source to assembly ";
|
2007-11-21 21:37:14 +03:00
|
|
|
assemblyEcho += objS;
|
2006-08-08 07:25:21 +04:00
|
|
|
this->LocalGenerator->AppendEcho(
|
2016-05-26 23:52:22 +03:00
|
|
|
commands, assemblyEcho, cmLocalUnixMakefileGenerator3::EchoBuild);
|
2006-08-08 07:25:21 +04:00
|
|
|
|
|
|
|
std::string assemblyRuleVar = "CMAKE_";
|
|
|
|
assemblyRuleVar += lang;
|
|
|
|
assemblyRuleVar += "_CREATE_ASSEMBLY_SOURCE";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* assemblyRule =
|
|
|
|
this->Makefile->GetDefinition(assemblyRuleVar)) {
|
2007-11-21 21:37:14 +03:00
|
|
|
std::vector<std::string> assemblyCommands;
|
|
|
|
cmSystemTools::ExpandListArgument(assemblyRule, assemblyCommands);
|
2009-02-02 21:28:17 +03:00
|
|
|
|
2016-08-27 14:44:55 +03:00
|
|
|
std::string shellObjS = this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
objS, cmOutputConverter::SHELL);
|
2009-02-02 22:36:53 +03:00
|
|
|
vars.AssemblySource = shellObjS.c_str();
|
|
|
|
|
2009-02-02 21:28:17 +03:00
|
|
|
// Expand placeholders in the commands.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator i = assemblyCommands.begin();
|
|
|
|
i != assemblyCommands.end(); ++i) {
|
2009-02-02 21:28:17 +03:00
|
|
|
this->LocalGenerator->ExpandRuleVariables(*i, vars);
|
2006-08-08 07:25:21 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
|
|
|
|
this->LocalGenerator->CreateCDCommand(
|
|
|
|
assemblyCommands, this->LocalGenerator->GetCurrentBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->LocalGenerator->GetBinaryDirectory());
|
2016-05-16 17:34:04 +03:00
|
|
|
commands.insert(commands.end(), assemblyCommands.begin(),
|
|
|
|
assemblyCommands.end());
|
|
|
|
} else {
|
2006-08-08 07:25:21 +04:00
|
|
|
std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
|
|
|
|
cmd += assemblyRuleVar;
|
|
|
|
commands.push_back(cmd);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-08-08 07:25:21 +04:00
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
|
2016-05-16 17:34:04 +03:00
|
|
|
relativeObjS, force_depends,
|
|
|
|
commands, false);
|
2006-08-08 07:25:21 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-08-08 07:25:21 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// If the language needs provides-requires mode, create the
|
|
|
|
// corresponding targets.
|
|
|
|
std::string objectRequires = relativeObj;
|
|
|
|
objectRequires += ".requires";
|
|
|
|
std::vector<std::string> p_depends;
|
|
|
|
// always provide an empty requires target
|
2016-06-27 23:44:16 +03:00
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
|
|
|
|
objectRequires, p_depends, no_commands,
|
|
|
|
true);
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
// write a build rule to recursively build what this obj provides
|
|
|
|
std::string objectProvides = relativeObj;
|
|
|
|
objectProvides += ".provides";
|
|
|
|
std::string temp = relativeObj;
|
|
|
|
temp += ".provides.build";
|
|
|
|
std::vector<std::string> r_commands;
|
2006-07-10 15:52:35 +04:00
|
|
|
std::string tgtMakefileName =
|
2015-10-15 01:12:53 +03:00
|
|
|
this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
|
2006-02-14 18:36:04 +03:00
|
|
|
tgtMakefileName += "/build.make";
|
2016-05-16 17:34:04 +03:00
|
|
|
r_commands.push_back(
|
|
|
|
this->LocalGenerator->GetRecursiveMakeCall(tgtMakefileName.c_str(), temp));
|
2006-05-12 20:29:09 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
p_depends.clear();
|
|
|
|
p_depends.push_back(objectRequires);
|
2016-06-27 23:44:16 +03:00
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
|
|
|
|
objectProvides, p_depends, r_commands,
|
|
|
|
true);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// write the provides.build rule dependency on the obj file
|
|
|
|
p_depends.clear();
|
|
|
|
p_depends.push_back(relativeObj);
|
2016-06-27 23:44:16 +03:00
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR, temp,
|
2016-05-16 17:34:04 +03:00
|
|
|
p_depends, no_commands, false);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefileTargetGenerator::WriteTargetRequiresRules()
|
|
|
|
{
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
std::vector<std::string> no_commands;
|
|
|
|
|
|
|
|
// Construct the name of the dependency generation target.
|
2006-07-10 15:52:35 +04:00
|
|
|
std::string depTarget =
|
2015-10-15 01:12:53 +03:00
|
|
|
this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
|
2006-02-14 18:36:04 +03:00
|
|
|
depTarget += "/requires";
|
|
|
|
|
|
|
|
// This target drives dependency generation for all object files.
|
|
|
|
std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
|
|
|
|
std::string objTarget;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator obj = this->Objects.begin();
|
|
|
|
obj != this->Objects.end(); ++obj) {
|
2006-02-14 18:36:04 +03:00
|
|
|
objTarget = relPath;
|
|
|
|
objTarget += *obj;
|
|
|
|
objTarget += ".requires";
|
|
|
|
depends.push_back(objTarget);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
// Write the rule.
|
2016-06-27 23:44:16 +03:00
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
|
|
|
|
depTarget, depends, no_commands, true);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmMakefileTargetGenerator::WriteTargetCleanRules()
|
|
|
|
{
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
std::vector<std::string> commands;
|
|
|
|
|
|
|
|
// Construct the clean target name.
|
2006-07-10 15:52:35 +04:00
|
|
|
std::string cleanTarget =
|
2015-10-15 01:12:53 +03:00
|
|
|
this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
|
2006-02-14 18:36:04 +03:00
|
|
|
cleanTarget += "/clean";
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Construct the clean command.
|
2006-03-09 22:30:35 +03:00
|
|
|
this->LocalGenerator->AppendCleanCommand(commands, this->CleanFiles,
|
2015-10-15 01:23:53 +03:00
|
|
|
this->GeneratorTarget);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerator->CreateCDCommand(
|
|
|
|
commands, this->LocalGenerator->GetCurrentBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->LocalGenerator->GetBinaryDirectory());
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Write the rule.
|
2016-06-27 23:44:16 +03:00
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
|
|
|
|
cleanTarget, depends, commands, true);
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
2015-04-10 20:03:34 +03:00
|
|
|
bool cmMakefileTargetGenerator::WriteMakeRule(
|
2016-05-16 17:34:04 +03:00
|
|
|
std::ostream& os, const char* comment,
|
2015-03-06 22:35:28 +03:00
|
|
|
const std::vector<std::string>& outputs,
|
|
|
|
const std::vector<std::string>& depends,
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::vector<std::string>& commands, bool in_help)
|
2015-03-06 22:35:28 +03:00
|
|
|
{
|
2015-04-10 20:03:34 +03:00
|
|
|
bool symbolic = false;
|
2016-05-27 00:05:30 +03:00
|
|
|
if (outputs.empty()) {
|
2015-04-10 20:03:34 +03:00
|
|
|
return symbolic;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-04-10 20:03:34 +03:00
|
|
|
|
|
|
|
// Check whether we need to bother checking for a symbolic output.
|
|
|
|
bool need_symbolic = this->GlobalGenerator->GetNeedSymbolicMark();
|
|
|
|
|
|
|
|
// Check whether the first output is marked as symbolic.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (need_symbolic) {
|
|
|
|
if (cmSourceFile* sf = this->Makefile->GetSource(outputs[0])) {
|
2015-04-10 20:03:34 +03:00
|
|
|
symbolic = sf->GetPropertyAsBool("SYMBOLIC");
|
2015-03-06 22:35:28 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-03-06 22:35:28 +03:00
|
|
|
|
|
|
|
// We always attach the actual commands to the first output.
|
|
|
|
this->LocalGenerator->WriteMakeRule(os, comment, outputs[0], depends,
|
|
|
|
commands, symbolic, in_help);
|
|
|
|
|
|
|
|
// For single outputs, we are done.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (outputs.size() == 1) {
|
2015-04-10 20:03:34 +03:00
|
|
|
return symbolic;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-03-06 22:35:28 +03:00
|
|
|
|
|
|
|
// For multiple outputs, make the extra ones depend on the first one.
|
|
|
|
std::vector<std::string> const output_depends(1, outputs[0]);
|
2016-09-08 00:31:04 +03:00
|
|
|
std::string binDir = this->LocalGenerator->GetBinaryDirectory();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator o = outputs.begin() + 1;
|
|
|
|
o != outputs.end(); ++o) {
|
2015-03-06 22:35:28 +03:00
|
|
|
// Touch the extra output so "make" knows that it was updated,
|
|
|
|
// but only if the output was acually created.
|
2016-08-27 19:20:37 +03:00
|
|
|
std::string const out = this->LocalGenerator->ConvertToOutputFormat(
|
2016-09-08 00:31:04 +03:00
|
|
|
this->LocalGenerator->ConvertToRelativePath(binDir, *o),
|
2016-08-27 19:20:37 +03:00
|
|
|
cmOutputConverter::SHELL);
|
2015-03-06 22:35:28 +03:00
|
|
|
std::vector<std::string> output_commands;
|
2015-04-10 20:03:34 +03:00
|
|
|
|
|
|
|
bool o_symbolic = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (need_symbolic) {
|
|
|
|
if (cmSourceFile* sf = this->Makefile->GetSource(*o)) {
|
2015-04-10 20:03:34 +03:00
|
|
|
o_symbolic = sf->GetPropertyAsBool("SYMBOLIC");
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-04-10 20:03:34 +03:00
|
|
|
symbolic = symbolic && o_symbolic;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!o_symbolic) {
|
2015-03-06 22:35:28 +03:00
|
|
|
output_commands.push_back("@$(CMAKE_COMMAND) -E touch_nocreate " + out);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-06-27 23:44:16 +03:00
|
|
|
this->LocalGenerator->WriteMakeRule(os, CM_NULLPTR, *o, output_depends,
|
2015-04-10 20:03:34 +03:00
|
|
|
output_commands, o_symbolic, in_help);
|
2015-03-06 22:35:28 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!o_symbolic) {
|
2015-03-06 22:35:28 +03:00
|
|
|
// At build time, remove the first output if this one does not exist
|
|
|
|
// so that "make" will rerun the real commands that create this one.
|
|
|
|
MultipleOutputPairsType::value_type p(*o, outputs[0]);
|
|
|
|
this->MultipleOutputPairs.insert(p);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-04-10 20:03:34 +03:00
|
|
|
return symbolic;
|
2015-03-06 22:35:28 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
void cmMakefileTargetGenerator::WriteTargetDependRules()
|
|
|
|
{
|
|
|
|
// must write the targets depend info file
|
2015-10-09 23:27:46 +03:00
|
|
|
std::string dir =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
|
2006-02-14 18:36:04 +03:00
|
|
|
this->InfoFileNameFull = dir;
|
|
|
|
this->InfoFileNameFull += "/DependInfo.cmake";
|
2006-07-10 15:52:35 +04:00
|
|
|
this->InfoFileNameFull =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->LocalGenerator->ConvertToFullPath(this->InfoFileNameFull);
|
2006-07-10 15:52:35 +04:00
|
|
|
this->InfoFileStream =
|
2006-02-14 18:36:04 +03:00
|
|
|
new cmGeneratedFileStream(this->InfoFileNameFull.c_str());
|
|
|
|
this->InfoFileStream->SetCopyIfDifferent(true);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!*this->InfoFileStream) {
|
2006-02-14 18:36:04 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
this->LocalGenerator->WriteDependLanguageInfo(*this->InfoFileStream,
|
|
|
|
this->GeneratorTarget);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2015-03-06 22:35:28 +03:00
|
|
|
// Store multiple output pairs in the depend info file.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->MultipleOutputPairs.empty()) {
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2015-03-06 22:35:28 +03:00
|
|
|
*this->InfoFileStream
|
|
|
|
<< "\n"
|
|
|
|
<< "# Pairs of files generated by the same build rule.\n"
|
|
|
|
<< "set(CMAKE_MULTIPLE_OUTPUT_PAIRS\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-05-16 17:34:04 +03:00
|
|
|
for (MultipleOutputPairsType::const_iterator pi =
|
|
|
|
this->MultipleOutputPairs.begin();
|
|
|
|
pi != this->MultipleOutputPairs.end(); ++pi) {
|
2015-03-06 22:35:28 +03:00
|
|
|
*this->InfoFileStream
|
2016-05-16 17:34:04 +03:00
|
|
|
<< " " << cmOutputConverter::EscapeForCMake(pi->first) << " "
|
|
|
|
<< cmOutputConverter::EscapeForCMake(pi->second) << "\n";
|
2015-03-06 22:35:28 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
*this->InfoFileStream << " )\n\n";
|
|
|
|
}
|
2015-03-06 22:35:28 +03:00
|
|
|
|
2007-12-28 19:49:46 +03:00
|
|
|
// Store list of targets linked directly or transitively.
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
/* clang-format off */
|
2007-12-28 19:49:46 +03:00
|
|
|
*this->InfoFileStream
|
|
|
|
<< "\n"
|
|
|
|
<< "# Targets to which this target links.\n"
|
2013-08-22 13:30:19 +04:00
|
|
|
<< "set(CMAKE_TARGET_LINKED_INFO_FILES\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
/* clang-format on */
|
|
|
|
std::vector<std::string> dirs = this->GetLinkedTargetDirectories();
|
|
|
|
for (std::vector<std::string>::iterator i = dirs.begin(); i != dirs.end();
|
|
|
|
++i) {
|
|
|
|
*this->InfoFileStream << " \"" << *i << "/DependInfo.cmake\"\n";
|
2007-12-28 19:49:46 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
*this->InfoFileStream << " )\n";
|
2007-12-28 19:49:46 +03:00
|
|
|
}
|
|
|
|
|
2016-09-19 22:36:00 +03:00
|
|
|
std::string const& working_dir =
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory();
|
|
|
|
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2015-07-29 18:49:00 +03:00
|
|
|
*this->InfoFileStream
|
|
|
|
<< "\n"
|
|
|
|
<< "# Fortran module output directory.\n"
|
|
|
|
<< "set(CMAKE_Fortran_TARGET_MODULE_DIR \""
|
2016-09-19 22:36:00 +03:00
|
|
|
<< this->GeneratorTarget->GetFortranModuleDirectory(working_dir)
|
|
|
|
<< "\")\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2007-12-31 00:11:38 +03:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// and now write the rule to use it
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
std::vector<std::string> commands;
|
|
|
|
|
|
|
|
// Construct the name of the dependency generation target.
|
2006-07-10 15:52:35 +04:00
|
|
|
std::string depTarget =
|
2015-10-15 01:12:53 +03:00
|
|
|
this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
|
2006-02-14 18:36:04 +03:00
|
|
|
depTarget += "/depend";
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Add a command to call CMake to scan dependencies. CMake will
|
|
|
|
// touch the corresponding depends file after scanning dependencies.
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream depCmd;
|
2016-05-16 17:34:04 +03:00
|
|
|
// TODO: Account for source file properties and directory-level
|
|
|
|
// definitions when scanning for dependencies.
|
2006-04-27 18:41:37 +04:00
|
|
|
#if !defined(_WIN32) || defined(__CYGWIN__)
|
|
|
|
// This platform supports symlinks, so cmSystemTools will translate
|
|
|
|
// paths. Make sure PWD is set to the original name of the home
|
|
|
|
// output directory to help cmSystemTools to create the same
|
|
|
|
// translation table for the dependency scanning process.
|
2016-08-27 14:44:57 +03:00
|
|
|
depCmd << "cd " << (this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(
|
|
|
|
this->LocalGenerator->GetBinaryDirectory()),
|
|
|
|
cmOutputConverter::SHELL))
|
2006-04-27 18:41:37 +04:00
|
|
|
<< " && ";
|
|
|
|
#endif
|
2006-05-25 17:47:30 +04:00
|
|
|
// Generate a call this signature:
|
|
|
|
//
|
|
|
|
// cmake -E cmake_depends <generator>
|
|
|
|
// <home-src-dir> <start-src-dir>
|
|
|
|
// <home-out-dir> <start-out-dir>
|
2007-12-20 01:15:41 +03:00
|
|
|
// <dep-info> --color=$(COLOR)
|
2006-05-25 17:47:30 +04:00
|
|
|
//
|
|
|
|
// This gives the dependency scanner enough information to recreate
|
|
|
|
// the state of our local generator sufficiently for its needs.
|
|
|
|
depCmd << "$(CMAKE_COMMAND) -E cmake_depends \""
|
2006-02-14 18:36:04 +03:00
|
|
|
<< this->GlobalGenerator->GetName() << "\" "
|
2016-08-27 14:44:57 +03:00
|
|
|
<< this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(
|
|
|
|
this->LocalGenerator->GetSourceDirectory()),
|
|
|
|
cmOutputConverter::SHELL)
|
2006-02-14 18:36:04 +03:00
|
|
|
<< " "
|
2016-08-27 14:44:57 +03:00
|
|
|
<< this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(
|
|
|
|
this->LocalGenerator->GetCurrentSourceDirectory()),
|
|
|
|
cmOutputConverter::SHELL)
|
2006-05-25 17:47:30 +04:00
|
|
|
<< " "
|
2016-08-27 14:44:57 +03:00
|
|
|
<< this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(
|
|
|
|
this->LocalGenerator->GetBinaryDirectory()),
|
|
|
|
cmOutputConverter::SHELL)
|
2006-05-25 17:47:30 +04:00
|
|
|
<< " "
|
2016-08-27 14:44:57 +03:00
|
|
|
<< this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory()),
|
|
|
|
cmOutputConverter::SHELL)
|
2006-02-14 18:36:04 +03:00
|
|
|
<< " "
|
2016-08-27 14:44:57 +03:00
|
|
|
<< this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(this->InfoFileNameFull),
|
|
|
|
cmOutputConverter::SHELL);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->LocalGenerator->GetColorMakefile()) {
|
2008-10-15 18:40:57 +04:00
|
|
|
depCmd << " --color=$(COLOR)";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
commands.push_back(depCmd.str());
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-08-31 22:09:56 +04:00
|
|
|
// Make sure all custom command outputs in this target are built.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CustomCommandDriver == OnDepends) {
|
2006-09-29 00:40:35 +04:00
|
|
|
this->DriveCustomCommands(depends);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-09-29 00:40:35 +04:00
|
|
|
|
|
|
|
// Write the rule.
|
2016-06-27 23:44:16 +03:00
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
|
|
|
|
depTarget, depends, commands, true);
|
2006-09-29 00:40:35 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::DriveCustomCommands(
|
|
|
|
std::vector<std::string>& depends)
|
2006-09-29 00:40:35 +04:00
|
|
|
{
|
|
|
|
// Depend on all custom command outputs.
|
2013-07-14 20:22:57 +04:00
|
|
|
std::vector<cmSourceFile*> sources;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GeneratorTarget->GetSourceFiles(
|
|
|
|
sources, this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
|
|
|
|
for (std::vector<cmSourceFile*>::const_iterator source = sources.begin();
|
|
|
|
source != sources.end(); ++source) {
|
|
|
|
if (cmCustomCommand* cc = (*source)->GetCustomCommand()) {
|
2015-07-25 18:52:10 +03:00
|
|
|
cmCustomCommandGenerator ccg(*cc, this->ConfigName,
|
|
|
|
this->LocalGenerator);
|
2014-03-10 23:47:19 +04:00
|
|
|
const std::vector<std::string>& outputs = ccg.GetOutputs();
|
2014-11-22 13:00:45 +03:00
|
|
|
depends.insert(depends.end(), outputs.begin(), outputs.end());
|
2006-08-31 22:09:56 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::WriteObjectDependRules(
|
|
|
|
cmSourceFile const& source, std::vector<std::string>& depends)
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
|
|
|
// Create the list of dependencies known at cmake time. These are
|
|
|
|
// shared between the object file and dependency scanning rule.
|
|
|
|
depends.push_back(source.GetFullPath());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* objectDeps = source.GetProperty("OBJECT_DEPENDS")) {
|
2014-12-18 23:03:38 +03:00
|
|
|
cmSystemTools::ExpandListArgument(objectDeps, depends);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::GenerateCustomRuleFile(
|
|
|
|
cmCustomCommandGenerator const& ccg)
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
|
|
|
// Collect the commands.
|
|
|
|
std::vector<std::string> commands;
|
2014-03-10 23:47:19 +04:00
|
|
|
std::string comment = this->LocalGenerator->ConstructComment(ccg);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!comment.empty()) {
|
2006-07-13 22:03:56 +04:00
|
|
|
// add in a progress call if needed
|
2015-02-06 00:48:16 +03:00
|
|
|
this->NumberOfProgressActions++;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->NoRuleMessages) {
|
2015-02-06 00:48:16 +03:00
|
|
|
cmLocalUnixMakefileGenerator3::EchoProgress progress;
|
|
|
|
this->MakeEchoProgress(progress);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerator->AppendEcho(
|
2016-05-26 23:52:22 +03:00
|
|
|
commands, comment, cmLocalUnixMakefileGenerator3::EchoGenerate,
|
2016-05-16 17:34:04 +03:00
|
|
|
&progress);
|
2006-04-11 19:06:19 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-03 17:55:28 +04:00
|
|
|
|
|
|
|
// Now append the actual user-specified commands.
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream content;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerator->AppendCustomCommand(
|
2016-08-27 14:44:53 +03:00
|
|
|
commands, ccg, this->GeneratorTarget,
|
|
|
|
this->LocalGenerator->GetBinaryDirectory(), false, &content);
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-02-14 18:36:04 +03:00
|
|
|
// Collect the dependencies.
|
|
|
|
std::vector<std::string> depends;
|
2014-03-10 23:47:19 +04:00
|
|
|
this->LocalGenerator->AppendCustomDepend(depends, ccg);
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
// Write the rule.
|
2014-03-10 23:47:19 +04:00
|
|
|
const std::vector<std::string>& outputs = ccg.GetOutputs();
|
2016-06-27 23:44:16 +03:00
|
|
|
bool symbolic = this->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
|
|
|
|
outputs, depends, commands);
|
2008-06-03 00:44:58 +04:00
|
|
|
|
|
|
|
// If the rule has changed make sure the output is rebuilt.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!symbolic) {
|
2014-03-10 23:47:19 +04:00
|
|
|
this->GlobalGenerator->AddRuleHash(ccg.GetOutputs(), content.str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-04-11 19:06:19 +04:00
|
|
|
|
2007-09-17 18:50:46 +04:00
|
|
|
// Setup implicit dependency scanning.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cmCustomCommand::ImplicitDependsList::const_iterator idi =
|
|
|
|
ccg.GetCC().GetImplicitDepends().begin();
|
|
|
|
idi != ccg.GetCC().GetImplicitDepends().end(); ++idi) {
|
2016-08-27 14:44:55 +03:00
|
|
|
std::string objFullPath = cmSystemTools::CollapseFullPath(outputs[0]);
|
|
|
|
std::string srcFullPath = cmSystemTools::CollapseFullPath(idi->second);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerator->AddImplicitDepends(this->GeneratorTarget, idi->first,
|
|
|
|
objFullPath.c_str(),
|
|
|
|
srcFullPath.c_str());
|
|
|
|
}
|
2007-03-09 19:29:15 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::MakeEchoProgress(
|
|
|
|
cmLocalUnixMakefileGenerator3::EchoProgress& progress) const
|
2009-03-16 23:22:13 +03:00
|
|
|
{
|
2015-10-07 02:17:48 +03:00
|
|
|
progress.Dir = this->LocalGenerator->GetBinaryDirectory();
|
2015-02-06 00:48:16 +03:00
|
|
|
progress.Dir += cmake::GetCMakeFilesDirectory();
|
|
|
|
std::ostringstream progressArg;
|
|
|
|
progressArg << "$(CMAKE_PROGRESS_" << this->NumberOfProgressActions << ")";
|
|
|
|
progress.Arg = progressArg.str();
|
2009-03-16 23:22:13 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::WriteObjectsVariable(
|
|
|
|
std::string& variableName, std::string& variableNameExternal,
|
|
|
|
bool useWatcomQuote)
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
|
|
|
// Write a make variable assignment that lists all objects for the
|
|
|
|
// target.
|
2016-05-16 17:34:04 +03:00
|
|
|
variableName = this->LocalGenerator->CreateMakeVariable(
|
|
|
|
this->GeneratorTarget->GetName(), "_OBJECTS");
|
|
|
|
*this->BuildFileStream << "# Object files for target "
|
|
|
|
<< this->GeneratorTarget->GetName() << "\n"
|
|
|
|
<< variableName << " =";
|
2006-02-14 18:36:04 +03:00
|
|
|
std::string object;
|
2006-07-10 15:52:35 +04:00
|
|
|
const char* lineContinue =
|
2006-02-14 18:36:04 +03:00
|
|
|
this->Makefile->GetDefinition("CMAKE_MAKE_LINE_CONTINUE");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!lineContinue) {
|
2006-02-14 18:36:04 +03:00
|
|
|
lineContinue = "\\";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (std::vector<std::string>::const_iterator i = this->Objects.begin();
|
|
|
|
i != this->Objects.end(); ++i) {
|
2006-02-14 18:36:04 +03:00
|
|
|
*this->BuildFileStream << " " << lineContinue << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
*this->BuildFileStream << this->LocalGenerator->ConvertToQuotedOutputPath(
|
|
|
|
i->c_str(), useWatcomQuote);
|
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
*this->BuildFileStream << "\n";
|
|
|
|
|
|
|
|
// Write a make variable assignment that lists all external objects
|
|
|
|
// for the target.
|
2016-05-16 17:34:04 +03:00
|
|
|
variableNameExternal = this->LocalGenerator->CreateMakeVariable(
|
|
|
|
this->GeneratorTarget->GetName(), "_EXTERNAL_OBJECTS");
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2006-02-14 18:36:04 +03:00
|
|
|
*this->BuildFileStream
|
|
|
|
<< "\n"
|
2006-07-10 15:52:35 +04:00
|
|
|
<< "# External object files for target "
|
2015-10-16 21:09:43 +03:00
|
|
|
<< this->GeneratorTarget->GetName() << "\n"
|
2014-03-11 16:35:32 +04:00
|
|
|
<< variableNameExternal << " =";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-09-07 00:52:42 +03:00
|
|
|
std::string currentBinDir =
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator i =
|
|
|
|
this->ExternalObjects.begin();
|
|
|
|
i != this->ExternalObjects.end(); ++i) {
|
2016-09-07 00:52:42 +03:00
|
|
|
object = this->LocalGenerator->ConvertToRelativePath(currentBinDir, *i);
|
2016-05-16 17:34:04 +03:00
|
|
|
*this->BuildFileStream << " " << lineContinue << "\n"
|
|
|
|
<< this->Makefile->GetSafeDefinition(
|
|
|
|
"CMAKE_OBJECT_NAME");
|
|
|
|
*this->BuildFileStream << this->LocalGenerator->ConvertToQuotedOutputPath(
|
|
|
|
i->c_str(), useWatcomQuote);
|
|
|
|
}
|
|
|
|
*this->BuildFileStream << "\n"
|
|
|
|
<< "\n";
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::WriteObjectsString(std::string& buildObjs)
|
2006-06-16 00:17:11 +04:00
|
|
|
{
|
2008-01-30 04:46:25 +03:00
|
|
|
std::vector<std::string> objStrings;
|
|
|
|
this->WriteObjectsStrings(objStrings);
|
|
|
|
buildObjs = objStrings[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
class cmMakefileTargetGeneratorObjectStrings
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmMakefileTargetGeneratorObjectStrings(std::vector<std::string>& strings,
|
|
|
|
cmLocalUnixMakefileGenerator3* lg,
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string::size_type limit)
|
|
|
|
: Strings(strings)
|
|
|
|
, LocalGenerator(lg)
|
|
|
|
, LengthLimit(limit)
|
|
|
|
{
|
2008-01-30 04:46:25 +03:00
|
|
|
this->Space = "";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-30 04:46:25 +03:00
|
|
|
void Feed(std::string const& obj)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2008-01-30 04:46:25 +03:00
|
|
|
// Construct the name of the next object.
|
2016-08-27 19:52:40 +03:00
|
|
|
this->NextObject = this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
this->LocalGenerator->ConvertToRelativePath(
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory(), obj),
|
|
|
|
cmOutputConverter::RESPONSE);
|
2008-01-30 04:46:25 +03:00
|
|
|
|
|
|
|
// Roll over to next string if the limit will be exceeded.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->LengthLimit != std::string::npos &&
|
|
|
|
(this->CurrentString.length() + 1 + this->NextObject.length() >
|
|
|
|
this->LengthLimit)) {
|
2008-01-30 04:46:25 +03:00
|
|
|
this->Strings.push_back(this->CurrentString);
|
|
|
|
this->CurrentString = "";
|
|
|
|
this->Space = "";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-30 04:46:25 +03:00
|
|
|
|
|
|
|
// Separate from previous object.
|
|
|
|
this->CurrentString += this->Space;
|
|
|
|
this->Space = " ";
|
|
|
|
|
|
|
|
// Append this object.
|
|
|
|
this->CurrentString += this->NextObject;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
void Done() { this->Strings.push_back(this->CurrentString); }
|
2008-01-30 04:46:25 +03:00
|
|
|
private:
|
|
|
|
std::vector<std::string>& Strings;
|
|
|
|
cmLocalUnixMakefileGenerator3* LocalGenerator;
|
|
|
|
std::string::size_type LengthLimit;
|
|
|
|
std::string CurrentString;
|
|
|
|
std::string NextObject;
|
|
|
|
const char* Space;
|
|
|
|
};
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::WriteObjectsStrings(
|
|
|
|
std::vector<std::string>& objStrings, std::string::size_type limit)
|
2008-01-30 04:46:25 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmMakefileTargetGeneratorObjectStrings helper(objStrings,
|
|
|
|
this->LocalGenerator, limit);
|
|
|
|
for (std::vector<std::string>::const_iterator i = this->Objects.begin();
|
|
|
|
i != this->Objects.end(); ++i) {
|
2008-01-30 04:46:25 +03:00
|
|
|
helper.Feed(*i);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (std::vector<std::string>::const_iterator i =
|
|
|
|
this->ExternalObjects.begin();
|
|
|
|
i != this->ExternalObjects.end(); ++i) {
|
2008-01-30 04:46:25 +03:00
|
|
|
helper.Feed(*i);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-30 04:46:25 +03:00
|
|
|
helper.Done();
|
2006-06-16 00:17:11 +04:00
|
|
|
}
|
|
|
|
|
2014-02-25 05:32:55 +04:00
|
|
|
void cmMakefileTargetGenerator::WriteTargetDriverRule(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& main_output, bool relink)
|
2006-06-01 19:45:51 +04:00
|
|
|
{
|
|
|
|
// Compute the name of the driver target.
|
2006-10-10 05:25:58 +04:00
|
|
|
std::string dir =
|
2015-10-15 01:12:53 +03:00
|
|
|
this->LocalGenerator->GetRelativeTargetDirectory(this->GeneratorTarget);
|
2006-06-01 19:45:51 +04:00
|
|
|
std::string buildTargetRuleName = dir;
|
2016-05-16 17:34:04 +03:00
|
|
|
buildTargetRuleName += relink ? "/preinstall" : "/build";
|
2016-08-27 14:44:56 +03:00
|
|
|
buildTargetRuleName = this->LocalGenerator->ConvertToRelativePath(
|
2016-09-07 00:02:23 +03:00
|
|
|
this->LocalGenerator->GetBinaryDirectory(), buildTargetRuleName);
|
2006-06-01 19:45:51 +04:00
|
|
|
|
|
|
|
// Build the list of target outputs to drive.
|
|
|
|
std::vector<std::string> depends;
|
2014-02-25 05:32:55 +04:00
|
|
|
depends.push_back(main_output);
|
2006-06-01 19:45:51 +04:00
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
const char* comment = CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (relink) {
|
2006-06-01 19:45:51 +04:00
|
|
|
// Setup the comment for the preinstall driver.
|
|
|
|
comment = "Rule to relink during preinstall.";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2006-06-01 19:45:51 +04:00
|
|
|
// Setup the comment for the main build driver.
|
|
|
|
comment = "Rule to build all files generated by this target.";
|
2006-09-29 00:40:35 +04:00
|
|
|
|
|
|
|
// Make sure all custom command outputs in this target are built.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CustomCommandDriver == OnBuild) {
|
2006-09-29 00:40:35 +04:00
|
|
|
this->DriveCustomCommands(depends);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-02-15 19:22:23 +03:00
|
|
|
|
|
|
|
// Make sure the extra files are built.
|
2016-05-16 17:34:04 +03:00
|
|
|
depends.insert(depends.end(), this->ExtraFiles.begin(),
|
|
|
|
this->ExtraFiles.end());
|
|
|
|
}
|
2006-06-01 19:45:51 +04:00
|
|
|
|
|
|
|
// Write the driver rule.
|
|
|
|
std::vector<std::string> no_commands;
|
|
|
|
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, comment,
|
2016-05-16 17:34:04 +03:00
|
|
|
buildTargetRuleName, depends,
|
|
|
|
no_commands, true);
|
2006-06-01 19:45:51 +04:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::AppendTargetDepends(
|
|
|
|
std::vector<std::string>& depends)
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
|
|
|
// Static libraries never depend on anything for linking.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY) {
|
2006-02-14 18:36:04 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
|
|
|
|
// Loop over all library dependencies.
|
2015-07-08 18:21:55 +03:00
|
|
|
const char* cfg = this->LocalGenerator->GetConfigName().c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmComputeLinkInformation* cli =
|
|
|
|
this->GeneratorTarget->GetLinkInformation(cfg)) {
|
2008-05-22 03:57:35 +04:00
|
|
|
std::vector<std::string> const& libDeps = cli->GetDepends();
|
2014-11-22 13:00:45 +03:00
|
|
|
depends.insert(depends.end(), libDeps.begin(), libDeps.end());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-14 18:36:04 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::AppendObjectDepends(
|
|
|
|
std::vector<std::string>& depends)
|
2010-11-05 15:33:47 +03:00
|
|
|
{
|
|
|
|
// Add dependencies on the compiled object files.
|
|
|
|
std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
|
|
|
|
std::string objTarget;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator obj = this->Objects.begin();
|
|
|
|
obj != this->Objects.end(); ++obj) {
|
2010-11-05 15:33:47 +03:00
|
|
|
objTarget = relPath;
|
|
|
|
objTarget += *obj;
|
|
|
|
depends.push_back(objTarget);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-05 15:33:47 +03:00
|
|
|
|
2012-03-12 18:54:37 +04:00
|
|
|
// Add dependencies on the external object files.
|
2016-05-16 17:34:04 +03:00
|
|
|
depends.insert(depends.end(), this->ExternalObjects.begin(),
|
|
|
|
this->ExternalObjects.end());
|
2010-11-05 15:33:47 +03:00
|
|
|
|
|
|
|
// Add a dependency on the rule file itself.
|
|
|
|
this->LocalGenerator->AppendRuleDepend(depends,
|
|
|
|
this->BuildFileNameFull.c_str());
|
2012-03-12 18:54:37 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::AppendLinkDepends(
|
|
|
|
std::vector<std::string>& depends)
|
2012-03-12 18:54:37 +04:00
|
|
|
{
|
|
|
|
this->AppendObjectDepends(depends);
|
|
|
|
|
|
|
|
// Add dependencies on targets that must be built first.
|
|
|
|
this->AppendTargetDepends(depends);
|
2010-11-05 15:33:47 +03:00
|
|
|
|
2010-12-15 19:30:57 +03:00
|
|
|
// Add a dependency on the link definitions file, if any.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->ModuleDefinitionFile) {
|
2015-11-02 17:24:25 +03:00
|
|
|
depends.push_back(this->ModuleDefinitionFile->GetFullPath());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-12-15 19:30:57 +03:00
|
|
|
|
2015-09-16 17:24:16 +03:00
|
|
|
// Add a dependency on user-specified manifest files, if any.
|
|
|
|
std::vector<cmSourceFile const*> manifest_srcs;
|
|
|
|
this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
|
|
|
|
for (std::vector<cmSourceFile const*>::iterator mi = manifest_srcs.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
mi != manifest_srcs.end(); ++mi) {
|
2015-09-16 17:24:16 +03:00
|
|
|
depends.push_back((*mi)->GetFullPath());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-16 17:24:16 +03:00
|
|
|
|
2010-11-05 16:05:08 +03:00
|
|
|
// Add user-specified dependencies.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* linkDepends =
|
|
|
|
this->GeneratorTarget->GetProperty("LINK_DEPENDS")) {
|
2010-11-05 16:05:08 +03:00
|
|
|
cmSystemTools::ExpandListArgument(linkDepends, depends);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-05 15:33:47 +03:00
|
|
|
}
|
|
|
|
|
2014-02-05 01:06:56 +04:00
|
|
|
std::string cmMakefileTargetGenerator::GetLinkRule(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& linkRuleVar)
|
2011-12-06 01:28:03 +04:00
|
|
|
{
|
|
|
|
std::string linkRule = this->Makefile->GetRequiredDefinition(linkRuleVar);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->GeneratorTarget->HasImplibGNUtoMS()) {
|
2011-12-06 01:39:07 +04:00
|
|
|
std::string ruleVar = "CMAKE_";
|
2015-08-04 20:19:49 +03:00
|
|
|
ruleVar += this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
|
2011-12-06 01:39:07 +04:00
|
|
|
ruleVar += "_GNUtoMS_RULE";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* rule = this->Makefile->GetDefinition(ruleVar)) {
|
2011-12-06 01:39:07 +04:00
|
|
|
linkRule += rule;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-12-06 01:28:03 +04:00
|
|
|
return linkRule;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::CloseFileStreams()
|
2006-02-14 18:36:04 +03:00
|
|
|
{
|
|
|
|
delete this->BuildFileStream;
|
|
|
|
delete this->InfoFileStream;
|
|
|
|
delete this->FlagFileStream;
|
|
|
|
}
|
2006-03-14 22:03:16 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::RemoveForbiddenFlags(
|
|
|
|
const char* flagVar, const std::string& linkLang, std::string& linkFlags)
|
2006-03-14 22:03:16 +03:00
|
|
|
{
|
|
|
|
// check for language flags that are not allowed at link time, and
|
|
|
|
// remove them, -w on darwin for gcc -w -dynamiclib sends -w to libtool
|
|
|
|
// which fails, there may be more]
|
2006-07-10 15:52:35 +04:00
|
|
|
|
2006-03-14 22:03:16 +03:00
|
|
|
std::string removeFlags = "CMAKE_";
|
|
|
|
removeFlags += linkLang;
|
|
|
|
removeFlags += flagVar;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string removeflags = this->Makefile->GetSafeDefinition(removeFlags);
|
2006-03-14 22:03:16 +03:00
|
|
|
std::vector<std::string> removeList;
|
|
|
|
cmSystemTools::ExpandListArgument(removeflags, removeList);
|
2013-11-16 00:41:11 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator i = removeList.begin();
|
|
|
|
i != removeList.end(); ++i) {
|
2013-11-16 00:41:11 +04:00
|
|
|
std::string tmp;
|
|
|
|
std::string::size_type lastPosition = 0;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (;;) {
|
2013-11-16 00:41:11 +04:00
|
|
|
std::string::size_type position = linkFlags.find(*i, lastPosition);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (position == std::string::npos) {
|
2013-11-16 00:41:11 +04:00
|
|
|
tmp += linkFlags.substr(lastPosition);
|
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-11-16 00:41:11 +04:00
|
|
|
std::string::size_type prefixLength = position - lastPosition;
|
|
|
|
tmp += linkFlags.substr(lastPosition, prefixLength);
|
|
|
|
lastPosition = position + i->length();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool validFlagStart =
|
|
|
|
position == 0 || isspace(linkFlags[position - 1]);
|
2013-11-16 00:41:11 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool validFlagEnd =
|
|
|
|
lastPosition == linkFlags.size() || isspace(linkFlags[lastPosition]);
|
2013-11-16 00:41:11 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!validFlagStart || !validFlagEnd) {
|
2013-11-16 00:41:11 +04:00
|
|
|
tmp += *i;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-11-16 00:41:11 +04:00
|
|
|
|
|
|
|
linkFlags = tmp;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-14 22:03:16 +03:00
|
|
|
}
|
2006-07-11 17:55:27 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::CreateLinkScript(
|
|
|
|
const char* name, std::vector<std::string> const& link_commands,
|
|
|
|
std::vector<std::string>& makefile_commands,
|
|
|
|
std::vector<std::string>& makefile_depends)
|
2007-12-28 22:59:06 +03:00
|
|
|
{
|
|
|
|
// Create the link script file.
|
|
|
|
std::string linkScriptName = this->TargetBuildDirectoryFull;
|
|
|
|
linkScriptName += "/";
|
|
|
|
linkScriptName += name;
|
|
|
|
cmGeneratedFileStream linkScriptStream(linkScriptName.c_str());
|
2008-02-20 22:56:29 +03:00
|
|
|
linkScriptStream.SetCopyIfDifferent(true);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator cmd = link_commands.begin();
|
|
|
|
cmd != link_commands.end(); ++cmd) {
|
2007-12-28 22:59:06 +03:00
|
|
|
// Do not write out empty commands or commands beginning in the
|
|
|
|
// shell no-op ":".
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmd->empty() && (*cmd)[0] != ':') {
|
2007-12-28 22:59:06 +03:00
|
|
|
linkScriptStream << *cmd << "\n";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-28 22:59:06 +03:00
|
|
|
|
|
|
|
// Create the makefile command to invoke the link script.
|
|
|
|
std::string link_command = "$(CMAKE_COMMAND) -E cmake_link_script ";
|
2016-08-27 19:52:40 +03:00
|
|
|
link_command += this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
this->LocalGenerator->ConvertToRelativePath(
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory(), linkScriptName),
|
|
|
|
cmOutputConverter::SHELL);
|
2007-12-28 22:59:06 +03:00
|
|
|
link_command += " --verbose=$(VERBOSE)";
|
|
|
|
makefile_commands.push_back(link_command);
|
2008-02-20 22:56:29 +03:00
|
|
|
makefile_depends.push_back(linkScriptName);
|
2007-12-28 22:59:06 +03:00
|
|
|
}
|
2007-12-31 00:11:38 +03:00
|
|
|
|
2016-07-20 21:57:18 +03:00
|
|
|
static size_t calculateCommandLineLengthLimit()
|
|
|
|
{
|
|
|
|
#if defined(_SC_ARG_MAX)
|
|
|
|
return ((size_t)sysconf(_SC_ARG_MAX)) - 1000;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-07-20 21:39:38 +03:00
|
|
|
bool cmMakefileTargetGenerator::CheckUseResponseFileForObjects(
|
|
|
|
std::string const& l) const
|
|
|
|
{
|
|
|
|
// Check for an explicit setting one way or the other.
|
|
|
|
std::string const responseVar =
|
|
|
|
"CMAKE_" + l + "_USE_RESPONSE_FILE_FOR_OBJECTS";
|
|
|
|
if (const char* val = this->Makefile->GetDefinition(responseVar)) {
|
|
|
|
if (*val) {
|
|
|
|
return cmSystemTools::IsOn(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-20 21:57:18 +03:00
|
|
|
// Check for a system limit.
|
|
|
|
if (size_t const limit = calculateCommandLineLengthLimit()) {
|
|
|
|
// Compute the total length of our list of object files with room
|
|
|
|
// for argument separation and quoting. This does not convert paths
|
2016-08-27 19:52:40 +03:00
|
|
|
// relative to CMAKE_CURRENT_BINARY_DIR like the final list will be, so the
|
|
|
|
// actual list will likely be much shorter than this. However, in the
|
|
|
|
// worst case all objects will remain as absolute paths.
|
2016-07-20 21:57:18 +03:00
|
|
|
size_t length = 0;
|
|
|
|
for (std::vector<std::string>::const_iterator i = this->Objects.begin();
|
|
|
|
i != this->Objects.end(); ++i) {
|
|
|
|
length += i->size() + 3;
|
|
|
|
}
|
|
|
|
for (std::vector<std::string>::const_iterator i =
|
|
|
|
this->ExternalObjects.begin();
|
|
|
|
i != this->ExternalObjects.end(); ++i) {
|
|
|
|
length += i->size() + 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to guarantee room for both objects and libraries, so
|
|
|
|
// if the objects take up more than half then use a response file
|
|
|
|
// for them.
|
|
|
|
if (length > (limit / 2)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-20 21:39:38 +03:00
|
|
|
// We do not need a response file for objects.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmMakefileTargetGenerator::CheckUseResponseFileForLibraries(
|
|
|
|
std::string const& l) const
|
|
|
|
{
|
|
|
|
// Check for an explicit setting one way or the other.
|
|
|
|
std::string const responseVar =
|
|
|
|
"CMAKE_" + l + "_USE_RESPONSE_FILE_FOR_LIBRARIES";
|
|
|
|
if (const char* val = this->Makefile->GetDefinition(responseVar)) {
|
|
|
|
if (*val) {
|
|
|
|
return cmSystemTools::IsOn(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We do not need a response file for libraries.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmMakefileTargetGenerator::CreateResponseFile(
|
|
|
|
const char* name, std::string const& options,
|
|
|
|
std::vector<std::string>& makefile_depends)
|
2008-02-28 01:10:45 +03:00
|
|
|
{
|
|
|
|
// Create the response file.
|
|
|
|
std::string responseFileNameFull = this->TargetBuildDirectoryFull;
|
|
|
|
responseFileNameFull += "/";
|
|
|
|
responseFileNameFull += name;
|
|
|
|
cmGeneratedFileStream responseStream(responseFileNameFull.c_str());
|
2008-04-03 19:11:54 +04:00
|
|
|
responseStream.SetCopyIfDifferent(true);
|
2008-02-28 01:10:45 +03:00
|
|
|
responseStream << options << "\n";
|
|
|
|
|
|
|
|
// Add a dependency so the target will rebuild when the set of
|
|
|
|
// objects changes.
|
|
|
|
makefile_depends.push_back(responseFileNameFull);
|
|
|
|
|
|
|
|
// Construct the name to be used on the command line.
|
|
|
|
std::string responseFileName = this->TargetBuildDirectory;
|
|
|
|
responseFileName += "/";
|
|
|
|
responseFileName += name;
|
|
|
|
return responseFileName;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::CreateLinkLibs(
|
|
|
|
std::string& linkLibs, bool relink, bool useResponseFile,
|
|
|
|
std::vector<std::string>& makefile_depends, bool useWatcomQuote)
|
2014-03-04 20:20:27 +04:00
|
|
|
{
|
|
|
|
std::string frameworkPath;
|
|
|
|
std::string linkPath;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerator->OutputLinkLibraries(linkLibs, frameworkPath, linkPath,
|
|
|
|
*this->GeneratorTarget, relink,
|
|
|
|
useResponseFile, useWatcomQuote);
|
2014-03-04 20:20:27 +04:00
|
|
|
linkLibs = frameworkPath + linkPath + linkLibs;
|
2014-03-04 22:25:42 +04:00
|
|
|
|
2016-05-24 22:24:10 +03:00
|
|
|
if (useResponseFile && linkLibs.find_first_not_of(' ') != linkLibs.npos) {
|
2014-03-04 22:25:42 +04:00
|
|
|
// Lookup the response file reference flag.
|
|
|
|
std::string responseFlagVar = "CMAKE_";
|
2016-05-16 17:34:04 +03:00
|
|
|
responseFlagVar +=
|
|
|
|
this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
|
2014-03-04 22:25:42 +04:00
|
|
|
responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* responseFlag = this->Makefile->GetDefinition(responseFlagVar);
|
|
|
|
if (!responseFlag) {
|
2014-03-04 22:25:42 +04:00
|
|
|
responseFlag = "@";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-04 22:25:42 +04:00
|
|
|
|
|
|
|
// Create this response file.
|
|
|
|
std::string link_rsp =
|
|
|
|
this->CreateResponseFile("linklibs.rsp", linkLibs, makefile_depends);
|
|
|
|
|
|
|
|
// Reference the response file.
|
|
|
|
linkLibs = responseFlag;
|
2016-08-27 14:44:55 +03:00
|
|
|
linkLibs += this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
link_rsp, cmOutputConverter::SHELL);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-04 20:20:27 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmMakefileTargetGenerator::CreateObjectLists(
|
|
|
|
bool useLinkScript, bool useArchiveRules, bool useResponseFile,
|
|
|
|
std::string& buildObjs, std::vector<std::string>& makefile_depends,
|
|
|
|
bool useWatcomQuote)
|
2008-10-15 18:21:14 +04:00
|
|
|
{
|
|
|
|
std::string variableName;
|
|
|
|
std::string variableNameExternal;
|
2014-03-25 10:17:45 +04:00
|
|
|
this->WriteObjectsVariable(variableName, variableNameExternal,
|
|
|
|
useWatcomQuote);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (useResponseFile) {
|
2008-10-15 18:21:21 +04:00
|
|
|
// MSVC response files cannot exceed 128K.
|
|
|
|
std::string::size_type const responseFileLimit = 131000;
|
|
|
|
|
|
|
|
// Construct the individual object list strings.
|
|
|
|
std::vector<std::string> object_strings;
|
|
|
|
this->WriteObjectsStrings(object_strings, responseFileLimit);
|
|
|
|
|
2010-03-11 17:03:26 +03:00
|
|
|
// Lookup the response file reference flag.
|
|
|
|
std::string responseFlagVar = "CMAKE_";
|
2016-05-16 17:34:04 +03:00
|
|
|
responseFlagVar +=
|
|
|
|
this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
|
2010-03-11 17:03:26 +03:00
|
|
|
responseFlagVar += "_RESPONSE_FILE_LINK_FLAG";
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* responseFlag = this->Makefile->GetDefinition(responseFlagVar);
|
|
|
|
if (!responseFlag) {
|
2010-03-11 17:03:26 +03:00
|
|
|
responseFlag = "@";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-03-11 17:03:26 +03:00
|
|
|
|
2008-10-15 18:21:21 +04:00
|
|
|
// Write a response file for each string.
|
|
|
|
const char* sep = "";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 0; i < object_strings.size(); ++i) {
|
2008-10-15 18:21:21 +04:00
|
|
|
// Number the response files.
|
|
|
|
char rsp[32];
|
2016-05-16 17:34:04 +03:00
|
|
|
sprintf(rsp, "objects%u.rsp", i + 1);
|
2008-10-15 18:21:21 +04:00
|
|
|
|
|
|
|
// Create this response file.
|
|
|
|
std::string objects_rsp =
|
|
|
|
this->CreateResponseFile(rsp, object_strings[i], makefile_depends);
|
|
|
|
|
|
|
|
// Separate from previous response file references.
|
|
|
|
buildObjs += sep;
|
|
|
|
sep = " ";
|
|
|
|
|
|
|
|
// Reference the response file.
|
2010-03-11 17:03:26 +03:00
|
|
|
buildObjs += responseFlag;
|
2016-08-27 14:44:55 +03:00
|
|
|
buildObjs += this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
objects_rsp, cmOutputConverter::SHELL);
|
2008-10-15 18:21:14 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (useLinkScript) {
|
|
|
|
if (!useArchiveRules) {
|
2008-10-15 18:21:14 +04:00
|
|
|
this->WriteObjectsString(buildObjs);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-10-15 18:21:14 +04:00
|
|
|
buildObjs = "$(";
|
|
|
|
buildObjs += variableName;
|
|
|
|
buildObjs += ") $(";
|
|
|
|
buildObjs += variableNameExternal;
|
|
|
|
buildObjs += ")";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-10-15 18:21:14 +04:00
|
|
|
}
|
|
|
|
|
2011-03-15 21:07:36 +03:00
|
|
|
void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags,
|
2014-02-04 06:20:56 +04:00
|
|
|
const std::string& lang)
|
2011-03-15 21:07:36 +03:00
|
|
|
{
|
|
|
|
std::string responseVar = "CMAKE_";
|
|
|
|
responseVar += lang;
|
|
|
|
responseVar += "_USE_RESPONSE_FILE_FOR_INCLUDES";
|
2014-03-11 03:04:11 +04:00
|
|
|
bool useResponseFile = this->Makefile->IsOn(responseVar);
|
2011-03-15 21:07:36 +03:00
|
|
|
|
2011-12-04 19:36:48 +04:00
|
|
|
std::vector<std::string> includes;
|
2014-02-10 07:48:34 +04:00
|
|
|
const std::string& config =
|
|
|
|
this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
|
2016-05-16 17:34:04 +03:00
|
|
|
this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
|
2012-10-15 12:42:42 +04:00
|
|
|
lang, config);
|
2011-12-04 19:36:48 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string includeFlags = this->LocalGenerator->GetIncludeFlags(
|
|
|
|
includes, this->GeneratorTarget, lang, false, useResponseFile, config);
|
|
|
|
if (includeFlags.empty()) {
|
2011-03-15 21:07:36 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-03-15 21:07:36 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (useResponseFile) {
|
2011-03-15 21:07:36 +03:00
|
|
|
std::string name = "includes_";
|
|
|
|
name += lang;
|
|
|
|
name += ".rsp";
|
|
|
|
std::string arg = "@" +
|
|
|
|
this->CreateResponseFile(name.c_str(), includeFlags,
|
|
|
|
this->FlagFileDepends[lang]);
|
2014-05-02 00:07:26 +04:00
|
|
|
this->LocalGenerator->AppendFlags(flags, arg);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-05-02 00:07:26 +04:00
|
|
|
this->LocalGenerator->AppendFlags(flags, includeFlags);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-03-15 21:07:36 +03:00
|
|
|
}
|
2016-07-10 20:24:43 +03:00
|
|
|
|
|
|
|
void cmMakefileTargetGenerator::GenDefFile(
|
|
|
|
std::vector<std::string>& real_link_commands, std::string& linkFlags)
|
|
|
|
{
|
|
|
|
if (this->GeneratorTarget->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS")) {
|
|
|
|
std::string name_of_def_file =
|
|
|
|
this->GeneratorTarget->GetSupportDirectory();
|
|
|
|
name_of_def_file += std::string("/") + this->GeneratorTarget->GetName();
|
|
|
|
name_of_def_file += ".def";
|
|
|
|
std::string cmd = cmSystemTools::GetCMakeCommand();
|
2016-08-27 14:44:55 +03:00
|
|
|
cmd = this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
cmd, cmOutputConverter::SHELL);
|
2016-07-10 20:24:43 +03:00
|
|
|
cmd += " -E __create_def ";
|
2016-08-27 19:52:40 +03:00
|
|
|
cmd += this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
this->LocalGenerator->ConvertToRelativePath(
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory(), name_of_def_file),
|
|
|
|
cmOutputConverter::SHELL);
|
2016-07-10 20:24:43 +03:00
|
|
|
cmd += " ";
|
|
|
|
std::string objlist_file = name_of_def_file;
|
|
|
|
objlist_file += ".objs";
|
2016-08-27 19:52:40 +03:00
|
|
|
cmd += this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
this->LocalGenerator->ConvertToRelativePath(
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory(), objlist_file),
|
|
|
|
cmOutputConverter::SHELL);
|
2016-07-10 20:24:43 +03:00
|
|
|
real_link_commands.insert(real_link_commands.begin(), cmd);
|
|
|
|
// create a list of obj files for the -E __create_def to read
|
|
|
|
cmGeneratedFileStream fout(objlist_file.c_str());
|
|
|
|
for (std::vector<std::string>::const_iterator i = this->Objects.begin();
|
|
|
|
i != this->Objects.end(); ++i) {
|
|
|
|
if (cmHasLiteralSuffix(*i, ".obj")) {
|
|
|
|
fout << *i << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (std::vector<std::string>::const_iterator i =
|
|
|
|
this->ExternalObjects.begin();
|
|
|
|
i != this->ExternalObjects.end(); ++i) {
|
|
|
|
fout << *i << "\n";
|
|
|
|
}
|
|
|
|
// now add the def file link flag
|
|
|
|
linkFlags += " ";
|
|
|
|
linkFlags += this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
|
2016-08-27 19:52:40 +03:00
|
|
|
linkFlags += this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
this->LocalGenerator->ConvertToRelativePath(
|
|
|
|
this->LocalGenerator->GetCurrentBinaryDirectory(), name_of_def_file),
|
|
|
|
cmOutputConverter::SHELL);
|
2016-07-10 20:24:43 +03:00
|
|
|
linkFlags += " ";
|
|
|
|
}
|
|
|
|
}
|