2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2005-05-05 20:45:53 +04: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.
|
2005-05-05 20:45:53 +04: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.
|
|
|
|
============================================================================*/
|
2005-05-05 20:45:53 +04:00
|
|
|
#include "cmLocalUnixMakefileGenerator3.h"
|
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmAlgorithms.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmCustomCommand.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmCustomCommandGenerator.h"
|
|
|
|
#include "cmFileTimeComparison.h"
|
2005-05-05 20:45:53 +04:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmGeneratorTarget.h"
|
|
|
|
#include "cmGlobalGenerator.h"
|
2005-07-27 17:49:37 +04:00
|
|
|
#include "cmGlobalUnixMakefileGenerator3.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
2005-05-05 20:45:53 +04:00
|
|
|
#include "cmMakefile.h"
|
2006-02-15 18:34:11 +03:00
|
|
|
#include "cmMakefileTargetGenerator.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmOutputConverter.h"
|
2005-05-05 20:45:53 +04:00
|
|
|
#include "cmSourceFile.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmState.h"
|
|
|
|
#include "cmSystemTools.h"
|
2006-11-29 23:59:16 +03:00
|
|
|
#include "cmVersion.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmake.h"
|
2005-05-05 20:45:53 +04:00
|
|
|
|
|
|
|
// Include dependency scanners for supported languages. Only the
|
|
|
|
// C/C++ scanner is needed for bootstrapping CMake.
|
|
|
|
#include "cmDependsC.h"
|
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2016-05-16 17:34:04 +03:00
|
|
|
#include "cmDependsFortran.h"
|
|
|
|
#include "cmDependsJava.h"
|
2005-05-05 20:45:53 +04:00
|
|
|
#endif
|
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <algorithm>
|
2016-06-28 17:17:52 +03:00
|
|
|
#include <cm_auto_ptr.hxx>
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <cmsys/FStream.hxx>
|
2015-02-06 00:29:59 +03:00
|
|
|
#include <cmsys/Terminal.h>
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <functional>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <utility>
|
2005-05-05 20:45:53 +04:00
|
|
|
|
2012-06-06 16:30:54 +04:00
|
|
|
// Escape special characters in Makefile dependency lines
|
|
|
|
class cmMakeSafe
|
|
|
|
{
|
|
|
|
public:
|
2016-05-16 17:34:04 +03:00
|
|
|
cmMakeSafe(const char* s)
|
|
|
|
: Data(s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
cmMakeSafe(std::string const& s)
|
|
|
|
: Data(s.c_str())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-06 16:30:54 +04:00
|
|
|
private:
|
|
|
|
const char* Data;
|
2016-05-16 17:34:04 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream& os, cmMakeSafe const& self)
|
|
|
|
{
|
|
|
|
for (const char* c = self.Data; *c; ++c) {
|
|
|
|
switch (*c) {
|
|
|
|
case '=':
|
|
|
|
os << "$(EQUALS)";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os << *c;
|
|
|
|
break;
|
2012-06-06 16:30:54 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return os;
|
|
|
|
}
|
2012-06-06 16:30:54 +04:00
|
|
|
};
|
|
|
|
|
2008-01-08 00:12:37 +03:00
|
|
|
// Helper function used below.
|
|
|
|
static std::string cmSplitExtension(std::string const& in, std::string& base)
|
|
|
|
{
|
|
|
|
std::string ext;
|
2016-05-24 22:24:10 +03:00
|
|
|
std::string::size_type dot_pos = in.rfind('.');
|
2016-05-16 17:34:04 +03:00
|
|
|
if (dot_pos != std::string::npos) {
|
2008-01-08 00:12:37 +03:00
|
|
|
// Remove the extension first in case &base == &in.
|
|
|
|
ext = in.substr(dot_pos, std::string::npos);
|
|
|
|
base = in.substr(0, dot_pos);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-01-08 00:12:37 +03:00
|
|
|
base = in;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-08 00:12:37 +03:00
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3(
|
|
|
|
cmGlobalGenerator* gg, cmMakefile* mf)
|
2016-06-16 17:54:20 +03:00
|
|
|
: cmLocalCommonGenerator(gg, mf, cmOutputConverter::START_OUTPUT)
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->MakefileVariableSize = 0;
|
2006-05-25 22:16:19 +04:00
|
|
|
this->ColorMakefile = false;
|
2006-08-09 17:56:52 +04:00
|
|
|
this->SkipPreprocessedSourceRules = false;
|
|
|
|
this->SkipAssemblySourceRules = false;
|
2007-03-08 21:05:02 +03:00
|
|
|
this->MakeCommandEscapeTargetTwice = false;
|
2007-05-17 18:53:18 +04:00
|
|
|
this->BorlandMakeCurlyHack = false;
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-30 20:12:38 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::Generate()
|
2005-06-01 21:37:49 +04:00
|
|
|
{
|
2015-07-08 18:27:22 +03:00
|
|
|
this->SetConfigName();
|
2005-05-05 20:45:53 +04:00
|
|
|
|
2006-08-09 17:56:52 +04:00
|
|
|
// Record whether some options are enabled to avoid checking many
|
2006-05-25 22:16:19 +04:00
|
|
|
// times later.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile()) {
|
2009-07-21 19:58:43 +04:00
|
|
|
this->ColorMakefile = this->Makefile->IsOn("CMAKE_COLOR_MAKEFILE");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-08-09 17:56:52 +04:00
|
|
|
this->SkipPreprocessedSourceRules =
|
|
|
|
this->Makefile->IsOn("CMAKE_SKIP_PREPROCESSED_SOURCE_RULES");
|
|
|
|
this->SkipAssemblySourceRules =
|
|
|
|
this->Makefile->IsOn("CMAKE_SKIP_ASSEMBLY_SOURCE_RULES");
|
2006-05-25 22:16:19 +04:00
|
|
|
|
2005-05-05 20:45:53 +04:00
|
|
|
// Generate the rule files for each target.
|
2015-10-18 17:53:00 +03:00
|
|
|
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
|
2009-06-25 17:58:51 +04:00
|
|
|
cmGlobalUnixMakefileGenerator3* gg =
|
|
|
|
static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
|
|
|
|
t != targets.end(); ++t) {
|
|
|
|
if ((*t)->GetType() == cmState::INTERFACE_LIBRARY) {
|
2012-10-10 23:32:37 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-06-28 17:17:52 +03:00
|
|
|
CM_AUTO_PTR<cmMakefileTargetGenerator> tg(
|
2015-10-18 17:53:00 +03:00
|
|
|
cmMakefileTargetGenerator::New(*t));
|
2016-05-16 17:34:04 +03:00
|
|
|
if (tg.get()) {
|
2006-02-15 18:34:11 +03:00
|
|
|
tg->WriteRuleFiles();
|
2009-06-25 17:58:51 +04:00
|
|
|
gg->RecordTargetProgress(tg.get());
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
|
2005-05-11 16:45:16 +04:00
|
|
|
// write the local Makefile
|
|
|
|
this->WriteLocalMakefile();
|
2010-11-12 00:02:07 +03:00
|
|
|
|
2005-05-06 22:49:38 +04:00
|
|
|
// Write the cmake file with information for this directory.
|
|
|
|
this->WriteDirectoryInformationFile();
|
2006-07-11 17:55:27 +04:00
|
|
|
}
|
|
|
|
|
2015-06-13 09:38:27 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::ComputeHomeRelativeOutputPath()
|
|
|
|
{
|
|
|
|
// Compute the path to use when referencing the current output
|
|
|
|
// directory from the top output directory.
|
2016-08-27 14:44:56 +03:00
|
|
|
this->HomeRelativeOutputPath = this->ConvertToRelativePath(
|
2016-05-20 00:11:40 +03:00
|
|
|
this->GetCurrentBinaryDirectory(), cmOutputConverter::HOME_OUTPUT);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->HomeRelativeOutputPath == ".") {
|
2015-06-13 09:38:27 +03:00
|
|
|
this->HomeRelativeOutputPath = "";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!this->HomeRelativeOutputPath.empty()) {
|
2015-06-13 09:38:27 +03:00
|
|
|
this->HomeRelativeOutputPath += "/";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-06-13 09:38:27 +03:00
|
|
|
}
|
|
|
|
|
2014-03-11 20:37:26 +04:00
|
|
|
void cmLocalUnixMakefileGenerator3::ComputeObjectFilenames(
|
2016-05-16 17:34:04 +03:00
|
|
|
std::map<cmSourceFile const*, std::string>& mapping,
|
|
|
|
cmGeneratorTarget const* gt)
|
2014-03-11 20:37:26 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::map<cmSourceFile const*, std::string>::iterator si =
|
|
|
|
mapping.begin();
|
|
|
|
si != mapping.end(); ++si) {
|
2014-03-11 20:37:26 +04:00
|
|
|
cmSourceFile const* sf = si->first;
|
2016-05-16 17:34:04 +03:00
|
|
|
si->second =
|
|
|
|
this->GetObjectFileNameWithoutTarget(*sf, gt->ObjectDirectory);
|
|
|
|
}
|
2014-03-11 20:37:26 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles(
|
|
|
|
std::map<std::string, LocalObjectInfo>& localObjectFiles)
|
2012-03-06 23:42:40 +04:00
|
|
|
{
|
2015-10-18 17:53:00 +03:00
|
|
|
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
|
|
|
|
ti != targets.end(); ++ti) {
|
2015-10-18 17:53:00 +03:00
|
|
|
cmGeneratorTarget* gt = *ti;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (gt->GetType() == cmState::INTERFACE_LIBRARY) {
|
2014-03-11 19:35:58 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-13 02:06:05 +04:00
|
|
|
std::vector<cmSourceFile const*> objectSources;
|
2016-05-16 17:34:04 +03:00
|
|
|
gt->GetObjectSources(
|
|
|
|
objectSources, this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
|
2014-03-11 19:35:58 +04:00
|
|
|
// Compute full path to object file directory for this target.
|
2014-03-17 18:27:01 +04:00
|
|
|
std::string dir;
|
2015-10-21 20:59:12 +03:00
|
|
|
dir += gt->LocalGenerator->GetCurrentBinaryDirectory();
|
2014-03-17 18:27:01 +04:00
|
|
|
dir += "/";
|
2015-10-09 23:27:46 +03:00
|
|
|
dir += this->GetTargetDirectory(gt);
|
2014-03-17 18:27:01 +04:00
|
|
|
dir += "/";
|
2014-03-11 19:35:58 +04:00
|
|
|
// Compute the name of each object file.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmSourceFile const*>::iterator si = objectSources.begin();
|
|
|
|
si != objectSources.end(); ++si) {
|
2014-03-13 02:06:05 +04:00
|
|
|
cmSourceFile const* sf = *si;
|
2014-03-11 19:35:58 +04:00
|
|
|
bool hasSourceExtension = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string objectName =
|
|
|
|
this->GetObjectFileNameWithoutTarget(*sf, dir, &hasSourceExtension);
|
|
|
|
if (cmSystemTools::FileIsFullPath(objectName.c_str())) {
|
2014-03-11 19:35:58 +04:00
|
|
|
objectName = cmSystemTools::GetFilenameName(objectName);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-11 19:35:58 +04:00
|
|
|
LocalObjectInfo& info = localObjectFiles[objectName];
|
|
|
|
info.HasSourceExtension = hasSourceExtension;
|
2015-10-15 01:11:21 +03:00
|
|
|
info.push_back(LocalObjectEntry(gt, sf->GetLanguage()));
|
2012-03-06 23:42:40 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-03-06 23:42:40 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::GetIndividualFileTargets(
|
|
|
|
std::vector<std::string>& targets)
|
2009-09-17 02:01:23 +04:00
|
|
|
{
|
2014-03-11 19:35:58 +04:00
|
|
|
std::map<std::string, LocalObjectInfo> localObjectFiles;
|
|
|
|
this->GetLocalObjectFiles(localObjectFiles);
|
2014-02-10 09:21:34 +04:00
|
|
|
for (std::map<std::string, LocalObjectInfo>::iterator lo =
|
2014-03-11 19:35:58 +04:00
|
|
|
localObjectFiles.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
lo != localObjectFiles.end(); ++lo) {
|
2009-09-17 02:01:23 +04:00
|
|
|
targets.push_back(lo->first);
|
|
|
|
|
|
|
|
std::string::size_type dot_pos = lo->first.rfind(".");
|
|
|
|
std::string base = lo->first.substr(0, dot_pos);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (lo->second.HasPreprocessRule) {
|
2009-09-17 02:01:23 +04:00
|
|
|
targets.push_back(base + ".i");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-17 02:01:23 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (lo->second.HasAssembleRule) {
|
2009-09-17 02:01:23 +04:00
|
|
|
targets.push_back(base + ".s");
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-17 02:01:23 +04:00
|
|
|
}
|
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
|
|
|
|
{
|
|
|
|
// generate the includes
|
|
|
|
std::string ruleFileName = "Makefile";
|
|
|
|
|
|
|
|
// Open the rule file. This should be copy-if-different because the
|
|
|
|
// rules may depend on this file itself.
|
|
|
|
std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
|
|
|
|
cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!ruleFileStream) {
|
2006-02-15 18:34:11 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
// always write the top makefile
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->IsRootMakefile()) {
|
2006-02-15 18:34:11 +03:00
|
|
|
ruleFileStream.SetCopyIfDifferent(true);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-12 00:02:07 +03:00
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
// write the all rules
|
|
|
|
this->WriteLocalAllRules(ruleFileStream);
|
2010-11-12 00:02:07 +03:00
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
// only write local targets unless at the top Keep track of targets already
|
|
|
|
// listed.
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> emittedTargets;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->IsRootMakefile()) {
|
2006-02-15 18:34:11 +03:00
|
|
|
// write our targets, and while doing it collect up the object
|
|
|
|
// file rules
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteLocalMakefileTargets(ruleFileStream, emittedTargets);
|
|
|
|
} else {
|
|
|
|
cmGlobalUnixMakefileGenerator3* gg =
|
2006-03-15 19:02:08 +03:00
|
|
|
static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
|
2016-05-16 17:34:04 +03:00
|
|
|
gg->WriteConvenienceRules(ruleFileStream, emittedTargets);
|
|
|
|
}
|
2006-08-08 07:25:21 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool do_preprocess_rules = this->GetCreatePreprocessedSourceRules();
|
|
|
|
bool do_assembly_rules = this->GetCreateAssemblySourceRules();
|
2006-08-08 07:25:21 +04:00
|
|
|
|
2014-03-11 19:35:58 +04:00
|
|
|
std::map<std::string, LocalObjectInfo> localObjectFiles;
|
|
|
|
this->GetLocalObjectFiles(localObjectFiles);
|
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
// now write out the object rules
|
|
|
|
// for each object file name
|
2014-02-10 09:21:34 +04:00
|
|
|
for (std::map<std::string, LocalObjectInfo>::iterator lo =
|
2014-03-11 19:35:58 +04:00
|
|
|
localObjectFiles.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
lo != localObjectFiles.end(); ++lo) {
|
2006-08-08 07:25:21 +04:00
|
|
|
// Add a convenience rule for building the object file.
|
2006-08-02 19:06:32 +04:00
|
|
|
this->WriteObjectConvenienceRule(ruleFileStream,
|
|
|
|
"target to build an object file",
|
|
|
|
lo->first.c_str(), lo->second);
|
2006-08-08 07:25:21 +04:00
|
|
|
|
2006-08-15 20:00:27 +04:00
|
|
|
// Check whether preprocessing and assembly rules make sense.
|
|
|
|
// They make sense only for C and C++ sources.
|
2014-11-05 21:37:25 +03:00
|
|
|
bool lang_has_preprocessor = false;
|
|
|
|
bool lang_has_assembly = false;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<LocalObjectEntry>::const_iterator ei = lo->second.begin();
|
|
|
|
ei != lo->second.end(); ++ei) {
|
|
|
|
if (ei->Language == "C" || ei->Language == "CXX" ||
|
|
|
|
ei->Language == "Fortran") {
|
2014-11-05 21:43:06 +03:00
|
|
|
// Right now, C, C++ and Fortran have both a preprocessor and the
|
2014-11-05 21:37:25 +03:00
|
|
|
// ability to generate assembly code
|
|
|
|
lang_has_preprocessor = true;
|
|
|
|
lang_has_assembly = true;
|
2011-11-05 19:17:23 +04:00
|
|
|
break;
|
2006-08-15 20:00:27 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-08-15 20:00:27 +04:00
|
|
|
|
2006-08-08 07:25:21 +04:00
|
|
|
// Add convenience rules for preprocessed and assembly files.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (lang_has_preprocessor && do_preprocess_rules) {
|
2006-08-08 07:25:21 +04:00
|
|
|
std::string::size_type dot_pos = lo->first.rfind(".");
|
|
|
|
std::string base = lo->first.substr(0, dot_pos);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteObjectConvenienceRule(ruleFileStream,
|
|
|
|
"target to preprocess a source file",
|
|
|
|
(base + ".i").c_str(), lo->second);
|
2014-11-05 21:37:25 +03:00
|
|
|
lo->second.HasPreprocessRule = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-11-05 21:37:25 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (lang_has_assembly && do_assembly_rules) {
|
2014-11-05 21:37:25 +03:00
|
|
|
std::string::size_type dot_pos = lo->first.rfind(".");
|
|
|
|
std::string base = lo->first.substr(0, dot_pos);
|
|
|
|
this->WriteObjectConvenienceRule(
|
2016-05-16 17:34:04 +03:00
|
|
|
ruleFileStream, "target to generate assembly for a file",
|
|
|
|
(base + ".s").c_str(), lo->second);
|
2014-11-05 21:37:25 +03:00
|
|
|
lo->second.HasAssembleRule = true;
|
2006-02-15 18:34:11 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
|
|
|
|
// add a help target as long as there isn;t a real target named help
|
2016-05-16 17:34:04 +03:00
|
|
|
if (emittedTargets.insert("help").second) {
|
|
|
|
cmGlobalUnixMakefileGenerator3* gg =
|
2006-03-15 19:02:08 +03:00
|
|
|
static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
|
2016-05-16 17:34:04 +03:00
|
|
|
gg->WriteHelpRule(ruleFileStream, this);
|
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
|
|
|
|
this->WriteSpecialTargetsBottom(ruleFileStream);
|
|
|
|
}
|
2005-05-06 22:49:38 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::WriteObjectConvenienceRule(
|
|
|
|
std::ostream& ruleFileStream, const char* comment, const char* output,
|
|
|
|
LocalObjectInfo const& info)
|
2006-08-02 19:06:32 +04:00
|
|
|
{
|
2008-01-08 00:12:37 +03:00
|
|
|
// If the rule includes the source file extension then create a
|
|
|
|
// version that has the extension removed. The help should include
|
|
|
|
// only the version without source extension.
|
|
|
|
bool inHelp = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (info.HasSourceExtension) {
|
2008-01-08 00:12:37 +03:00
|
|
|
// Remove the last extension. This should be kept.
|
|
|
|
std::string outBase1 = output;
|
|
|
|
std::string outExt1 = cmSplitExtension(outBase1, outBase1);
|
|
|
|
|
|
|
|
// Now remove the source extension and put back the last
|
|
|
|
// extension.
|
|
|
|
std::string outNoExt;
|
|
|
|
cmSplitExtension(outBase1, outNoExt);
|
|
|
|
outNoExt += outExt1;
|
|
|
|
|
|
|
|
// Add a rule to drive the rule below.
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
depends.push_back(output);
|
2008-01-14 17:20:58 +03:00
|
|
|
std::vector<std::string> no_commands;
|
2016-06-27 23:44:16 +03:00
|
|
|
this->WriteMakeRule(ruleFileStream, CM_NULLPTR, outNoExt, depends,
|
|
|
|
no_commands, true, true);
|
2008-01-08 00:12:37 +03:00
|
|
|
inHelp = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-08 00:12:37 +03:00
|
|
|
|
2006-08-02 19:06:32 +04:00
|
|
|
// Recursively make the rule for each target using the object file.
|
|
|
|
std::vector<std::string> commands;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<LocalObjectEntry>::const_iterator t = info.begin();
|
|
|
|
t != info.end(); ++t) {
|
|
|
|
std::string tgtMakefileName = this->GetRelativeTargetDirectory(t->Target);
|
2006-08-02 19:06:32 +04:00
|
|
|
std::string targetName = tgtMakefileName;
|
|
|
|
tgtMakefileName += "/build.make";
|
|
|
|
targetName += "/";
|
|
|
|
targetName += output;
|
|
|
|
commands.push_back(
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GetRecursiveMakeCall(tgtMakefileName.c_str(), targetName));
|
|
|
|
}
|
|
|
|
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->GetCurrentBinaryDirectory());
|
2006-08-02 19:06:32 +04:00
|
|
|
|
|
|
|
// Write the rule to the makefile.
|
|
|
|
std::vector<std::string> no_depends;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteMakeRule(ruleFileStream, comment, output, no_depends, commands,
|
|
|
|
true, inHelp);
|
2006-08-02 19:06:32 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets(
|
|
|
|
std::ostream& ruleFileStream, std::set<std::string>& emitted)
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
2006-02-15 18:34:11 +03:00
|
|
|
std::vector<std::string> depends;
|
|
|
|
std::vector<std::string> commands;
|
|
|
|
|
|
|
|
// for each target we just provide a rule to cd up to the top and do a make
|
|
|
|
// on the target
|
2015-10-18 17:53:00 +03:00
|
|
|
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
|
2006-02-15 18:34:11 +03:00
|
|
|
std::string localName;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
|
|
|
|
t != targets.end(); ++t) {
|
|
|
|
if (((*t)->GetType() == cmState::EXECUTABLE) ||
|
|
|
|
((*t)->GetType() == cmState::STATIC_LIBRARY) ||
|
|
|
|
((*t)->GetType() == cmState::SHARED_LIBRARY) ||
|
|
|
|
((*t)->GetType() == cmState::MODULE_LIBRARY) ||
|
|
|
|
((*t)->GetType() == cmState::OBJECT_LIBRARY) ||
|
|
|
|
((*t)->GetType() == cmState::UTILITY)) {
|
2015-10-18 17:53:00 +03:00
|
|
|
emitted.insert((*t)->GetName());
|
2006-02-15 18:34:11 +03:00
|
|
|
|
|
|
|
// for subdirs add a rule to build this specific target by name.
|
2015-10-18 17:53:00 +03:00
|
|
|
localName = this->GetRelativeTargetDirectory(*t);
|
2006-02-15 18:34:11 +03:00
|
|
|
localName += "/rule";
|
|
|
|
commands.clear();
|
|
|
|
depends.clear();
|
2010-11-12 00:02:07 +03:00
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
// Build the target for this pass.
|
2007-08-04 00:31:08 +04:00
|
|
|
std::string makefile2 = cmake::GetCMakeFilesDirectoryPostSlash();
|
|
|
|
makefile2 += "Makefile2";
|
2016-05-16 17:34:04 +03:00
|
|
|
commands.push_back(
|
|
|
|
this->GetRecursiveMakeCall(makefile2.c_str(), localName));
|
|
|
|
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->GetCurrentBinaryDirectory());
|
2006-02-15 18:34:11 +03:00
|
|
|
this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
|
2014-03-11 03:04:11 +04:00
|
|
|
localName, depends, commands, true);
|
2010-11-12 00:02:07 +03:00
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
// Add a target with the canonical name (no prefix, suffix or path).
|
2016-05-16 17:34:04 +03:00
|
|
|
if (localName != (*t)->GetName()) {
|
2006-02-15 18:34:11 +03:00
|
|
|
commands.clear();
|
|
|
|
depends.push_back(localName);
|
|
|
|
this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
|
2015-10-18 17:53:00 +03:00
|
|
|
(*t)->GetName(), depends, commands, true);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-06-01 22:09:21 +04:00
|
|
|
|
|
|
|
// Add a fast rule to build the target
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string makefileName = this->GetRelativeTargetDirectory(*t);
|
2006-06-01 22:09:21 +04:00
|
|
|
makefileName += "/build.make";
|
2007-02-19 22:25:45 +03:00
|
|
|
// make sure the makefile name is suitable for a makefile
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string makeTargetName = this->GetRelativeTargetDirectory(*t);
|
2006-06-01 22:09:21 +04:00
|
|
|
makeTargetName += "/build";
|
2015-10-18 17:53:00 +03:00
|
|
|
localName = (*t)->GetName();
|
2006-06-01 22:09:21 +04:00
|
|
|
localName += "/fast";
|
|
|
|
depends.clear();
|
|
|
|
commands.clear();
|
2016-05-16 17:34:04 +03:00
|
|
|
commands.push_back(
|
|
|
|
this->GetRecursiveMakeCall(makefileName.c_str(), makeTargetName));
|
|
|
|
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->GetCurrentBinaryDirectory());
|
2006-06-01 22:09:21 +04:00
|
|
|
this->WriteMakeRule(ruleFileStream, "fast build rule for target.",
|
2014-03-11 03:04:11 +04:00
|
|
|
localName, depends, commands, true);
|
2007-08-04 00:31:08 +04:00
|
|
|
|
|
|
|
// Add a local name for the rule to relink the target before
|
|
|
|
// installation.
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((*t)->NeedRelinkBeforeInstall(this->ConfigName)) {
|
2015-10-18 17:53:00 +03:00
|
|
|
makeTargetName = this->GetRelativeTargetDirectory(*t);
|
2007-08-04 00:31:08 +04:00
|
|
|
makeTargetName += "/preinstall";
|
2015-10-18 17:53:00 +03:00
|
|
|
localName = (*t)->GetName();
|
2007-08-04 00:31:08 +04:00
|
|
|
localName += "/preinstall";
|
|
|
|
depends.clear();
|
|
|
|
commands.clear();
|
2016-05-16 17:34:04 +03:00
|
|
|
commands.push_back(
|
|
|
|
this->GetRecursiveMakeCall(makefile2.c_str(), makeTargetName));
|
|
|
|
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->GetCurrentBinaryDirectory());
|
2007-08-04 00:31:08 +04:00
|
|
|
this->WriteMakeRule(ruleFileStream,
|
|
|
|
"Manual pre-install relink rule for target.",
|
2014-03-11 03:04:11 +04:00
|
|
|
localName, depends, commands, true);
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
|
2005-05-06 22:49:38 +04:00
|
|
|
void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile()
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
2015-10-22 01:29:36 +03:00
|
|
|
std::string infoFileName = this->GetCurrentBinaryDirectory();
|
2006-06-14 20:28:32 +04:00
|
|
|
infoFileName += cmake::GetCMakeFilesDirectory();
|
|
|
|
infoFileName += "/CMakeDirectoryInformation.cmake";
|
2005-05-05 20:45:53 +04:00
|
|
|
|
|
|
|
// Open the output file.
|
|
|
|
cmGeneratedFileStream infoFileStream(infoFileName.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!infoFileStream) {
|
2005-05-05 20:45:53 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
|
2009-09-22 22:40:23 +04:00
|
|
|
infoFileStream.SetCopyIfDifferent(true);
|
2005-05-05 20:45:53 +04:00
|
|
|
// Write the do not edit header.
|
|
|
|
this->WriteDisclaimer(infoFileStream);
|
|
|
|
|
2007-03-16 23:48:27 +03:00
|
|
|
// Setup relative path conversion tops.
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2007-03-16 23:48:27 +03:00
|
|
|
infoFileStream
|
|
|
|
<< "# Relative path conversion top directories.\n"
|
2015-05-05 00:30:29 +03:00
|
|
|
<< "set(CMAKE_RELATIVE_PATH_TOP_SOURCE \""
|
2015-07-18 20:11:05 +03:00
|
|
|
<< this->StateSnapshot.GetDirectory().GetRelativePathTopSource()
|
2007-03-16 23:48:27 +03:00
|
|
|
<< "\")\n"
|
2015-05-05 00:30:29 +03:00
|
|
|
<< "set(CMAKE_RELATIVE_PATH_TOP_BINARY \""
|
2015-07-18 20:11:05 +03:00
|
|
|
<< this->StateSnapshot.GetDirectory().GetRelativePathTopBinary()
|
2007-03-16 23:48:27 +03:00
|
|
|
<< "\")\n"
|
|
|
|
<< "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2007-03-16 23:48:27 +03:00
|
|
|
|
2005-05-05 20:45:53 +04:00
|
|
|
// Tell the dependency scanner to use unix paths if necessary.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::GetForceUnixPaths()) {
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2005-05-05 20:45:53 +04:00
|
|
|
infoFileStream
|
|
|
|
<< "# Force unix paths in dependencies.\n"
|
2013-08-22 13:30:19 +04:00
|
|
|
<< "set(CMAKE_FORCE_UNIX_PATHS 1)\n"
|
2005-05-05 20:45:53 +04:00
|
|
|
<< "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
|
|
|
|
// Store the include regular expressions for this directory.
|
2016-05-16 17:34:04 +03:00
|
|
|
infoFileStream << "\n"
|
|
|
|
<< "# The C and CXX include file regular expressions for "
|
|
|
|
<< "this directory.\n";
|
|
|
|
infoFileStream << "set(CMAKE_C_INCLUDE_REGEX_SCAN ";
|
2005-05-05 20:45:53 +04:00
|
|
|
this->WriteCMakeArgument(infoFileStream,
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->GetIncludeRegularExpression());
|
2016-05-16 17:34:04 +03:00
|
|
|
infoFileStream << ")\n";
|
|
|
|
infoFileStream << "set(CMAKE_C_INCLUDE_REGEX_COMPLAIN ";
|
2005-05-05 20:45:53 +04:00
|
|
|
this->WriteCMakeArgument(infoFileStream,
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->GetComplainRegularExpression());
|
2016-05-16 17:34:04 +03:00
|
|
|
infoFileStream << ")\n";
|
2005-05-05 20:45:53 +04:00
|
|
|
infoFileStream
|
2013-08-22 13:30:19 +04:00
|
|
|
<< "set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
infoFileStream << "set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN "
|
|
|
|
"${CMAKE_C_INCLUDE_REGEX_COMPLAIN})\n";
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmLocalUnixMakefileGenerator3::ConvertToFullPath(
|
|
|
|
const std::string& localPath)
|
2005-05-06 22:49:38 +04:00
|
|
|
{
|
2015-10-22 01:29:36 +03:00
|
|
|
std::string dir = this->GetCurrentBinaryDirectory();
|
2005-05-06 22:49:38 +04:00
|
|
|
dir += "/";
|
|
|
|
dir += localPath;
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& cmLocalUnixMakefileGenerator3::GetHomeRelativeOutputPath()
|
2005-06-01 21:37:49 +04:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
return this->HomeRelativeOutputPath;
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::WriteMakeRule(
|
|
|
|
std::ostream& os, const char* comment, const std::string& target,
|
|
|
|
const std::vector<std::string>& depends,
|
|
|
|
const std::vector<std::string>& commands, bool symbolic, bool in_help)
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
2006-02-15 18:34:11 +03:00
|
|
|
// Make sure there is a target.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target.empty()) {
|
2006-02-15 18:34:11 +03:00
|
|
|
cmSystemTools::Error("No target for WriteMakeRule! called with comment: ",
|
|
|
|
comment);
|
2005-07-27 17:49:37 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
|
|
|
|
std::string replace;
|
|
|
|
|
|
|
|
// Write the comment describing the rule in the makefile.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (comment) {
|
2006-02-15 18:34:11 +03:00
|
|
|
replace = comment;
|
|
|
|
std::string::size_type lpos = 0;
|
|
|
|
std::string::size_type rpos;
|
2016-05-16 17:34:04 +03:00
|
|
|
while ((rpos = replace.find('\n', lpos)) != std::string::npos) {
|
|
|
|
os << "# " << replace.substr(lpos, rpos - lpos) << "\n";
|
|
|
|
lpos = rpos + 1;
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
os << "# " << replace.substr(lpos) << "\n";
|
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
|
|
|
|
// Construct the left hand side of the rule.
|
2016-05-20 00:11:40 +03:00
|
|
|
std::string tgt = this->Convert(target, cmOutputConverter::HOME_OUTPUT,
|
|
|
|
cmOutputConverter::MAKERULE);
|
2014-12-05 17:55:49 +03:00
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
const char* space = "";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (tgt.size() == 1) {
|
2006-02-15 18:34:11 +03:00
|
|
|
// Add a space before the ":" to avoid drive letter confusion on
|
|
|
|
// Windows.
|
|
|
|
space = " ";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-12-26 21:14:19 +03:00
|
|
|
|
2006-02-16 00:35:16 +03:00
|
|
|
// Mark the rule as symbolic if requested.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (symbolic) {
|
|
|
|
if (const char* sym =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_MAKE_SYMBOLIC_RULE")) {
|
2012-06-06 16:30:54 +04:00
|
|
|
os << cmMakeSafe(tgt) << space << ": " << sym << "\n";
|
2006-02-16 00:35:16 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-16 00:35:16 +03:00
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
// Write the rule.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (depends.empty()) {
|
2006-02-15 18:34:11 +03:00
|
|
|
// No dependencies. The commands will always run.
|
2012-06-06 16:30:54 +04:00
|
|
|
os << cmMakeSafe(tgt) << space << ":\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2006-02-15 18:34:11 +03:00
|
|
|
// Split dependencies into multiple rule lines. This allows for
|
|
|
|
// very long dependency lists even on older make implementations.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator dep = depends.begin();
|
|
|
|
dep != depends.end(); ++dep) {
|
2006-02-15 18:34:11 +03:00
|
|
|
replace = *dep;
|
2016-05-20 00:11:40 +03:00
|
|
|
replace = this->Convert(replace, cmOutputConverter::HOME_OUTPUT,
|
|
|
|
cmOutputConverter::MAKERULE);
|
2012-06-06 16:30:54 +04:00
|
|
|
os << cmMakeSafe(tgt) << space << ": " << cmMakeSafe(replace) << "\n";
|
2005-12-27 23:33:47 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-12-27 23:33:47 +03:00
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
// Write the list of commands.
|
2015-02-19 01:50:36 +03:00
|
|
|
os << cmWrap("\t", commands, "", "\n") << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (symbolic && !this->IsWatcomWMake()) {
|
2012-06-06 16:30:54 +04:00
|
|
|
os << ".PHONY : " << cmMakeSafe(tgt) << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
os << "\n";
|
2006-08-23 17:45:24 +04:00
|
|
|
// Add the output to the local help if requested.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (in_help) {
|
2015-03-06 22:35:28 +03:00
|
|
|
this->LocalHelp.push_back(target);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-12-26 21:14:19 +03:00
|
|
|
}
|
|
|
|
|
2016-08-27 14:44:53 +03:00
|
|
|
std::string cmLocalUnixMakefileGenerator3::MaybeConvertWatcomShellCommand(
|
|
|
|
std::string const& cmd)
|
2011-11-03 16:59:50 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsWatcomWMake() && cmSystemTools::FileIsFullPath(cmd.c_str()) &&
|
|
|
|
cmd.find_first_of("( )") != cmd.npos) {
|
2011-11-03 16:59:50 +04:00
|
|
|
// On Watcom WMake use the windows short path for the command
|
|
|
|
// name. This is needed to avoid funny quoting problems on
|
|
|
|
// lines with shell redirection operators.
|
|
|
|
std::string scmd;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::GetShortPath(cmd, scmd)) {
|
2016-08-27 14:44:55 +03:00
|
|
|
return this->ConvertToOutputFormat(scmd, cmOutputConverter::SHELL);
|
2011-11-03 16:59:50 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-08-27 14:44:53 +03:00
|
|
|
return std::string();
|
2011-11-03 16:59:50 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::WriteMakeVariables(
|
|
|
|
std::ostream& makefileStream)
|
2005-05-06 22:49:38 +04:00
|
|
|
{
|
|
|
|
this->WriteDivider(makefileStream);
|
2016-05-16 17:34:04 +03:00
|
|
|
makefileStream << "# Set environment variables for the build.\n"
|
|
|
|
<< "\n";
|
2015-05-16 06:20:36 +03:00
|
|
|
cmGlobalUnixMakefileGenerator3* gg =
|
|
|
|
static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (gg->DefineWindowsNULL) {
|
|
|
|
makefileStream << "!IF \"$(OS)\" == \"Windows_NT\"\n"
|
|
|
|
<< "NULL=\n"
|
|
|
|
<< "!ELSE\n"
|
|
|
|
<< "NULL=nul\n"
|
|
|
|
<< "!ENDIF\n";
|
|
|
|
}
|
|
|
|
if (this->IsWindowsShell()) {
|
|
|
|
makefileStream << "SHELL = cmd.exe\n"
|
|
|
|
<< "\n";
|
|
|
|
} else {
|
2009-06-10 21:03:37 +04:00
|
|
|
#if !defined(__VMS)
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2005-12-23 00:42:36 +03:00
|
|
|
makefileStream
|
|
|
|
<< "# The shell in which to execute make rules.\n"
|
|
|
|
<< "SHELL = /bin/sh\n"
|
|
|
|
<< "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
/* clang-format on */
|
2009-06-10 21:03:37 +04:00
|
|
|
#endif
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-06 22:49:38 +04:00
|
|
|
|
2016-08-27 14:44:53 +03:00
|
|
|
std::string cmakeShellCommand =
|
|
|
|
this->MaybeConvertWatcomShellCommand(cmSystemTools::GetCMakeCommand());
|
|
|
|
if (cmakeShellCommand.empty()) {
|
2016-08-27 14:44:57 +03:00
|
|
|
cmakeShellCommand = this->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(cmSystemTools::GetCMakeCommand()),
|
|
|
|
cmOutputConverter::SHELL);
|
2016-08-27 14:44:53 +03:00
|
|
|
}
|
2016-08-27 14:44:53 +03:00
|
|
|
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2005-05-06 22:49:38 +04:00
|
|
|
makefileStream
|
|
|
|
<< "# The CMake executable.\n"
|
|
|
|
<< "CMAKE_COMMAND = "
|
2016-08-27 14:44:53 +03:00
|
|
|
<< cmakeShellCommand
|
2005-07-05 17:21:44 +04:00
|
|
|
<< "\n"
|
2005-05-06 22:49:38 +04:00
|
|
|
<< "\n";
|
|
|
|
makefileStream
|
|
|
|
<< "# The command to remove a file.\n"
|
|
|
|
<< "RM = "
|
2016-08-27 14:44:53 +03:00
|
|
|
<< cmakeShellCommand
|
2005-05-06 22:49:38 +04:00
|
|
|
<< " -E remove -f\n"
|
|
|
|
<< "\n";
|
2012-06-06 16:30:54 +04:00
|
|
|
makefileStream
|
|
|
|
<< "# Escaping for special characters.\n"
|
|
|
|
<< "EQUALS = =\n"
|
|
|
|
<< "\n";
|
2005-05-06 22:49:38 +04:00
|
|
|
makefileStream
|
|
|
|
<< "# The top-level source directory on which CMake was run.\n"
|
|
|
|
<< "CMAKE_SOURCE_DIR = "
|
2016-08-27 14:44:57 +03:00
|
|
|
<< this->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(this->GetSourceDirectory()),
|
2016-05-20 00:11:40 +03:00
|
|
|
cmOutputConverter::SHELL)
|
2005-05-06 22:49:38 +04:00
|
|
|
<< "\n"
|
|
|
|
<< "\n";
|
|
|
|
makefileStream
|
|
|
|
<< "# The top-level build directory on which CMake was run.\n"
|
2005-07-05 17:21:44 +04:00
|
|
|
<< "CMAKE_BINARY_DIR = "
|
2016-08-27 14:44:57 +03:00
|
|
|
<< this->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(this->GetBinaryDirectory()),
|
2016-05-20 00:11:40 +03:00
|
|
|
cmOutputConverter::SHELL)
|
2005-05-06 22:49:38 +04:00
|
|
|
<< "\n"
|
|
|
|
<< "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2005-05-06 22:49:38 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsTop(
|
|
|
|
std::ostream& makefileStream)
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
|
|
|
this->WriteDivider(makefileStream);
|
2016-05-16 17:34:04 +03:00
|
|
|
makefileStream << "# Special targets provided by cmake.\n"
|
|
|
|
<< "\n";
|
2005-05-05 20:45:53 +04:00
|
|
|
|
2006-09-08 18:42:14 +04:00
|
|
|
std::vector<std::string> no_commands;
|
|
|
|
std::vector<std::string> no_depends;
|
|
|
|
|
|
|
|
// Special target to cleanup operation of make tool.
|
|
|
|
// This should be the first target except for the default_target in
|
|
|
|
// the interface Makefile.
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteMakeRule(makefileStream,
|
|
|
|
"Disable implicit rules so canonical targets will work.",
|
|
|
|
".SUFFIXES", no_depends, no_commands, false);
|
2006-09-08 18:42:14 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->IsNMake() && !this->IsWatcomWMake() &&
|
|
|
|
!this->BorlandMakeCurlyHack) {
|
2008-03-18 18:28:59 +03:00
|
|
|
// turn off RCS and SCCS automatic stuff from gmake
|
2008-03-18 18:51:23 +03:00
|
|
|
makefileStream
|
|
|
|
<< "# Remove some rules from gmake that .SUFFIXES does not remove.\n"
|
2008-04-10 19:55:49 +04:00
|
|
|
<< "SUFFIXES =\n\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-09-08 18:42:14 +04:00
|
|
|
// Add a fake suffix to keep HP happy. Must be max 32 chars for SGI make.
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
depends.push_back(".hpux_make_needs_suffix_list");
|
2016-06-27 23:44:16 +03:00
|
|
|
this->WriteMakeRule(makefileStream, CM_NULLPTR, ".SUFFIXES", depends,
|
|
|
|
no_commands, false);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsWatcomWMake()) {
|
2014-03-09 13:41:06 +04:00
|
|
|
// Switch on WMake feature, if an error or interrupt occurs during
|
|
|
|
// makefile processing, the current target being made may be deleted
|
|
|
|
// without prompting (the same as command line -e option).
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2014-03-09 13:41:06 +04:00
|
|
|
makefileStream <<
|
|
|
|
"\n"
|
|
|
|
".ERASE\n"
|
|
|
|
"\n"
|
|
|
|
;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE")) {
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2005-12-31 05:54:03 +03:00
|
|
|
makefileStream
|
|
|
|
<< "# Produce verbose output by default.\n"
|
|
|
|
<< "VERBOSE = 1\n"
|
|
|
|
<< "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->IsWatcomWMake()) {
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2014-03-09 13:41:06 +04:00
|
|
|
makefileStream <<
|
|
|
|
"!ifndef VERBOSE\n"
|
|
|
|
".SILENT\n"
|
|
|
|
"!endif\n"
|
2014-03-16 15:35:18 +04:00
|
|
|
"\n"
|
2014-03-09 13:41:06 +04:00
|
|
|
;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-03-09 13:41:06 +04:00
|
|
|
// Write special target to silence make output. This must be after
|
|
|
|
// the default target in case VERBOSE is set (which changes the
|
|
|
|
// name). The setting of CMAKE_VERBOSE_MAKEFILE to ON will cause a
|
|
|
|
// "VERBOSE=1" to be added as a make variable which will change the
|
|
|
|
// name of this special target. This gives a make-time choice to
|
|
|
|
// the user.
|
2006-01-17 18:21:45 +03:00
|
|
|
this->WriteMakeRule(makefileStream,
|
|
|
|
"Suppress display of executed commands.",
|
2016-05-16 17:34:04 +03:00
|
|
|
"$(VERBOSE).SILENT", no_depends, no_commands, false);
|
|
|
|
}
|
2005-10-21 23:24:12 +04:00
|
|
|
|
2007-02-28 17:33:25 +03:00
|
|
|
// Work-around for makes that drop rules that have no dependencies
|
|
|
|
// or commands.
|
2014-03-09 13:41:06 +04:00
|
|
|
cmGlobalUnixMakefileGenerator3* gg =
|
|
|
|
static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
|
2007-02-28 17:33:25 +03:00
|
|
|
std::string hack = gg->GetEmptyRuleHackDepends();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!hack.empty()) {
|
2007-02-28 17:33:25 +03:00
|
|
|
no_depends.push_back(hack);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-05-16 21:24:17 +04:00
|
|
|
std::string hack_cmd = gg->GetEmptyRuleHackCommand();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!hack_cmd.empty()) {
|
2007-05-16 21:24:17 +04:00
|
|
|
no_commands.push_back(hack_cmd);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-02-28 17:33:25 +03:00
|
|
|
|
2006-09-20 20:13:50 +04:00
|
|
|
// Special symbolic target that never exists to force dependers to
|
|
|
|
// run their rules.
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteMakeRule(makefileStream, "A target that is always out of date.",
|
|
|
|
"cmake_force", no_depends, no_commands, true);
|
2006-09-20 20:13:50 +04:00
|
|
|
|
2006-09-08 18:42:14 +04:00
|
|
|
// Variables for reference by other rules.
|
|
|
|
this->WriteMakeVariables(makefileStream);
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsBottom(
|
|
|
|
std::ostream& makefileStream)
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
|
|
|
this->WriteDivider(makefileStream);
|
2016-05-16 17:34:04 +03:00
|
|
|
makefileStream << "# Special targets to cleanup operation of make.\n"
|
|
|
|
<< "\n";
|
2005-05-05 20:45:53 +04:00
|
|
|
|
|
|
|
// Write special "cmake_check_build_system" target to run cmake with
|
|
|
|
// the --check-build-system flag.
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
// Build command to run CMake to check if anything needs regenerating.
|
|
|
|
std::string cmakefileName = cmake::GetCMakeFilesDirectoryPostSlash();
|
|
|
|
cmakefileName += "Makefile.cmake";
|
|
|
|
std::string runRule =
|
|
|
|
"$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
|
|
|
|
runRule += " --check-build-system ";
|
2016-08-27 14:44:55 +03:00
|
|
|
runRule +=
|
|
|
|
this->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL);
|
2016-05-16 17:34:04 +03:00
|
|
|
runRule += " 0";
|
2006-03-02 02:54:17 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<std::string> no_depends;
|
|
|
|
std::vector<std::string> commands;
|
|
|
|
commands.push_back(runRule);
|
|
|
|
if (!this->IsRootMakefile()) {
|
|
|
|
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->GetCurrentBinaryDirectory());
|
2006-03-02 02:54:17 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteMakeRule(
|
|
|
|
makefileStream, "Special rule to run CMake to check the build system "
|
2005-05-05 20:45:53 +04:00
|
|
|
"integrity.\n"
|
|
|
|
"No rule that depends on this can have "
|
|
|
|
"commands that come from listfiles\n"
|
|
|
|
"because they might be regenerated.",
|
2016-05-16 17:34:04 +03:00
|
|
|
"cmake_check_build_system", no_depends, commands, true);
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::WriteConvenienceRule(
|
|
|
|
std::ostream& ruleFileStream, const std::string& realTarget,
|
|
|
|
const std::string& helpTarget)
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
|
|
|
// A rule is only needed if the names are different.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (realTarget != helpTarget) {
|
2005-05-05 20:45:53 +04:00
|
|
|
// The helper target depends on the real target.
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
depends.push_back(realTarget);
|
|
|
|
|
|
|
|
// There are no commands.
|
|
|
|
std::vector<std::string> no_commands;
|
|
|
|
|
|
|
|
// Write the rule.
|
|
|
|
this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
|
2006-02-16 00:35:16 +03:00
|
|
|
helpTarget, depends, no_commands, true);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmLocalUnixMakefileGenerator3::GetRelativeTargetDirectory(
|
|
|
|
cmGeneratorTarget* target)
|
2005-05-11 16:45:16 +04:00
|
|
|
{
|
2006-04-11 20:51:20 +04:00
|
|
|
std::string dir = this->HomeRelativeOutputPath;
|
2015-10-09 23:27:46 +03:00
|
|
|
dir += this->GetTargetDirectory(target);
|
2016-08-27 14:44:53 +03:00
|
|
|
return dir;
|
2006-02-15 18:34:11 +03:00
|
|
|
}
|
|
|
|
|
2007-05-10 22:43:55 +04:00
|
|
|
void cmLocalUnixMakefileGenerator3::AppendFlags(std::string& flags,
|
2014-05-02 00:07:26 +04:00
|
|
|
const std::string& newFlags)
|
2007-05-10 22:43:55 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsWatcomWMake() && !newFlags.empty()) {
|
2007-05-10 22:43:55 +04:00
|
|
|
std::string newf = newFlags;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (newf.find("\\\"") != newf.npos) {
|
2007-05-10 22:43:55 +04:00
|
|
|
cmSystemTools::ReplaceString(newf, "\\\"", "\"");
|
2014-05-02 00:07:26 +04:00
|
|
|
this->cmLocalGenerator::AppendFlags(flags, newf);
|
2007-05-10 22:43:55 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-05-10 22:43:55 +04:00
|
|
|
this->cmLocalGenerator::AppendFlags(flags, newFlags);
|
|
|
|
}
|
|
|
|
|
2014-05-02 00:07:26 +04:00
|
|
|
void cmLocalUnixMakefileGenerator3::AppendFlags(std::string& flags,
|
|
|
|
const char* newFlags)
|
|
|
|
{
|
|
|
|
this->cmLocalGenerator::AppendFlags(flags, newFlags);
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::AppendRuleDepend(
|
|
|
|
std::vector<std::string>& depends, const char* ruleFileName)
|
2006-02-15 18:34:11 +03:00
|
|
|
{
|
|
|
|
// Add a dependency on the rule file itself unless an option to skip
|
|
|
|
// it is specifically enabled by the user or project.
|
2010-11-12 00:02:07 +03:00
|
|
|
const char* nodep =
|
2006-05-15 18:19:57 +04:00
|
|
|
this->Makefile->GetDefinition("CMAKE_SKIP_RULE_DEPENDENCY");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!nodep || cmSystemTools::IsOff(nodep)) {
|
2006-02-15 18:34:11 +03:00
|
|
|
depends.push_back(ruleFileName);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-11 16:45:16 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::AppendRuleDepends(
|
|
|
|
std::vector<std::string>& depends, std::vector<std::string> const& ruleFiles)
|
2011-03-15 21:07:36 +03:00
|
|
|
{
|
|
|
|
// Add a dependency on the rule file itself unless an option to skip
|
|
|
|
// it is specifically enabled by the user or project.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Makefile->IsOn("CMAKE_SKIP_RULE_DEPENDENCY")) {
|
2011-03-15 21:07:36 +03:00
|
|
|
depends.insert(depends.end(), ruleFiles.begin(), ruleFiles.end());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-03-15 21:07:36 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::AppendCustomDepends(
|
|
|
|
std::vector<std::string>& depends, const std::vector<cmCustomCommand>& ccs)
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
|
|
|
|
i != ccs.end(); ++i) {
|
2015-07-25 18:52:10 +03:00
|
|
|
cmCustomCommandGenerator ccg(*i, this->ConfigName, this);
|
2014-03-10 23:47:19 +04:00
|
|
|
this->AppendCustomDepend(depends, ccg);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::AppendCustomDepend(
|
|
|
|
std::vector<std::string>& depends, cmCustomCommandGenerator const& ccg)
|
2006-02-15 18:34:11 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator d = ccg.GetDepends().begin();
|
|
|
|
d != ccg.GetDepends().end(); ++d) {
|
2006-02-15 18:34:11 +03:00
|
|
|
// Lookup the real name of the dependency in case it is a CMake target.
|
2010-12-09 00:51:16 +03:00
|
|
|
std::string dep;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->GetRealDependency(*d, this->ConfigName, dep)) {
|
2010-12-09 00:51:16 +03:00
|
|
|
depends.push_back(dep);
|
2005-11-17 21:49:10 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
}
|
2005-11-17 21:49:10 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::AppendCustomCommands(
|
|
|
|
std::vector<std::string>& commands, const std::vector<cmCustomCommand>& ccs,
|
2016-08-27 14:44:53 +03:00
|
|
|
cmGeneratorTarget* target, std::string const& relative)
|
2006-02-15 18:34:11 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
|
|
|
|
i != ccs.end(); ++i) {
|
2015-07-25 18:52:10 +03:00
|
|
|
cmCustomCommandGenerator ccg(*i, this->ConfigName, this);
|
2016-08-27 14:44:52 +03:00
|
|
|
this->AppendCustomCommand(commands, ccg, target, relative, true);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
|
|
|
|
std::vector<std::string>& commands, cmCustomCommandGenerator const& ccg,
|
2016-08-27 14:44:53 +03:00
|
|
|
cmGeneratorTarget* target, std::string const& relative, bool echo_comment,
|
|
|
|
std::ostream* content)
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
2007-12-18 17:50:08 +03:00
|
|
|
// Optionally create a command to display the custom command's
|
|
|
|
// comment text. This is used for pre-build, pre-link, and
|
|
|
|
// post-build command comments. Custom build step commands have
|
|
|
|
// their comments generated elsewhere.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (echo_comment) {
|
2014-03-10 23:47:19 +04:00
|
|
|
const char* comment = ccg.GetComment();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (comment && *comment) {
|
2007-12-18 17:50:08 +03:00
|
|
|
this->AppendEcho(commands, comment,
|
|
|
|
cmLocalUnixMakefileGenerator3::EchoGenerate);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-18 17:50:08 +03:00
|
|
|
|
2006-06-26 23:27:51 +04:00
|
|
|
// if the command specified a working directory use it.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string dir = this->GetCurrentBinaryDirectory();
|
2014-03-10 23:47:19 +04:00
|
|
|
std::string workingDir = ccg.GetWorkingDirectory();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!workingDir.empty()) {
|
2006-06-26 23:27:51 +04:00
|
|
|
dir = workingDir;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (content) {
|
2009-02-02 21:28:12 +03:00
|
|
|
*content << dir;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
|
|
|
|
// Add each command line to the set of commands.
|
2006-06-26 23:27:51 +04:00
|
|
|
std::vector<std::string> commands1;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c) {
|
2005-05-05 20:45:53 +04:00
|
|
|
// Build the command line in a single string.
|
2010-12-08 00:23:38 +03:00
|
|
|
std::string cmd = ccg.GetCommand(c);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmd.empty()) {
|
2010-06-03 21:43:39 +04:00
|
|
|
// Use "call " before any invocations of .bat or .cmd files
|
|
|
|
// invoked as custom commands in the WindowsShell.
|
|
|
|
//
|
|
|
|
bool useCall = false;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsWindowsShell()) {
|
2010-06-03 21:43:39 +04:00
|
|
|
std::string suffix;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmd.size() > 4) {
|
|
|
|
suffix = cmSystemTools::LowerCase(cmd.substr(cmd.size() - 4));
|
|
|
|
if (suffix == ".bat" || suffix == ".cmd") {
|
2010-06-03 21:43:39 +04:00
|
|
|
useCall = true;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-06-03 21:43:39 +04:00
|
|
|
|
2005-05-20 20:09:33 +04:00
|
|
|
cmSystemTools::ReplaceString(cmd, "/./", "/");
|
2006-06-26 23:27:51 +04:00
|
|
|
// Convert the command to a relative path only if the current
|
|
|
|
// working directory will be the start-output directory.
|
2016-05-24 22:24:10 +03:00
|
|
|
bool had_slash = cmd.find('/') != cmd.npos;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (workingDir.empty()) {
|
2016-08-27 14:44:56 +03:00
|
|
|
cmd =
|
|
|
|
this->ConvertToRelativePath(cmd, cmOutputConverter::START_OUTPUT);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-05-24 22:24:10 +03:00
|
|
|
bool has_slash = cmd.find('/') != cmd.npos;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (had_slash && !has_slash) {
|
2007-05-23 20:05:05 +04:00
|
|
|
// This command was specified as a path to a file in the
|
|
|
|
// current directory. Add a leading "./" so it can run
|
|
|
|
// without the current directory being in the search path.
|
2005-05-20 20:09:33 +04:00
|
|
|
cmd = "./" + cmd;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-08-27 14:44:54 +03:00
|
|
|
|
|
|
|
std::string launcher;
|
|
|
|
// Short-circuit if there is no launcher.
|
|
|
|
const char* prop = "RULE_LAUNCH_CUSTOM";
|
|
|
|
const char* val = this->GetRuleLauncher(target, prop);
|
|
|
|
if (val && *val) {
|
|
|
|
// Expand rules in the empty string. It may insert the launcher and
|
|
|
|
// perform replacements.
|
|
|
|
RuleVariables vars;
|
|
|
|
vars.RuleLauncher = prop;
|
|
|
|
vars.CMTarget = target;
|
|
|
|
std::string output;
|
|
|
|
const std::vector<std::string>& outputs = ccg.GetOutputs();
|
|
|
|
if (!outputs.empty()) {
|
2016-08-27 14:44:54 +03:00
|
|
|
if (workingDir.empty()) {
|
|
|
|
output = this->Convert(outputs[0], cmOutputConverter::START_OUTPUT,
|
|
|
|
cmOutputConverter::SHELL);
|
|
|
|
|
|
|
|
} else {
|
2016-08-27 14:44:55 +03:00
|
|
|
output = this->ConvertToOutputFormat(outputs[0],
|
|
|
|
cmOutputConverter::SHELL);
|
2016-08-27 14:44:54 +03:00
|
|
|
}
|
2016-08-27 14:44:54 +03:00
|
|
|
}
|
|
|
|
vars.Output = output.c_str();
|
|
|
|
|
|
|
|
this->ExpandRuleVariables(launcher, vars);
|
|
|
|
if (!launcher.empty()) {
|
|
|
|
launcher += " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-27 14:44:53 +03:00
|
|
|
std::string shellCommand = this->MaybeConvertWatcomShellCommand(cmd);
|
|
|
|
if (shellCommand.empty()) {
|
2016-08-27 14:44:55 +03:00
|
|
|
shellCommand =
|
|
|
|
this->ConvertToOutputFormat(cmd, cmOutputConverter::SHELL);
|
2016-08-27 14:44:53 +03:00
|
|
|
}
|
|
|
|
cmd = launcher + shellCommand;
|
2010-12-08 00:23:38 +03:00
|
|
|
|
|
|
|
ccg.AppendArguments(c, cmd);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (content) {
|
2009-02-10 16:51:15 +03:00
|
|
|
// Rule content does not include the launcher.
|
2016-05-16 17:34:04 +03:00
|
|
|
*content << (cmd.c_str() + launcher.size());
|
|
|
|
}
|
|
|
|
if (this->BorlandMakeCurlyHack) {
|
2007-05-17 18:53:18 +04:00
|
|
|
// Borland Make has a very strange bug. If the first curly
|
|
|
|
// brace anywhere in the command string is a left curly, it
|
|
|
|
// must be written {{} instead of just {. Otherwise some
|
|
|
|
// curly braces are removed. The hack can be skipped if the
|
|
|
|
// first curly brace is the last character.
|
2016-05-24 22:24:10 +03:00
|
|
|
std::string::size_type lcurly = cmd.find('{');
|
2016-05-16 17:34:04 +03:00
|
|
|
if (lcurly != cmd.npos && lcurly < (cmd.size() - 1)) {
|
2016-05-24 22:24:10 +03:00
|
|
|
std::string::size_type rcurly = cmd.find('}');
|
2016-05-16 17:34:04 +03:00
|
|
|
if (rcurly == cmd.npos || rcurly > lcurly) {
|
2007-05-17 18:53:18 +04:00
|
|
|
// The first curly is a left curly. Use the hack.
|
|
|
|
std::string hack_cmd = cmd.substr(0, lcurly);
|
|
|
|
hack_cmd += "{{}";
|
2016-05-16 17:34:04 +03:00
|
|
|
hack_cmd += cmd.substr(lcurly + 1);
|
2007-05-17 18:53:18 +04:00
|
|
|
cmd = hack_cmd;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (launcher.empty()) {
|
|
|
|
if (useCall) {
|
2010-09-11 00:17:39 +04:00
|
|
|
cmd = "call " + cmd;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->IsNMake() && cmd[0] == '"') {
|
2010-09-11 00:17:39 +04:00
|
|
|
cmd = "echo >nul && " + cmd;
|
2010-06-03 21:43:39 +04:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
commands1.push_back(cmd);
|
2005-05-20 19:01:21 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-20 19:01:21 +04:00
|
|
|
|
2006-06-26 23:27:51 +04:00
|
|
|
// Setup the proper working directory for the commands.
|
2016-08-27 14:44:53 +03:00
|
|
|
this->CreateCDCommand(commands1, dir.c_str(), relative);
|
2006-02-15 18:34:11 +03:00
|
|
|
|
2006-06-26 23:27:51 +04:00
|
|
|
// push back the custom commands
|
2005-10-19 18:03:20 +04:00
|
|
|
commands.insert(commands.end(), commands1.begin(), commands1.end());
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::AppendCleanCommand(
|
|
|
|
std::vector<std::string>& commands, const std::vector<std::string>& files,
|
|
|
|
cmGeneratorTarget* target, const char* filename)
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
2015-10-22 01:29:36 +03:00
|
|
|
std::string cleanfile = this->GetCurrentBinaryDirectory();
|
2013-10-16 17:52:37 +04:00
|
|
|
cleanfile += "/";
|
2015-10-09 23:27:46 +03:00
|
|
|
cleanfile += this->GetTargetDirectory(target);
|
2013-10-16 17:52:37 +04:00
|
|
|
cleanfile += "/cmake_clean";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (filename) {
|
2013-10-16 17:52:37 +04:00
|
|
|
cleanfile += "_";
|
|
|
|
cleanfile += filename;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-16 17:52:37 +04:00
|
|
|
cleanfile += ".cmake";
|
2016-08-27 14:44:55 +03:00
|
|
|
std::string cleanfilePath = cmSystemTools::CollapseFullPath(cleanfile);
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ofstream fout(cleanfilePath.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fout) {
|
2013-10-16 17:52:37 +04:00
|
|
|
cmSystemTools::Error("Could not create ", cleanfilePath.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!files.empty()) {
|
2013-08-22 13:30:19 +04:00
|
|
|
fout << "file(REMOVE_RECURSE\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator f = files.begin();
|
|
|
|
f != files.end(); ++f) {
|
2016-08-27 14:44:56 +03:00
|
|
|
std::string fc =
|
|
|
|
this->ConvertToRelativePath(*f, cmOutputConverter::START_OUTPUT);
|
2015-05-16 01:55:21 +03:00
|
|
|
fout << " " << cmOutputConverter::EscapeForCMake(fc) << "\n";
|
2013-10-16 17:52:37 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
fout << ")\n";
|
|
|
|
}
|
2013-10-16 17:52:37 +04:00
|
|
|
std::string remove = "$(CMAKE_COMMAND) -P ";
|
2016-05-20 00:11:40 +03:00
|
|
|
remove += this->Convert(cleanfile, cmOutputConverter::START_OUTPUT,
|
|
|
|
cmOutputConverter::SHELL);
|
2013-10-16 17:52:37 +04:00
|
|
|
commands.push_back(remove);
|
2007-12-28 19:50:14 +03:00
|
|
|
|
2013-10-16 17:52:37 +04:00
|
|
|
// For the main clean rule add per-language cleaning.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!filename) {
|
2013-10-16 17:52:37 +04:00
|
|
|
// Get the set of source languages in the target.
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> languages;
|
2016-05-16 17:34:04 +03:00
|
|
|
target->GetLanguages(
|
|
|
|
languages, this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2013-10-16 17:52:37 +04:00
|
|
|
fout << "\n"
|
|
|
|
<< "# Per-language clean rules from dependency scanning.\n"
|
2015-02-12 22:53:43 +03:00
|
|
|
<< "foreach(lang " << cmJoin(languages, " ") << ")\n"
|
2015-10-09 23:27:46 +03:00
|
|
|
<< " include(" << this->GetTargetDirectory(target)
|
2013-10-16 17:52:37 +04:00
|
|
|
<< "/cmake_clean_${lang}.cmake OPTIONAL)\n"
|
|
|
|
<< "endforeach()\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::AppendEcho(
|
|
|
|
std::vector<std::string>& commands, std::string const& text, EchoColor color,
|
|
|
|
EchoProgress const* progress)
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
2006-03-31 00:39:03 +04:00
|
|
|
// Choose the color for the text.
|
2006-04-27 05:31:39 +04:00
|
|
|
std::string color_name;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->GlobalGenerator->GetToolSupportsColor() && this->ColorMakefile) {
|
2006-04-27 05:31:39 +04:00
|
|
|
// See cmake::ExecuteEchoColor in cmake.cxx for these options.
|
|
|
|
// This color set is readable on both black and white backgrounds.
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (color) {
|
2006-03-31 00:39:03 +04:00
|
|
|
case EchoNormal:
|
|
|
|
break;
|
|
|
|
case EchoDepend:
|
2006-04-27 05:31:39 +04:00
|
|
|
color_name = "--magenta --bold ";
|
2006-03-31 00:39:03 +04:00
|
|
|
break;
|
|
|
|
case EchoBuild:
|
2006-04-27 05:31:39 +04:00
|
|
|
color_name = "--green ";
|
2006-03-31 00:39:03 +04:00
|
|
|
break;
|
|
|
|
case EchoLink:
|
2015-02-07 03:07:56 +03:00
|
|
|
color_name = "--green --bold ";
|
2006-03-31 00:39:03 +04:00
|
|
|
break;
|
|
|
|
case EchoGenerate:
|
2006-04-27 05:31:39 +04:00
|
|
|
color_name = "--blue --bold ";
|
2006-03-31 00:39:03 +04:00
|
|
|
break;
|
|
|
|
case EchoGlobal:
|
2006-04-27 05:31:39 +04:00
|
|
|
color_name = "--cyan ";
|
2006-03-31 00:39:03 +04:00
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-31 00:39:03 +04:00
|
|
|
|
2005-05-05 20:45:53 +04:00
|
|
|
// Echo one line at a time.
|
|
|
|
std::string line;
|
2006-04-11 20:51:20 +04:00
|
|
|
line.reserve(200);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (const char* c = text.c_str();; ++c) {
|
|
|
|
if (*c == '\n' || *c == '\0') {
|
2005-05-05 20:45:53 +04:00
|
|
|
// Avoid writing a blank last line on end-of-string.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (*c != '\0' || !line.empty()) {
|
2005-05-05 20:45:53 +04:00
|
|
|
// Add a command to echo this line.
|
2006-04-27 05:31:39 +04:00
|
|
|
std::string cmd;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (color_name.empty() && !progress) {
|
2006-04-27 05:31:39 +04:00
|
|
|
// Use the native echo command.
|
2011-06-16 23:43:17 +04:00
|
|
|
cmd = "@echo ";
|
2014-03-11 03:04:11 +04:00
|
|
|
cmd += this->EscapeForShell(line, false, true);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2006-04-27 05:31:39 +04:00
|
|
|
// Use cmake to echo the text in color.
|
|
|
|
cmd = "@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) ";
|
|
|
|
cmd += color_name;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (progress) {
|
2015-02-06 00:48:16 +03:00
|
|
|
cmd += "--progress-dir=";
|
2016-08-27 14:44:57 +03:00
|
|
|
cmd += this->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(progress->Dir),
|
|
|
|
cmOutputConverter::SHELL);
|
2015-02-06 00:48:16 +03:00
|
|
|
cmd += " ";
|
|
|
|
cmd += "--progress-num=";
|
|
|
|
cmd += progress->Arg;
|
|
|
|
cmd += " ";
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
cmd += this->EscapeForShell(line);
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
commands.push_back(cmd);
|
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
|
|
|
|
// Reset the line to emtpy.
|
|
|
|
line = "";
|
|
|
|
|
2015-02-06 00:48:16 +03:00
|
|
|
// Progress appears only on first line.
|
2016-06-27 23:44:16 +03:00
|
|
|
progress = CM_NULLPTR;
|
2015-02-06 00:48:16 +03:00
|
|
|
|
2005-05-05 20:45:53 +04:00
|
|
|
// Terminate on end-of-string.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (*c == '\0') {
|
2005-05-05 20:45:53 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (*c != '\r') {
|
2005-05-05 20:45:53 +04:00
|
|
|
// Append this character to the current line.
|
|
|
|
line += *c;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmLocalUnixMakefileGenerator3::CreateMakeVariable(
|
2016-05-26 23:21:15 +03:00
|
|
|
const std::string& sin, const std::string& s2)
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
|
|
|
std::string s = sin;
|
|
|
|
std::string unmodified = s;
|
|
|
|
unmodified += s2;
|
|
|
|
// if there is no restriction on the length of make variables
|
2012-11-07 20:13:09 +04:00
|
|
|
// and there are no "." characters in the string, then return the
|
2005-05-05 20:45:53 +04:00
|
|
|
// unmodified combination.
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((!this->MakefileVariableSize && unmodified.find('.') == s.npos) &&
|
|
|
|
(!this->MakefileVariableSize && unmodified.find('+') == s.npos) &&
|
|
|
|
(!this->MakefileVariableSize && unmodified.find('-') == s.npos)) {
|
2005-05-05 20:45:53 +04:00
|
|
|
return unmodified;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
|
|
|
|
// see if the variable has been defined before and return
|
|
|
|
// the modified version of the variable
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::string>::iterator i =
|
2006-05-15 18:19:57 +04:00
|
|
|
this->MakeVariableMap.find(unmodified);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i != this->MakeVariableMap.end()) {
|
2005-05-05 20:45:53 +04:00
|
|
|
return i->second;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
// start with the unmodified variable
|
|
|
|
std::string ret = unmodified;
|
2006-03-15 19:02:08 +03:00
|
|
|
// if this there is no value for this->MakefileVariableSize then
|
2005-05-05 20:45:53 +04:00
|
|
|
// the string must have bad characters in it
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->MakefileVariableSize) {
|
Use std::replace for replacing chars in strings.
Find uses of `cmSystemTools::ReplaceString` where both `replace` and
`with` are string literals with a size of one.
Automate with:
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\2', '\3');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\(.\)\", \"\\\\\\\\\");|std::replace(\1.begin(), \1.end(), '\2', '\\\\\\\\');|g"
git grep -l ReplaceString | xargs sed -i "s|cmSystemTools::ReplaceString(\([^,]*\), \"\\\\\\\\\", \"\(.\)\");|std::replace(\1.begin(), \1.end(), '\\\\\\\\', '\2');|g"
2016-05-24 23:58:11 +03:00
|
|
|
std::replace(ret.begin(), ret.end(), '.', '_');
|
2006-02-07 00:32:09 +03:00
|
|
|
cmSystemTools::ReplaceString(ret, "-", "__");
|
2011-08-25 00:08:31 +04:00
|
|
|
cmSystemTools::ReplaceString(ret, "+", "___");
|
2005-05-05 20:45:53 +04:00
|
|
|
int ni = 0;
|
|
|
|
char buffer[5];
|
|
|
|
// make sure the _ version is not already used, if
|
|
|
|
// it is used then add number to the end of the variable
|
2016-05-16 17:34:04 +03:00
|
|
|
while (this->ShortMakeVariableMap.count(ret) && ni < 1000) {
|
2005-05-05 20:45:53 +04:00
|
|
|
++ni;
|
|
|
|
sprintf(buffer, "%04d", ni);
|
|
|
|
ret = unmodified + buffer;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
this->ShortMakeVariableMap[ret] = "1";
|
|
|
|
this->MakeVariableMap[unmodified] = ret;
|
2005-05-05 20:45:53 +04:00
|
|
|
return ret;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
|
2012-11-07 20:13:09 +04:00
|
|
|
// if the string is greater than 32 chars it is an invalid variable name
|
2005-05-05 20:45:53 +04:00
|
|
|
// for borland make
|
2016-05-16 17:34:04 +03:00
|
|
|
if (static_cast<int>(ret.size()) > this->MakefileVariableSize) {
|
2006-03-15 19:02:08 +03:00
|
|
|
int keep = this->MakefileVariableSize - 8;
|
2005-05-05 20:45:53 +04:00
|
|
|
int size = keep + 3;
|
|
|
|
std::string str1 = s;
|
|
|
|
std::string str2 = s2;
|
2012-11-07 20:13:09 +04:00
|
|
|
// we must shorten the combined string by 4 characters
|
|
|
|
// keep no more than 24 characters from the second string
|
2016-05-16 17:34:04 +03:00
|
|
|
if (static_cast<int>(str2.size()) > keep) {
|
2005-05-05 20:45:53 +04:00
|
|
|
str2 = str2.substr(0, keep);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size) {
|
2005-05-05 20:45:53 +04:00
|
|
|
str1 = str1.substr(0, size - str2.size());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
char buffer[5];
|
|
|
|
int ni = 0;
|
|
|
|
sprintf(buffer, "%04d", ni);
|
|
|
|
ret = str1 + str2 + buffer;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (this->ShortMakeVariableMap.count(ret) && ni < 1000) {
|
2005-05-05 20:45:53 +04:00
|
|
|
++ni;
|
|
|
|
sprintf(buffer, "%04d", ni);
|
|
|
|
ret = str1 + str2 + buffer;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (ni == 1000) {
|
2005-05-05 20:45:53 +04:00
|
|
|
cmSystemTools::Error("Borland makefile variable length too long");
|
|
|
|
return unmodified;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
// once an unused variable is found
|
2006-03-15 19:02:08 +03:00
|
|
|
this->ShortMakeVariableMap[ret] = "1";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
// always make an entry into the unmodified to variable map
|
2006-03-15 19:02:08 +03:00
|
|
|
this->MakeVariableMap[unmodified] = ret;
|
2005-05-05 20:45:53 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-12-20 00:36:30 +03:00
|
|
|
bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
|
2007-12-20 01:15:41 +03:00
|
|
|
bool verbose,
|
|
|
|
bool color)
|
2007-12-20 00:36:30 +03:00
|
|
|
{
|
2007-12-21 20:22:12 +03:00
|
|
|
// read in the target info file
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Makefile->ReadListFile(tgtInfo) ||
|
|
|
|
cmSystemTools::GetErrorOccuredFlag()) {
|
2007-12-21 20:22:12 +03:00
|
|
|
cmSystemTools::Error("Target DependInfo.cmake file not found");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-21 20:22:12 +03:00
|
|
|
|
|
|
|
// Check if any multiple output pairs have a missing file.
|
|
|
|
this->CheckMultipleOutputs(verbose);
|
|
|
|
|
2007-12-20 00:36:30 +03:00
|
|
|
std::string dir = cmSystemTools::GetFilenamePath(tgtInfo);
|
|
|
|
std::string internalDependFile = dir + "/depend.internal";
|
|
|
|
std::string dependFile = dir + "/depend.make";
|
|
|
|
|
2008-03-12 00:53:54 +03:00
|
|
|
// If the target DependInfo.cmake file has changed since the last
|
|
|
|
// time dependencies were scanned then force rescanning. This may
|
|
|
|
// happen when a new source file is added and CMake regenerates the
|
|
|
|
// project but no other sources were touched.
|
2009-09-22 22:40:23 +04:00
|
|
|
bool needRescanDependInfo = false;
|
2008-03-12 00:53:54 +03:00
|
|
|
cmFileTimeComparison* ftc =
|
|
|
|
this->GlobalGenerator->GetCMakeInstance()->GetFileComparison();
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
int result;
|
|
|
|
if (!ftc->FileTimeCompare(internalDependFile.c_str(), tgtInfo, &result) ||
|
|
|
|
result < 0) {
|
|
|
|
if (verbose) {
|
|
|
|
std::ostringstream msg;
|
|
|
|
msg << "Dependee \"" << tgtInfo << "\" is newer than depender \""
|
|
|
|
<< internalDependFile << "\"." << std::endl;
|
|
|
|
cmSystemTools::Stdout(msg.str().c_str());
|
2008-03-12 00:53:54 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
needRescanDependInfo = true;
|
2008-03-12 00:53:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-22 22:40:23 +04:00
|
|
|
// If the directory information is newer than depend.internal, include dirs
|
|
|
|
// may have changed. In this case discard all old dependencies.
|
|
|
|
bool needRescanDirInfo = false;
|
2015-10-22 01:29:36 +03:00
|
|
|
std::string dirInfoFile = this->GetCurrentBinaryDirectory();
|
2009-09-22 22:40:23 +04:00
|
|
|
dirInfoFile += cmake::GetCMakeFilesDirectory();
|
|
|
|
dirInfoFile += "/CMakeDirectoryInformation.cmake";
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
int result;
|
|
|
|
if (!ftc->FileTimeCompare(internalDependFile.c_str(), dirInfoFile.c_str(),
|
|
|
|
&result) ||
|
|
|
|
result < 0) {
|
|
|
|
if (verbose) {
|
|
|
|
std::ostringstream msg;
|
|
|
|
msg << "Dependee \"" << dirInfoFile << "\" is newer than depender \""
|
|
|
|
<< internalDependFile << "\"." << std::endl;
|
|
|
|
cmSystemTools::Stdout(msg.str().c_str());
|
2009-09-22 22:40:23 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
needRescanDirInfo = true;
|
2009-09-22 22:40:23 +04:00
|
|
|
}
|
|
|
|
}
|
2010-11-12 00:02:07 +03:00
|
|
|
|
2007-12-20 00:36:30 +03:00
|
|
|
// Check the implicit dependencies to see if they are up to date.
|
|
|
|
// The build.make file may have explicit dependencies for the object
|
|
|
|
// files but these will not affect the scanning process so they need
|
|
|
|
// not be considered.
|
2009-09-23 22:02:05 +04:00
|
|
|
std::map<std::string, cmDepends::DependencyVector> validDependencies;
|
2009-09-22 22:40:23 +04:00
|
|
|
bool needRescanDependencies = false;
|
2016-06-02 00:29:53 +03:00
|
|
|
if (!needRescanDirInfo) {
|
2009-09-22 22:40:23 +04:00
|
|
|
cmDependsC checker;
|
|
|
|
checker.SetVerbose(verbose);
|
|
|
|
checker.SetFileComparison(ftc);
|
2009-09-23 22:02:05 +04:00
|
|
|
// cmDependsC::Check() fills the vector validDependencies() with the
|
|
|
|
// dependencies for those files where they are still valid, i.e. neither
|
|
|
|
// the files themselves nor any files they depend on have changed.
|
2010-11-12 00:02:07 +03:00
|
|
|
// We don't do that if the CMakeDirectoryInformation.cmake file has
|
2009-09-23 22:02:05 +04:00
|
|
|
// changed, because then potentially all dependencies have changed.
|
|
|
|
// This information is given later on to cmDependsC, which then only
|
|
|
|
// rescans the files where it did not get valid dependencies via this
|
2010-11-12 00:02:07 +03:00
|
|
|
// dependency vector. This means that in the normal case, when only
|
2009-09-23 22:02:05 +04:00
|
|
|
// few or one file have been edited, then also only this one file is
|
|
|
|
// actually scanned again, instead of all files for this target.
|
2016-05-16 17:34:04 +03:00
|
|
|
needRescanDependencies = !checker.Check(
|
|
|
|
dependFile.c_str(), internalDependFile.c_str(), validDependencies);
|
|
|
|
}
|
2009-09-22 22:40:23 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (needRescanDependInfo || needRescanDirInfo || needRescanDependencies) {
|
2007-12-20 00:36:30 +03:00
|
|
|
// The dependencies must be regenerated.
|
|
|
|
std::string targetName = cmSystemTools::GetFilenameName(dir);
|
2016-05-16 17:34:04 +03:00
|
|
|
targetName = targetName.substr(0, targetName.length() - 4);
|
2007-12-20 01:15:41 +03:00
|
|
|
std::string message = "Scanning dependencies of target ";
|
|
|
|
message += targetName;
|
2016-05-16 17:34:04 +03:00
|
|
|
cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundMagenta |
|
|
|
|
cmsysTerminal_Color_ForegroundBold,
|
|
|
|
message.c_str(), true, color);
|
2007-12-20 00:36:30 +03:00
|
|
|
|
2009-09-23 22:02:05 +04:00
|
|
|
return this->ScanDependencies(dir.c_str(), validDependencies);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-30 19:46:42 +04:00
|
|
|
|
|
|
|
// The dependencies are already up-to-date.
|
|
|
|
return true;
|
2007-12-20 00:36:30 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmLocalUnixMakefileGenerator3::ScanDependencies(
|
|
|
|
const char* targetDir,
|
|
|
|
std::map<std::string, cmDepends::DependencyVector>& validDeps)
|
2005-05-05 20:45:53 +04:00
|
|
|
{
|
|
|
|
// Read the directory information file.
|
2006-05-25 17:47:30 +04:00
|
|
|
cmMakefile* mf = this->Makefile;
|
2005-05-05 20:45:53 +04:00
|
|
|
bool haveDirectoryInfo = false;
|
2015-10-22 01:29:36 +03:00
|
|
|
std::string dirInfoFile = this->GetCurrentBinaryDirectory();
|
2006-06-14 20:28:32 +04:00
|
|
|
dirInfoFile += cmake::GetCMakeFilesDirectory();
|
|
|
|
dirInfoFile += "/CMakeDirectoryInformation.cmake";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (mf->ReadListFile(dirInfoFile.c_str()) &&
|
|
|
|
!cmSystemTools::GetErrorOccuredFlag()) {
|
2005-05-05 20:45:53 +04:00
|
|
|
haveDirectoryInfo = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-12 00:02:07 +03:00
|
|
|
|
2007-03-16 23:48:27 +03:00
|
|
|
// Lookup useful directory information.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (haveDirectoryInfo) {
|
2007-03-16 23:48:27 +03:00
|
|
|
// Test whether we need to force Unix paths.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* force = mf->GetDefinition("CMAKE_FORCE_UNIX_PATHS")) {
|
|
|
|
if (!cmSystemTools::IsOff(force)) {
|
2005-05-05 20:45:53 +04:00
|
|
|
cmSystemTools::SetForceUnixPaths(true);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-03-16 23:48:27 +03:00
|
|
|
|
|
|
|
// Setup relative path top directories.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* relativePathTopSource =
|
|
|
|
mf->GetDefinition("CMAKE_RELATIVE_PATH_TOP_SOURCE")) {
|
|
|
|
this->StateSnapshot.GetDirectory().SetRelativePathTopSource(
|
|
|
|
relativePathTopSource);
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* relativePathTopBinary =
|
|
|
|
mf->GetDefinition("CMAKE_RELATIVE_PATH_TOP_BINARY")) {
|
|
|
|
this->StateSnapshot.GetDirectory().SetRelativePathTopBinary(
|
|
|
|
relativePathTopBinary);
|
2005-06-07 18:47:28 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
cmSystemTools::Error("Directory Information file not found");
|
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
|
2005-07-27 17:49:37 +04:00
|
|
|
// create the file stream for the depends file
|
2007-12-21 20:22:12 +03:00
|
|
|
std::string dir = targetDir;
|
2008-05-08 01:25:05 +04:00
|
|
|
|
|
|
|
// Open the make depends file. This should be copy-if-different
|
|
|
|
// because the make tool may try to reload it needlessly otherwise.
|
2005-07-27 17:49:37 +04:00
|
|
|
std::string ruleFileNameFull = dir;
|
2005-10-12 21:52:29 +04:00
|
|
|
ruleFileNameFull += "/depend.make";
|
2005-07-27 17:49:37 +04:00
|
|
|
cmGeneratedFileStream ruleFileStream(ruleFileNameFull.c_str());
|
|
|
|
ruleFileStream.SetCopyIfDifferent(true);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!ruleFileStream) {
|
2005-07-27 17:49:37 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-05-08 01:25:05 +04:00
|
|
|
|
|
|
|
// Open the cmake dependency tracking file. This should not be
|
|
|
|
// copy-if-different because dependencies are re-scanned when it is
|
|
|
|
// older than the DependInfo.cmake.
|
2005-10-12 21:52:29 +04:00
|
|
|
std::string internalRuleFileNameFull = dir;
|
|
|
|
internalRuleFileNameFull += "/depend.internal";
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratedFileStream internalRuleFileStream(
|
|
|
|
internalRuleFileNameFull.c_str());
|
|
|
|
if (!internalRuleFileStream) {
|
2005-10-12 21:52:29 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-10-12 21:52:29 +04:00
|
|
|
|
2005-07-27 17:49:37 +04:00
|
|
|
this->WriteDisclaimer(ruleFileStream);
|
2005-10-12 21:52:29 +04:00
|
|
|
this->WriteDisclaimer(internalRuleFileStream);
|
2005-08-17 19:43:58 +04:00
|
|
|
|
2010-11-12 00:02:07 +03:00
|
|
|
// for each language we need to scan, scan it
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* langStr = mf->GetSafeDefinition("CMAKE_DEPENDS_LANGUAGES");
|
2005-07-27 17:49:37 +04:00
|
|
|
std::vector<std::string> langs;
|
|
|
|
cmSystemTools::ExpandListArgument(langStr, langs);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator li = langs.begin();
|
|
|
|
li != langs.end(); ++li) {
|
2005-07-27 17:49:37 +04:00
|
|
|
// construct the checker
|
2014-03-11 03:04:11 +04:00
|
|
|
std::string lang = *li;
|
2005-08-17 19:43:58 +04:00
|
|
|
|
2005-07-27 17:49:37 +04:00
|
|
|
// Create the scanner for this language
|
2016-06-27 23:44:16 +03:00
|
|
|
cmDepends* scanner = CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (lang == "C" || lang == "CXX" || lang == "RC" || lang == "ASM") {
|
2005-07-27 17:49:37 +04:00
|
|
|
// TODO: Handle RC (resource files) dependencies correctly.
|
2014-03-11 03:04:11 +04:00
|
|
|
scanner = new cmDependsC(this, targetDir, lang, &validDeps);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (lang == "Fortran") {
|
2008-05-08 18:09:14 +04:00
|
|
|
scanner = new cmDependsFortran(this);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (lang == "Java") {
|
2005-07-27 17:49:37 +04:00
|
|
|
scanner = new cmDependsJava();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-05 20:45:53 +04:00
|
|
|
#endif
|
2010-11-12 00:02:07 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (scanner) {
|
2007-10-12 17:32:48 +04:00
|
|
|
scanner->SetLocalGenerator(this);
|
2016-05-16 17:34:04 +03:00
|
|
|
scanner->SetFileComparison(
|
|
|
|
this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
|
2014-03-11 03:04:11 +04:00
|
|
|
scanner->SetLanguage(lang);
|
2007-12-23 06:41:42 +03:00
|
|
|
scanner->SetTargetDirectory(dir.c_str());
|
|
|
|
scanner->Write(ruleFileStream, internalRuleFileStream);
|
2005-08-19 18:13:04 +04:00
|
|
|
|
|
|
|
// free the scanner for this language
|
2005-07-27 17:49:37 +04:00
|
|
|
delete scanner;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-07-27 17:49:37 +04:00
|
|
|
|
|
|
|
return true;
|
2005-05-05 20:45:53 +04:00
|
|
|
}
|
|
|
|
|
2007-12-21 20:22:12 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::CheckMultipleOutputs(bool verbose)
|
|
|
|
{
|
|
|
|
cmMakefile* mf = this->Makefile;
|
|
|
|
|
|
|
|
// Get the string listing the multiple output pairs.
|
|
|
|
const char* pairs_string = mf->GetDefinition("CMAKE_MULTIPLE_OUTPUT_PAIRS");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!pairs_string) {
|
2007-12-21 20:22:12 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-21 20:22:12 +03:00
|
|
|
|
|
|
|
// Convert the string to a list and preserve empty entries.
|
|
|
|
std::vector<std::string> pairs;
|
|
|
|
cmSystemTools::ExpandListArgument(pairs_string, pairs, true);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator i = pairs.begin();
|
|
|
|
i != pairs.end() && (i + 1) != pairs.end();) {
|
2008-05-11 02:39:00 +04:00
|
|
|
const std::string& depender = *i++;
|
|
|
|
const std::string& dependee = *i++;
|
2007-12-21 20:22:12 +03:00
|
|
|
|
2008-05-11 02:39:00 +04:00
|
|
|
// If the depender is missing then delete the dependee to make
|
|
|
|
// sure both will be regenerated.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileExists(dependee.c_str()) &&
|
|
|
|
!cmSystemTools::FileExists(depender.c_str())) {
|
|
|
|
if (verbose) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream msg;
|
2008-05-11 02:39:00 +04:00
|
|
|
msg << "Deleting primary custom command output \"" << dependee
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "\" because another output \"" << depender
|
|
|
|
<< "\" does not exist." << std::endl;
|
2008-05-11 02:39:00 +04:00
|
|
|
cmSystemTools::Stdout(msg.str().c_str());
|
2007-12-21 20:22:12 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
cmSystemTools::RemoveFile(dependee);
|
2007-12-21 20:22:12 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-12-21 20:22:12 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
|
|
|
|
std::ostream& ruleFileStream)
|
2005-05-11 16:45:16 +04:00
|
|
|
{
|
|
|
|
this->WriteDisclaimer(ruleFileStream);
|
2006-02-16 00:35:16 +03:00
|
|
|
|
|
|
|
// Write the main entry point target. This must be the VERY first
|
|
|
|
// target so that make with no arguments will run it.
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
// Just depend on the all target to drive the build.
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
std::vector<std::string> no_commands;
|
|
|
|
depends.push_back("all");
|
2006-02-16 00:35:16 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// Write the rule.
|
2013-12-19 01:39:11 +04:00
|
|
|
this->WriteMakeRule(ruleFileStream,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Default target executed when no arguments are "
|
|
|
|
"given to make.",
|
|
|
|
"default_target", depends, no_commands, true);
|
|
|
|
|
|
|
|
// Help out users that try "gmake target1 target2 -j".
|
|
|
|
cmGlobalUnixMakefileGenerator3* gg =
|
|
|
|
static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
|
|
|
|
if (gg->AllowNotParallel()) {
|
|
|
|
std::vector<std::string> no_depends;
|
|
|
|
this->WriteMakeRule(ruleFileStream, "Allow only one \"make -f "
|
|
|
|
"Makefile2\" at a time, but pass "
|
|
|
|
"parallelism.",
|
|
|
|
".NOTPARALLEL", no_depends, no_commands, false);
|
2013-12-19 01:39:11 +04:00
|
|
|
}
|
2006-02-16 00:35:16 +03:00
|
|
|
}
|
|
|
|
|
2006-09-08 18:42:14 +04:00
|
|
|
this->WriteSpecialTargetsTop(ruleFileStream);
|
|
|
|
|
|
|
|
// Include the progress variables for the target.
|
2006-02-23 18:07:24 +03:00
|
|
|
// Write all global targets
|
2006-09-08 18:42:14 +04:00
|
|
|
this->WriteDivider(ruleFileStream);
|
2016-05-16 17:34:04 +03:00
|
|
|
ruleFileStream << "# Targets provided globally by CMake.\n"
|
|
|
|
<< "\n";
|
2015-10-18 18:06:14 +03:00
|
|
|
std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
|
|
|
|
std::vector<cmGeneratorTarget*>::iterator glIt;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (glIt = targets.begin(); glIt != targets.end(); ++glIt) {
|
|
|
|
if ((*glIt)->GetType() == cmState::GLOBAL_TARGET) {
|
|
|
|
std::string targetString =
|
|
|
|
"Special rule for the target " + (*glIt)->GetName();
|
2006-02-23 18:07:24 +03:00
|
|
|
std::vector<std::string> commands;
|
|
|
|
std::vector<std::string> depends;
|
|
|
|
|
2015-10-18 18:06:14 +03:00
|
|
|
const char* text = (*glIt)->GetProperty("EchoString");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!text) {
|
2006-02-23 18:07:24 +03:00
|
|
|
text = "Running external command ...";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-23 02:01:46 +03:00
|
|
|
depends.insert(depends.end(), (*glIt)->GetUtilities().begin(),
|
|
|
|
(*glIt)->GetUtilities().end());
|
2006-03-31 00:39:03 +04:00
|
|
|
this->AppendEcho(commands, text,
|
|
|
|
cmLocalUnixMakefileGenerator3::EchoGlobal);
|
2006-02-23 18:07:24 +03:00
|
|
|
|
2015-10-18 18:06:14 +03:00
|
|
|
cmGeneratorTarget* gt = *glIt;
|
2015-10-09 23:19:57 +03:00
|
|
|
|
2006-06-01 22:43:28 +04:00
|
|
|
// Global targets store their rules in pre- and post-build commands.
|
2016-05-16 17:34:04 +03:00
|
|
|
this->AppendCustomDepends(depends, gt->GetPreBuildCommands());
|
|
|
|
this->AppendCustomDepends(depends, gt->GetPostBuildCommands());
|
|
|
|
this->AppendCustomCommands(commands, gt->GetPreBuildCommands(), gt,
|
2016-08-27 14:44:53 +03:00
|
|
|
this->GetCurrentBinaryDirectory());
|
2016-05-16 17:34:04 +03:00
|
|
|
this->AppendCustomCommands(commands, gt->GetPostBuildCommands(), gt,
|
2016-08-27 14:44:53 +03:00
|
|
|
this->GetCurrentBinaryDirectory());
|
2015-10-18 18:06:14 +03:00
|
|
|
std::string targetName = gt->GetName();
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteMakeRule(ruleFileStream, targetString.c_str(), targetName,
|
|
|
|
depends, commands, true);
|
2006-06-01 22:43:28 +04:00
|
|
|
|
|
|
|
// Provide a "/fast" version of the target.
|
|
|
|
depends.clear();
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((targetName == "install") || (targetName == "install_local") ||
|
|
|
|
(targetName == "install_strip")) {
|
2006-06-01 22:43:28 +04:00
|
|
|
// Provide a fast install target that does not depend on all
|
|
|
|
// but has the same command.
|
|
|
|
depends.push_back("preinstall/fast");
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2006-06-01 22:43:28 +04:00
|
|
|
// Just forward to the real target so at least it will work.
|
|
|
|
depends.push_back(targetName);
|
|
|
|
commands.clear();
|
2006-02-16 00:35:16 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
targetName += "/fast";
|
|
|
|
this->WriteMakeRule(ruleFileStream, targetString.c_str(), targetName,
|
|
|
|
depends, commands, true);
|
2006-02-16 00:35:16 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-16 00:35:16 +03:00
|
|
|
|
2005-05-11 16:45:16 +04:00
|
|
|
std::vector<std::string> depends;
|
|
|
|
std::vector<std::string> commands;
|
2006-02-16 00:35:16 +03:00
|
|
|
|
2005-05-25 23:09:06 +04:00
|
|
|
// Write the all rule.
|
2015-10-22 01:29:36 +03:00
|
|
|
std::string recursiveTarget = this->GetCurrentBinaryDirectory();
|
2006-10-10 21:47:50 +04:00
|
|
|
recursiveTarget += "/all";
|
2006-03-15 19:02:08 +03:00
|
|
|
|
2006-03-02 02:54:17 +03:00
|
|
|
depends.push_back("cmake_check_build_system");
|
2006-03-15 19:02:08 +03:00
|
|
|
|
2015-10-07 02:17:48 +03:00
|
|
|
std::string progressDir = this->GetBinaryDirectory();
|
2006-06-27 18:24:09 +04:00
|
|
|
progressDir += cmake::GetCMakeFilesDirectory();
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream progCmd;
|
2016-05-16 17:34:04 +03:00
|
|
|
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start ";
|
2016-08-27 14:44:57 +03:00
|
|
|
progCmd << this->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(progressDir), cmOutputConverter::SHELL);
|
2008-01-18 18:25:25 +03:00
|
|
|
|
|
|
|
std::string progressFile = cmake::GetCMakeFilesDirectory();
|
2009-06-25 17:58:51 +04:00
|
|
|
progressFile += "/progress.marks";
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string progressFileNameFull = this->ConvertToFullPath(progressFile);
|
|
|
|
progCmd << " "
|
2016-08-27 14:44:57 +03:00
|
|
|
<< this->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(progressFileNameFull),
|
|
|
|
cmOutputConverter::SHELL);
|
2006-06-27 22:26:35 +04:00
|
|
|
commands.push_back(progCmd.str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-06-14 20:28:32 +04:00
|
|
|
std::string mf2Dir = cmake::GetCMakeFilesDirectoryPostSlash();
|
|
|
|
mf2Dir += "Makefile2";
|
2016-05-16 17:34:04 +03:00
|
|
|
commands.push_back(
|
|
|
|
this->GetRecursiveMakeCall(mf2Dir.c_str(), recursiveTarget));
|
|
|
|
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->GetCurrentBinaryDirectory());
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream progCmd;
|
2006-05-31 00:23:24 +04:00
|
|
|
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0
|
2016-08-27 14:44:57 +03:00
|
|
|
progCmd << this->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::CollapseFullPath(progressDir), cmOutputConverter::SHELL);
|
2006-05-23 17:58:10 +04:00
|
|
|
progCmd << " 0";
|
2006-05-23 17:11:46 +04:00
|
|
|
commands.push_back(progCmd.str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
this->WriteMakeRule(ruleFileStream, "The main all target", "all", depends,
|
|
|
|
commands, true);
|
2005-05-11 16:45:16 +04:00
|
|
|
|
2005-05-25 23:09:06 +04:00
|
|
|
// Write the clean rule.
|
2015-10-22 01:29:36 +03:00
|
|
|
recursiveTarget = this->GetCurrentBinaryDirectory();
|
2006-10-10 21:47:50 +04:00
|
|
|
recursiveTarget += "/clean";
|
2005-05-25 23:09:06 +04:00
|
|
|
commands.clear();
|
2005-10-20 22:25:08 +04:00
|
|
|
depends.clear();
|
2016-05-16 17:34:04 +03:00
|
|
|
commands.push_back(
|
|
|
|
this->GetRecursiveMakeCall(mf2Dir.c_str(), recursiveTarget));
|
|
|
|
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->GetCurrentBinaryDirectory());
|
2006-02-16 00:35:16 +03:00
|
|
|
this->WriteMakeRule(ruleFileStream, "The main clean target", "clean",
|
|
|
|
depends, commands, true);
|
2006-05-02 17:56:42 +04:00
|
|
|
commands.clear();
|
|
|
|
depends.clear();
|
|
|
|
depends.push_back("clean");
|
|
|
|
this->WriteMakeRule(ruleFileStream, "The main clean target", "clean/fast",
|
|
|
|
depends, commands, true);
|
2005-05-25 23:09:06 +04:00
|
|
|
|
2006-03-02 02:54:17 +03:00
|
|
|
// Write the preinstall rule.
|
2015-10-22 01:29:36 +03:00
|
|
|
recursiveTarget = this->GetCurrentBinaryDirectory();
|
2006-10-10 21:47:50 +04:00
|
|
|
recursiveTarget += "/preinstall";
|
2006-03-02 02:54:17 +03:00
|
|
|
commands.clear();
|
|
|
|
depends.clear();
|
|
|
|
const char* noall =
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!noall || cmSystemTools::IsOff(noall)) {
|
2006-03-02 02:54:17 +03:00
|
|
|
// Drive the build before installing.
|
|
|
|
depends.push_back("all");
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2006-03-02 02:54:17 +03:00
|
|
|
// At least make sure the build system is up to date.
|
|
|
|
depends.push_back("cmake_check_build_system");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
commands.push_back(
|
|
|
|
this->GetRecursiveMakeCall(mf2Dir.c_str(), recursiveTarget));
|
|
|
|
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->GetCurrentBinaryDirectory());
|
2006-03-02 02:54:17 +03:00
|
|
|
this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
|
|
|
|
"preinstall", depends, commands, true);
|
2006-06-01 22:09:21 +04:00
|
|
|
depends.clear();
|
2006-05-02 21:31:56 +04:00
|
|
|
this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
|
|
|
|
"preinstall/fast", depends, commands, true);
|
2006-03-02 02:54:17 +03:00
|
|
|
|
2005-10-20 21:40:28 +04:00
|
|
|
// write the depend rule, really a recompute depends rule
|
|
|
|
depends.clear();
|
|
|
|
commands.clear();
|
2006-06-14 20:28:32 +04:00
|
|
|
std::string cmakefileName = cmake::GetCMakeFilesDirectoryPostSlash();
|
|
|
|
cmakefileName += "Makefile.cmake";
|
2005-10-20 21:40:28 +04:00
|
|
|
std::string runRule =
|
|
|
|
"$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
|
|
|
|
runRule += " --check-build-system ";
|
2016-08-27 14:44:55 +03:00
|
|
|
runRule +=
|
|
|
|
this->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL);
|
2005-10-20 21:40:28 +04:00
|
|
|
runRule += " 1";
|
|
|
|
commands.push_back(runRule);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
|
2016-08-27 14:44:52 +03:00
|
|
|
this->GetCurrentBinaryDirectory());
|
2016-05-16 17:34:04 +03:00
|
|
|
this->WriteMakeRule(ruleFileStream, "clear depends", "depend", depends,
|
|
|
|
commands, true);
|
2005-10-20 21:40:28 +04:00
|
|
|
}
|
|
|
|
|
2007-12-20 00:36:30 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::ClearDependencies(cmMakefile* mf,
|
|
|
|
bool verbose)
|
2005-10-20 21:40:28 +04:00
|
|
|
{
|
2006-02-15 18:34:11 +03:00
|
|
|
// Get the list of target files to check
|
|
|
|
const char* infoDef = mf->GetDefinition("CMAKE_DEPEND_INFO_FILES");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!infoDef) {
|
2005-10-20 21:40:28 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
std::vector<std::string> files;
|
|
|
|
cmSystemTools::ExpandListArgument(infoDef, files);
|
|
|
|
|
2007-12-20 00:36:30 +03:00
|
|
|
// Each depend information file corresponds to a target. Clear the
|
|
|
|
// dependencies for that target.
|
|
|
|
cmDepends clearer;
|
|
|
|
clearer.SetVerbose(verbose);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator l = files.begin(); l != files.end();
|
|
|
|
++l) {
|
2014-03-11 03:04:11 +04:00
|
|
|
std::string dir = cmSystemTools::GetFilenamePath(*l);
|
2007-12-20 00:36:30 +03:00
|
|
|
|
|
|
|
// Clear the implicit dependency makefile.
|
2006-02-15 18:34:11 +03:00
|
|
|
std::string dependFile = dir + "/depend.make";
|
2007-12-20 00:36:30 +03:00
|
|
|
clearer.Clear(dependFile.c_str());
|
|
|
|
|
|
|
|
// Remove the internal dependency check file to force
|
|
|
|
// regeneration.
|
|
|
|
std::string internalDependFile = dir + "/depend.internal";
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveFile(internalDependFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
namespace {
|
|
|
|
// Helper predicate for removing absolute paths that don't point to the
|
|
|
|
// source or binary directory. It is used when CMAKE_DEPENDS_IN_PROJECT_ONLY
|
|
|
|
// is set ON, to only consider in-project dependencies during the build.
|
|
|
|
class NotInProjectDir
|
2016-03-22 15:18:42 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
public:
|
|
|
|
// Constructor with the source and binary directory's path
|
|
|
|
NotInProjectDir(const std::string& sourceDir, const std::string& binaryDir)
|
|
|
|
: SourceDir(sourceDir)
|
|
|
|
, BinaryDir(binaryDir)
|
2016-03-22 15:18:42 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-03-22 15:18:42 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// Operator evaluating the predicate
|
|
|
|
bool operator()(const std::string& path) const
|
|
|
|
{
|
|
|
|
// Keep all relative paths:
|
|
|
|
if (!cmSystemTools::FileIsFullPath(path)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// If it's an absolute path, check if it starts with the source
|
|
|
|
// direcotory:
|
|
|
|
return (
|
|
|
|
!(IsInDirectory(SourceDir, path) || IsInDirectory(BinaryDir, path)));
|
|
|
|
}
|
2016-03-22 15:18:42 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
private:
|
|
|
|
// Helper function used by the predicate
|
|
|
|
static bool IsInDirectory(const std::string& baseDir,
|
|
|
|
const std::string& testDir)
|
|
|
|
{
|
|
|
|
// First check if the test directory "starts with" the base directory:
|
|
|
|
if (testDir.find(baseDir) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// If it does, then check that it's either the same string, or that the
|
|
|
|
// next character is a slash:
|
|
|
|
return ((testDir.size() == baseDir.size()) ||
|
|
|
|
(testDir[baseDir.size()] == '/'));
|
|
|
|
}
|
2016-03-22 15:18:42 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
// The path to the source directory
|
|
|
|
std::string SourceDir;
|
|
|
|
// The path to the binary directory
|
|
|
|
std::string BinaryDir;
|
|
|
|
};
|
|
|
|
}
|
2016-03-22 15:18:42 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
|
|
|
|
std::ostream& cmakefileStream, cmGeneratorTarget* target)
|
2006-02-15 18:34:11 +03:00
|
|
|
{
|
2007-08-07 21:57:13 +04:00
|
|
|
ImplicitDependLanguageMap const& implicitLangs =
|
2015-10-19 00:20:47 +03:00
|
|
|
this->GetImplicitDepends(target);
|
2007-08-07 21:57:13 +04:00
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
// list the languages
|
|
|
|
cmakefileStream
|
2007-08-07 21:57:13 +04:00
|
|
|
<< "# The set of languages for which implicit dependencies are needed:\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
cmakefileStream << "set(CMAKE_DEPENDS_LANGUAGES\n";
|
|
|
|
for (ImplicitDependLanguageMap::const_iterator l = implicitLangs.begin();
|
|
|
|
l != implicitLangs.end(); ++l) {
|
2014-03-11 16:35:32 +04:00
|
|
|
cmakefileStream << " \"" << l->first << "\"\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
cmakefileStream << " )\n";
|
2007-08-07 21:57:13 +04:00
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
// now list the files for each language
|
2007-08-07 21:57:13 +04:00
|
|
|
cmakefileStream
|
|
|
|
<< "# The set of files for implicit dependencies of each language:\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (ImplicitDependLanguageMap::const_iterator l = implicitLangs.begin();
|
|
|
|
l != implicitLangs.end(); ++l) {
|
|
|
|
cmakefileStream << "set(CMAKE_DEPENDS_CHECK_" << l->first << "\n";
|
2007-08-07 21:57:13 +04:00
|
|
|
ImplicitDependFileMap const& implicitPairs = l->second;
|
|
|
|
|
|
|
|
// for each file pair
|
2016-05-16 17:34:04 +03:00
|
|
|
for (ImplicitDependFileMap::const_iterator pi = implicitPairs.begin();
|
|
|
|
pi != implicitPairs.end(); ++pi) {
|
|
|
|
for (cmDepends::DependencyVector::const_iterator di = pi->second.begin();
|
|
|
|
di != pi->second.end(); ++di) {
|
2012-09-30 20:34:57 +04:00
|
|
|
cmakefileStream << " \"" << *di << "\" ";
|
|
|
|
cmakefileStream << "\"" << pi->first << "\"\n";
|
2006-02-15 18:34:11 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
cmakefileStream << " )\n";
|
2008-01-02 19:04:52 +03:00
|
|
|
|
|
|
|
// Tell the dependency scanner what compiler is used.
|
|
|
|
std::string cidVar = "CMAKE_";
|
|
|
|
cidVar += l->first;
|
|
|
|
cidVar += "_COMPILER_ID";
|
2014-03-11 03:04:11 +04:00
|
|
|
const char* cid = this->Makefile->GetDefinition(cidVar);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cid && *cid) {
|
|
|
|
cmakefileStream << "set(CMAKE_" << l->first << "_COMPILER_ID \"" << cid
|
|
|
|
<< "\")\n";
|
|
|
|
}
|
2008-01-09 18:30:11 +03:00
|
|
|
|
2015-03-04 23:46:42 +03:00
|
|
|
// Build a list of preprocessor definitions for the target.
|
|
|
|
std::set<std::string> defines;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->AddCompileDefinitions(defines, target, this->ConfigName, l->first);
|
|
|
|
if (!defines.empty()) {
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2008-01-18 03:58:01 +03:00
|
|
|
cmakefileStream
|
2015-03-04 23:46:42 +03:00
|
|
|
<< "\n"
|
|
|
|
<< "# Preprocessor definitions for this target.\n"
|
|
|
|
<< "set(CMAKE_TARGET_DEFINITIONS_" << l->first << "\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator di = defines.begin();
|
|
|
|
di != defines.end(); ++di) {
|
|
|
|
cmakefileStream << " " << cmOutputConverter::EscapeForCMake(*di)
|
|
|
|
<< "\n";
|
2008-01-18 03:58:01 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
cmakefileStream << " )\n";
|
|
|
|
}
|
2015-03-04 23:53:15 +03:00
|
|
|
|
|
|
|
// Target-specific include directories:
|
2016-05-16 17:34:04 +03:00
|
|
|
cmakefileStream << "\n"
|
|
|
|
<< "# The include file search paths:\n";
|
|
|
|
cmakefileStream << "set(CMAKE_" << l->first << "_TARGET_INCLUDE_PATH\n";
|
2015-03-04 23:53:15 +03:00
|
|
|
std::vector<std::string> includes;
|
|
|
|
|
|
|
|
const std::string& config =
|
|
|
|
this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GetIncludeDirectories(includes, target, l->first, config);
|
|
|
|
if (this->Makefile->IsOn("CMAKE_DEPENDS_IN_PROJECT_ONLY")) {
|
2016-03-22 15:18:42 +03:00
|
|
|
const char* sourceDir = this->GetState()->GetSourceDirectory();
|
|
|
|
const char* binaryDir = this->GetState()->GetBinaryDirectory();
|
|
|
|
std::vector<std::string>::iterator itr =
|
|
|
|
std::remove_if(includes.begin(), includes.end(),
|
|
|
|
::NotInProjectDir(sourceDir, binaryDir));
|
|
|
|
includes.erase(itr, includes.end());
|
2008-01-18 03:58:01 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator i = includes.begin();
|
|
|
|
i != includes.end(); ++i) {
|
|
|
|
cmakefileStream << " \""
|
2016-08-27 14:44:56 +03:00
|
|
|
<< this->ConvertToRelativePath(
|
|
|
|
*i, cmOutputConverter::HOME_OUTPUT)
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "\"\n";
|
|
|
|
}
|
|
|
|
cmakefileStream << " )\n";
|
|
|
|
}
|
2008-05-14 19:54:52 +04:00
|
|
|
|
|
|
|
// Store include transform rule properties. Write the directory
|
|
|
|
// rules first because they may be overridden by later target rules.
|
|
|
|
std::vector<std::string> transformRules;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* xform =
|
|
|
|
this->Makefile->GetProperty("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM")) {
|
2008-05-14 19:54:52 +04:00
|
|
|
cmSystemTools::ExpandListArgument(xform, transformRules);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (const char* xform =
|
|
|
|
target->GetProperty("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM")) {
|
2008-05-14 19:54:52 +04:00
|
|
|
cmSystemTools::ExpandListArgument(xform, transformRules);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!transformRules.empty()) {
|
|
|
|
cmakefileStream << "set(CMAKE_INCLUDE_TRANSFORMS\n";
|
|
|
|
for (std::vector<std::string>::const_iterator tri = transformRules.begin();
|
|
|
|
tri != transformRules.end(); ++tri) {
|
|
|
|
cmakefileStream << " " << cmOutputConverter::EscapeForCMake(*tri)
|
|
|
|
<< "\n";
|
2008-05-14 19:54:52 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
cmakefileStream << " )\n";
|
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmLocalUnixMakefileGenerator3::WriteDisclaimer(std::ostream& os)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
os << "# CMAKE generated file: DO NOT EDIT!\n"
|
|
|
|
<< "# Generated by \"" << this->GlobalGenerator->GetName() << "\""
|
|
|
|
<< " Generator, CMake Version " << cmVersion::GetMajorVersion() << "."
|
|
|
|
<< cmVersion::GetMinorVersion() << "\n\n";
|
2006-02-15 18:34:11 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmLocalUnixMakefileGenerator3::GetRecursiveMakeCall(
|
|
|
|
const char* makefile, const std::string& tgt)
|
2006-02-15 18:34:11 +03:00
|
|
|
{
|
|
|
|
// Call make on the given file.
|
|
|
|
std::string cmd;
|
|
|
|
cmd += "$(MAKE) -f ";
|
2016-08-27 14:44:55 +03:00
|
|
|
cmd += this->ConvertToOutputFormat(makefile, cmOutputConverter::SHELL);
|
2006-02-15 18:34:11 +03:00
|
|
|
cmd += " ";
|
2010-11-12 00:02:07 +03:00
|
|
|
|
2015-05-16 06:23:06 +03:00
|
|
|
cmGlobalUnixMakefileGenerator3* gg =
|
|
|
|
static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
|
2009-02-10 00:36:56 +03:00
|
|
|
// Pass down verbosity level.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!gg->MakeSilentFlag.empty()) {
|
2015-05-16 06:23:06 +03:00
|
|
|
cmd += gg->MakeSilentFlag;
|
2006-02-15 18:34:11 +03:00
|
|
|
cmd += " ";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-10-20 21:40:28 +04:00
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
// Most unix makes will pass the command line flags to make down to
|
|
|
|
// sub-invoked makes via an environment variable. However, some
|
|
|
|
// makes do not support that, so you have to pass the flags
|
|
|
|
// explicitly.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (gg->PassMakeflags) {
|
2006-02-15 18:34:11 +03:00
|
|
|
cmd += "-$(MAKEFLAGS) ";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
|
|
|
|
// Add the target.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!tgt.empty()) {
|
2007-03-08 19:49:30 +03:00
|
|
|
// The make target is always relative to the top of the build tree.
|
2016-08-27 14:44:56 +03:00
|
|
|
std::string tgt2 =
|
|
|
|
this->ConvertToRelativePath(tgt, cmOutputConverter::HOME_OUTPUT);
|
2007-03-08 19:49:30 +03:00
|
|
|
|
|
|
|
// The target may have been written with windows paths.
|
|
|
|
cmSystemTools::ConvertToOutputSlashes(tgt2);
|
|
|
|
|
2007-03-08 21:05:02 +03:00
|
|
|
// Escape one extra time if the make tool requires it.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->MakeCommandEscapeTargetTwice) {
|
2014-03-11 03:04:11 +04:00
|
|
|
tgt2 = this->EscapeForShell(tgt2, true, false);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-03-08 21:05:02 +03:00
|
|
|
|
2007-03-08 19:49:30 +03:00
|
|
|
// The target name is now a string that should be passed verbatim
|
|
|
|
// on the command line.
|
2014-03-11 03:04:11 +04:00
|
|
|
cmd += this->EscapeForShell(tgt2, true, false);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmLocalUnixMakefileGenerator3::WriteDivider(std::ostream& os)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
os << "#======================================"
|
|
|
|
<< "=======================================\n";
|
2006-02-15 18:34:11 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::WriteCMakeArgument(std::ostream& os,
|
|
|
|
const char* s)
|
2006-02-15 18:34:11 +03:00
|
|
|
{
|
|
|
|
// Write the given string to the stream with escaping to get it back
|
|
|
|
// into CMake through the lexical scanner.
|
|
|
|
os << "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (const char* c = s; *c; ++c) {
|
|
|
|
if (*c == '\\') {
|
2006-02-15 18:34:11 +03:00
|
|
|
os << "\\\\";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (*c == '"') {
|
2006-02-15 18:34:11 +03:00
|
|
|
os << "\\\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2006-02-15 18:34:11 +03:00
|
|
|
os << *c;
|
2005-06-02 21:41:34 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
os << "\"";
|
|
|
|
}
|
2005-06-30 17:53:03 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(
|
|
|
|
const char* p, bool useWatcomQuote)
|
2006-02-15 18:34:11 +03:00
|
|
|
{
|
|
|
|
// Split the path into its components.
|
|
|
|
std::vector<std::string> components;
|
|
|
|
cmSystemTools::SplitPath(p, components);
|
|
|
|
|
2014-03-25 10:17:45 +04:00
|
|
|
// Open the quoted result.
|
2014-03-25 10:17:45 +04:00
|
|
|
std::string result;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (useWatcomQuote) {
|
2014-03-25 10:17:45 +04:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
result = "'";
|
|
|
|
#else
|
|
|
|
result = "\"'";
|
|
|
|
#endif
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-03-25 10:17:45 +04:00
|
|
|
result = "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-25 10:17:45 +04:00
|
|
|
|
2006-02-15 18:34:11 +03:00
|
|
|
// Return an empty path if there are no components.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!components.empty()) {
|
2014-03-25 10:17:45 +04:00
|
|
|
// Choose a slash direction and fix root component.
|
|
|
|
const char* slash = "/";
|
2006-02-15 18:34:11 +03:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::GetForceUnixPaths()) {
|
2014-03-25 10:17:45 +04:00
|
|
|
slash = "\\";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::string::iterator i = components[0].begin();
|
|
|
|
i != components[0].end(); ++i) {
|
|
|
|
if (*i == '/') {
|
2014-03-25 10:17:45 +04:00
|
|
|
*i = '\\';
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
#endif
|
2005-05-11 16:45:16 +04:00
|
|
|
|
2014-03-25 10:17:45 +04:00
|
|
|
// Begin the quoted result with the root component.
|
|
|
|
result += components[0];
|
2005-05-11 16:45:16 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (components.size() > 1) {
|
2015-02-11 01:09:03 +03:00
|
|
|
// Now add the rest of the components separated by the proper slash
|
|
|
|
// direction for this platform.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<std::string>::const_iterator compEnd = std::remove(
|
|
|
|
components.begin() + 1, components.end() - 1, std::string());
|
|
|
|
std::vector<std::string>::const_iterator compStart =
|
|
|
|
components.begin() + 1;
|
2015-07-18 11:45:18 +03:00
|
|
|
result += cmJoin(cmMakeRange(compStart, compEnd), slash);
|
2014-03-25 10:17:45 +04:00
|
|
|
// Only the last component can be empty to avoid double slashes.
|
2015-01-23 03:06:40 +03:00
|
|
|
result += slash;
|
2015-01-23 03:03:45 +03:00
|
|
|
result += components.back();
|
2005-05-11 16:45:16 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
|
|
|
|
// Close the quoted result.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (useWatcomQuote) {
|
2014-03-25 10:17:45 +04:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
result += "'";
|
|
|
|
#else
|
|
|
|
result += "'\"";
|
|
|
|
#endif
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-03-25 10:17:45 +04:00
|
|
|
result += "\"";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-02-15 18:34:11 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmLocalUnixMakefileGenerator3::GetTargetDirectory(
|
|
|
|
cmGeneratorTarget const* target) const
|
2006-02-15 18:34:11 +03:00
|
|
|
{
|
2006-06-14 20:28:32 +04:00
|
|
|
std::string dir = cmake::GetCMakeFilesDirectoryPostSlash();
|
2015-10-09 23:27:46 +03:00
|
|
|
dir += target->GetName();
|
2009-06-10 21:03:11 +04:00
|
|
|
#if defined(__VMS)
|
|
|
|
dir += "_dir";
|
|
|
|
#else
|
2006-02-15 18:34:11 +03:00
|
|
|
dir += ".dir";
|
2009-06-10 21:03:11 +04:00
|
|
|
#endif
|
2006-02-15 18:34:11 +03:00
|
|
|
return dir;
|
2005-05-11 16:45:16 +04:00
|
|
|
}
|
|
|
|
|
2007-08-07 21:57:13 +04:00
|
|
|
cmLocalUnixMakefileGenerator3::ImplicitDependLanguageMap const&
|
2016-05-16 17:34:04 +03:00
|
|
|
cmLocalUnixMakefileGenerator3::GetImplicitDepends(const cmGeneratorTarget* tgt)
|
2007-08-07 21:57:13 +04:00
|
|
|
{
|
2015-10-19 00:20:47 +03:00
|
|
|
return this->ImplicitDepends[tgt->GetName()];
|
2007-08-07 21:57:13 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::AddImplicitDepends(
|
|
|
|
const cmGeneratorTarget* tgt, const std::string& lang, const char* obj,
|
|
|
|
const char* src)
|
2007-08-07 21:57:13 +04:00
|
|
|
{
|
2015-10-19 00:20:47 +03:00
|
|
|
this->ImplicitDepends[tgt->GetName()][lang][obj].push_back(src);
|
2007-08-07 21:57:13 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmLocalUnixMakefileGenerator3::CreateCDCommand(
|
|
|
|
std::vector<std::string>& commands, const char* tgtDir,
|
2016-08-27 14:44:52 +03:00
|
|
|
std::string const& relDir)
|
2005-05-11 16:45:16 +04:00
|
|
|
{
|
2005-10-20 21:40:28 +04:00
|
|
|
// do we need to cd?
|
2016-08-27 14:44:52 +03:00
|
|
|
if (tgtDir == relDir) {
|
2005-10-20 21:40:28 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-12 00:02:07 +03:00
|
|
|
|
2011-04-09 00:12:18 +04:00
|
|
|
// In a Windows shell we must change drive letter too. The shell
|
|
|
|
// used by NMake and Borland make does not support "cd /d" so this
|
|
|
|
// feature simply cannot work with them (Borland make does not even
|
|
|
|
// support changing the drive letter with just "d:").
|
2015-05-04 23:40:11 +03:00
|
|
|
const char* cd_cmd = this->IsMinGWMake() ? "cd /d " : "cd ";
|
2011-04-08 17:28:59 +04:00
|
|
|
|
2015-05-16 06:21:24 +03:00
|
|
|
cmGlobalUnixMakefileGenerator3* gg =
|
|
|
|
static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!gg->UnixCD) {
|
2005-05-11 16:45:16 +04:00
|
|
|
// On Windows we must perform each step separately and then change
|
|
|
|
// back because the shell keeps the working directory between
|
|
|
|
// commands.
|
2011-04-08 17:28:59 +04:00
|
|
|
std::string cmd = cd_cmd;
|
2016-06-21 00:03:28 +03:00
|
|
|
cmd += this->ConvertToOutputForExisting(tgtDir);
|
2016-05-16 17:34:04 +03:00
|
|
|
commands.insert(commands.begin(), cmd);
|
2008-10-09 23:30:07 +04:00
|
|
|
|
|
|
|
// Change back to the starting directory.
|
2011-04-08 17:28:59 +04:00
|
|
|
cmd = cd_cmd;
|
2016-08-27 14:44:52 +03:00
|
|
|
cmd += this->ConvertToOutputForExisting(relDir);
|
2005-05-11 16:45:16 +04:00
|
|
|
commands.push_back(cmd);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2005-05-11 16:45:16 +04:00
|
|
|
// On UNIX we must construct a single shell command to change
|
|
|
|
// directory and build because make resets the directory between
|
|
|
|
// each command.
|
2016-06-21 00:03:28 +03:00
|
|
|
std::string outputForExisting = this->ConvertToOutputForExisting(tgtDir);
|
2015-01-25 17:07:27 +03:00
|
|
|
std::string prefix = cd_cmd + outputForExisting + " && ";
|
2015-01-18 18:01:54 +03:00
|
|
|
std::transform(commands.begin(), commands.end(), commands.begin(),
|
|
|
|
std::bind1st(std::plus<std::string>(), prefix));
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-05-11 16:45:16 +04:00
|
|
|
}
|