2011-11-11 09:00:49 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
|
|
|
|
Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmNinjaTargetGenerator.h"
|
|
|
|
#include "cmGlobalNinjaGenerator.h"
|
|
|
|
#include "cmLocalNinjaGenerator.h"
|
|
|
|
#include "cmGeneratedFileStream.h"
|
2012-03-13 17:24:54 +04:00
|
|
|
#include "cmGeneratorTarget.h"
|
2011-11-11 09:00:49 +04:00
|
|
|
#include "cmNinjaNormalTargetGenerator.h"
|
|
|
|
#include "cmNinjaUtilityTargetGenerator.h"
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
#include "cmComputeLinkInformation.h"
|
|
|
|
#include "cmSourceFile.h"
|
|
|
|
#include "cmCustomCommandGenerator.h"
|
2015-06-04 22:56:56 +03:00
|
|
|
#include "cmAlgorithms.h"
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
cmNinjaTargetGenerator *
|
2012-10-10 23:32:37 +04:00
|
|
|
cmNinjaTargetGenerator::New(cmGeneratorTarget* target)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
switch (target->GetType())
|
|
|
|
{
|
|
|
|
case cmTarget::EXECUTABLE:
|
|
|
|
case cmTarget::SHARED_LIBRARY:
|
|
|
|
case cmTarget::STATIC_LIBRARY:
|
|
|
|
case cmTarget::MODULE_LIBRARY:
|
2012-03-13 18:05:07 +04:00
|
|
|
case cmTarget::OBJECT_LIBRARY:
|
2011-11-11 09:00:49 +04:00
|
|
|
return new cmNinjaNormalTargetGenerator(target);
|
|
|
|
|
|
|
|
case cmTarget::UTILITY:
|
|
|
|
return new cmNinjaUtilityTargetGenerator(target);;
|
|
|
|
|
|
|
|
case cmTarget::GLOBAL_TARGET: {
|
|
|
|
// We only want to process global targets that live in the home
|
|
|
|
// (i.e. top-level) directory. CMake creates copies of these targets
|
|
|
|
// in every directory, which we don't need.
|
2012-10-10 23:32:37 +04:00
|
|
|
cmMakefile *mf = target->Target->GetMakefile();
|
2015-04-16 21:06:54 +03:00
|
|
|
if (strcmp(mf->GetCurrentSourceDirectory(),
|
|
|
|
mf->GetHomeDirectory()) == 0)
|
2011-11-11 09:00:49 +04:00
|
|
|
return new cmNinjaUtilityTargetGenerator(target);
|
|
|
|
// else fallthrough
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 15:02:24 +03:00
|
|
|
cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target)
|
2015-07-08 18:13:11 +03:00
|
|
|
: cmCommonTargetGenerator(target),
|
2012-07-18 14:17:39 +04:00
|
|
|
MacOSXContentGenerator(0),
|
2012-07-10 22:13:01 +04:00
|
|
|
OSXBundleGenerator(0),
|
|
|
|
MacContentFolders(),
|
2011-11-11 09:00:49 +04:00
|
|
|
LocalGenerator(
|
2015-06-06 15:02:24 +03:00
|
|
|
static_cast<cmLocalNinjaGenerator*>(target->GetLocalGenerator())),
|
2011-11-11 09:00:49 +04:00
|
|
|
Objects()
|
|
|
|
{
|
2012-07-18 14:17:39 +04:00
|
|
|
MacOSXContentGenerator = new MacOSXContentGeneratorType(this);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cmNinjaTargetGenerator::~cmNinjaTargetGenerator()
|
|
|
|
{
|
2012-07-21 21:52:17 +04:00
|
|
|
delete this->MacOSXContentGenerator;
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cmGeneratedFileStream& cmNinjaTargetGenerator::GetBuildFileStream() const
|
|
|
|
{
|
|
|
|
return *this->GetGlobalGenerator()->GetBuildFileStream();
|
|
|
|
}
|
|
|
|
|
|
|
|
cmGeneratedFileStream& cmNinjaTargetGenerator::GetRulesFileStream() const
|
|
|
|
{
|
|
|
|
return *this->GetGlobalGenerator()->GetRulesFileStream();
|
|
|
|
}
|
|
|
|
|
|
|
|
cmGlobalNinjaGenerator* cmNinjaTargetGenerator::GetGlobalGenerator() const
|
|
|
|
{
|
|
|
|
return this->LocalGenerator->GetGlobalNinjaGenerator();
|
|
|
|
}
|
|
|
|
|
2015-05-18 20:31:11 +03:00
|
|
|
std::string cmNinjaTargetGenerator::LanguageCompilerRule(
|
|
|
|
const std::string& lang) const
|
|
|
|
{
|
|
|
|
return lang + "_COMPILER__" +
|
|
|
|
cmGlobalNinjaGenerator::EncodeRuleName(this->Target->GetName());
|
|
|
|
}
|
|
|
|
|
2014-03-11 02:48:46 +04:00
|
|
|
std::string
|
|
|
|
cmNinjaTargetGenerator::OrderDependsTargetForTarget()
|
|
|
|
{
|
|
|
|
return "cmake_order_depends_target_" + this->GetTargetName();
|
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// TODO: Most of the code is picked up from
|
|
|
|
// void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink),
|
|
|
|
// void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
|
|
|
|
// Refactor it.
|
|
|
|
std::string
|
2014-03-13 02:50:42 +04:00
|
|
|
cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile const* source,
|
2011-11-11 09:00:49 +04:00
|
|
|
const std::string& language)
|
|
|
|
{
|
2015-07-09 17:05:12 +03:00
|
|
|
std::string flags = this->GetFlags(language);
|
2015-07-09 16:54:56 +03:00
|
|
|
|
2015-07-10 16:04:58 +03:00
|
|
|
// Add Fortran format flags.
|
|
|
|
if(language == "Fortran")
|
|
|
|
{
|
|
|
|
this->AppendFortranFormatFlags(flags, *source);
|
|
|
|
}
|
|
|
|
|
2014-02-12 09:00:29 +04:00
|
|
|
// Add source file specific flags.
|
|
|
|
this->LocalGenerator->AppendFlags(flags,
|
|
|
|
source->GetProperty("COMPILE_FLAGS"));
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2015-07-09 16:58:13 +03:00
|
|
|
void cmNinjaTargetGenerator::AddIncludeFlags(std::string& languageFlags,
|
|
|
|
std::string const& language)
|
|
|
|
{
|
|
|
|
std::vector<std::string> includes;
|
|
|
|
this->LocalGenerator->GetIncludeDirectories(includes,
|
|
|
|
this->GeneratorTarget,
|
|
|
|
language,
|
|
|
|
this->GetConfigName());
|
|
|
|
// Add include directory flags.
|
|
|
|
std::string includeFlags =
|
|
|
|
this->LocalGenerator->GetIncludeFlags(includes, this->GeneratorTarget,
|
|
|
|
language,
|
|
|
|
language == "RC" ? true : false, // full include paths for RC
|
|
|
|
// needed by cmcldeps
|
|
|
|
false,
|
|
|
|
this->GetConfigName());
|
|
|
|
if (this->GetGlobalGenerator()->IsGCCOnWindows())
|
|
|
|
cmSystemTools::ReplaceString(includeFlags, "\\", "/");
|
|
|
|
|
|
|
|
this->LocalGenerator->AppendFlags(languageFlags, includeFlags);
|
|
|
|
}
|
|
|
|
|
2015-01-29 19:02:06 +03:00
|
|
|
bool cmNinjaTargetGenerator::NeedDepTypeMSVC(const std::string& lang) const
|
2013-10-18 14:59:47 +04:00
|
|
|
{
|
2015-01-29 19:02:06 +03:00
|
|
|
if (lang == "C" || lang == "CXX")
|
|
|
|
{
|
|
|
|
cmMakefile* mf = this->GetMakefile();
|
|
|
|
return (
|
|
|
|
strcmp(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID"), "MSVC") == 0 ||
|
|
|
|
strcmp(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"), "MSVC") == 0 ||
|
|
|
|
strcmp(mf->GetSafeDefinition("CMAKE_C_SIMULATE_ID"), "MSVC") == 0 ||
|
|
|
|
strcmp(mf->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID"), "MSVC") == 0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return false;
|
2013-10-18 14:59:47 +04:00
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// TODO: Refactor with
|
|
|
|
// void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
|
|
|
|
std::string
|
|
|
|
cmNinjaTargetGenerator::
|
2014-03-13 02:50:42 +04:00
|
|
|
ComputeDefines(cmSourceFile const* source, const std::string& language)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2012-08-09 11:44:15 +04:00
|
|
|
std::set<std::string> defines;
|
2011-11-11 09:00:49 +04:00
|
|
|
this->LocalGenerator->AppendDefines
|
|
|
|
(defines,
|
2012-08-09 11:44:15 +04:00
|
|
|
source->GetProperty("COMPILE_DEFINITIONS"));
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
std::string defPropName = "COMPILE_DEFINITIONS_";
|
|
|
|
defPropName += cmSystemTools::UpperCase(this->GetConfigName());
|
|
|
|
this->LocalGenerator->AppendDefines
|
|
|
|
(defines,
|
2014-03-11 03:04:11 +04:00
|
|
|
source->GetProperty(defPropName));
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2015-07-09 17:15:08 +03:00
|
|
|
std::string definesString = this->GetDefines(language);
|
2012-08-09 11:44:15 +04:00
|
|
|
this->LocalGenerator->JoinDefines(defines, definesString,
|
2014-03-11 03:04:11 +04:00
|
|
|
language);
|
2012-08-09 11:44:15 +04:00
|
|
|
|
|
|
|
return definesString;
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
|
|
|
|
{
|
|
|
|
// Static libraries never depend on other targets for linking.
|
2012-03-13 18:05:07 +04:00
|
|
|
if (this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
|
|
|
|
this->Target->GetType() == cmTarget::OBJECT_LIBRARY)
|
2011-11-11 09:00:49 +04:00
|
|
|
return cmNinjaDeps();
|
|
|
|
|
|
|
|
cmComputeLinkInformation* cli =
|
2012-11-05 19:14:02 +04:00
|
|
|
this->Target->GetLinkInformation(this->GetConfigName());
|
2011-11-11 09:00:49 +04:00
|
|
|
if(!cli)
|
|
|
|
return cmNinjaDeps();
|
|
|
|
|
|
|
|
const std::vector<std::string> &deps = cli->GetDepends();
|
|
|
|
cmNinjaDeps result(deps.size());
|
|
|
|
std::transform(deps.begin(), deps.end(), result.begin(), MapToNinjaPath());
|
2012-03-07 02:41:40 +04:00
|
|
|
|
|
|
|
// Add a dependency on the link definitions file, if any.
|
2012-04-02 18:55:01 +04:00
|
|
|
if(!this->ModuleDefinitionFile.empty())
|
2012-03-07 02:41:40 +04:00
|
|
|
{
|
2015-07-08 22:24:17 +03:00
|
|
|
result.push_back(this->ConvertToNinjaPath(this->ModuleDefinitionFile));
|
2012-03-07 02:41:40 +04:00
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
cmNinjaTargetGenerator
|
2014-03-13 02:50:42 +04:00
|
|
|
::GetSourceFilePath(cmSourceFile const* source) const
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2014-10-15 16:54:05 +04:00
|
|
|
return ConvertToNinjaPath(source->GetFullPath());
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
cmNinjaTargetGenerator
|
2014-03-13 02:50:42 +04:00
|
|
|
::GetObjectFilePath(cmSourceFile const* source) const
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
|
|
|
|
if(!path.empty())
|
|
|
|
path += "/";
|
2013-11-10 14:22:44 +04:00
|
|
|
std::string const& objectName = this->GeneratorTarget
|
|
|
|
->GetObjectName(source);
|
2012-03-13 17:30:23 +04:00
|
|
|
path += this->LocalGenerator->GetTargetDirectory(*this->Target);
|
|
|
|
path += "/";
|
|
|
|
path += objectName;
|
2011-11-11 09:00:49 +04:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmNinjaTargetGenerator::GetTargetOutputDir() const
|
|
|
|
{
|
|
|
|
std::string dir = this->Target->GetDirectory(this->GetConfigName());
|
2014-10-15 16:54:05 +04:00
|
|
|
return ConvertToNinjaPath(dir);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
cmNinjaTargetGenerator
|
|
|
|
::GetTargetFilePath(const std::string& name) const
|
|
|
|
{
|
|
|
|
std::string path = this->GetTargetOutputDir();
|
|
|
|
if (path.empty() || path == ".")
|
|
|
|
return name;
|
|
|
|
path += "/";
|
|
|
|
path += name;
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmNinjaTargetGenerator::GetTargetName() const
|
|
|
|
{
|
|
|
|
return this->Target->GetName();
|
|
|
|
}
|
|
|
|
|
2012-02-22 00:18:05 +04:00
|
|
|
|
2012-08-22 14:37:55 +04:00
|
|
|
bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(cmNinjaVars& vars) const
|
2012-02-22 00:18:05 +04:00
|
|
|
{
|
2012-08-22 14:37:55 +04:00
|
|
|
cmMakefile* mf = this->GetMakefile();
|
|
|
|
if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") ||
|
|
|
|
mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID"))
|
2012-02-22 00:18:05 +04:00
|
|
|
{
|
2012-08-22 14:42:16 +04:00
|
|
|
std::string pdbPath;
|
2014-02-24 23:15:21 +04:00
|
|
|
std::string compilePdbPath;
|
2012-08-22 14:42:16 +04:00
|
|
|
if(this->Target->GetType() == cmTarget::EXECUTABLE ||
|
|
|
|
this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
|
|
|
|
this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
|
|
|
|
this->Target->GetType() == cmTarget::MODULE_LIBRARY)
|
|
|
|
{
|
2012-09-25 05:30:42 +04:00
|
|
|
pdbPath = this->Target->GetPDBDirectory(this->GetConfigName());
|
2012-08-22 14:42:16 +04:00
|
|
|
pdbPath += "/";
|
|
|
|
pdbPath += this->Target->GetPDBName(this->GetConfigName());
|
2012-09-25 05:30:42 +04:00
|
|
|
}
|
2014-02-24 23:15:21 +04:00
|
|
|
if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY)
|
|
|
|
{
|
|
|
|
compilePdbPath = this->Target->GetCompilePDBPath(this->GetConfigName());
|
|
|
|
if(compilePdbPath.empty())
|
|
|
|
{
|
|
|
|
compilePdbPath = this->Target->GetSupportDirectory() + "/";
|
|
|
|
}
|
|
|
|
}
|
2012-02-22 00:18:05 +04:00
|
|
|
|
2012-08-22 14:37:55 +04:00
|
|
|
vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
|
2014-10-15 16:54:05 +04:00
|
|
|
ConvertToNinjaPath(pdbPath),
|
2012-08-22 14:37:55 +04:00
|
|
|
cmLocalGenerator::SHELL);
|
2014-02-24 23:15:21 +04:00
|
|
|
vars["TARGET_COMPILE_PDB"] =
|
|
|
|
this->GetLocalGenerator()->ConvertToOutputFormat(
|
2014-10-15 16:54:05 +04:00
|
|
|
ConvertToNinjaPath(compilePdbPath),
|
2014-02-24 23:15:21 +04:00
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
|
2012-08-22 14:37:55 +04:00
|
|
|
EnsureParentDirectoryExists(pdbPath);
|
2014-02-24 23:15:21 +04:00
|
|
|
EnsureParentDirectoryExists(compilePdbPath);
|
2012-08-22 14:37:55 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-02-22 00:18:05 +04:00
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
void
|
|
|
|
cmNinjaTargetGenerator
|
|
|
|
::WriteLanguageRules(const std::string& language)
|
|
|
|
{
|
2012-06-10 22:20:29 +04:00
|
|
|
#ifdef NINJA_GEN_VERBOSE_FILES
|
2011-11-11 09:00:49 +04:00
|
|
|
this->GetRulesFileStream()
|
|
|
|
<< "# Rules for language " << language << "\n\n";
|
2012-06-10 22:20:29 +04:00
|
|
|
#endif
|
2011-11-11 09:00:49 +04:00
|
|
|
this->WriteCompileRule(language);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmNinjaTargetGenerator
|
2013-10-18 14:59:47 +04:00
|
|
|
::WriteCompileRule(const std::string& lang)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
|
|
|
cmLocalGenerator::RuleVariables vars;
|
|
|
|
vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
|
|
|
|
vars.CMTarget = this->GetTarget();
|
|
|
|
vars.Language = lang.c_str();
|
|
|
|
vars.Source = "$in";
|
|
|
|
vars.Object = "$out";
|
|
|
|
vars.Defines = "$DEFINES";
|
2015-07-13 17:35:04 +03:00
|
|
|
vars.Includes = "$INCLUDES";
|
2012-02-22 00:18:05 +04:00
|
|
|
vars.TargetPDB = "$TARGET_PDB";
|
2014-02-24 23:15:21 +04:00
|
|
|
vars.TargetCompilePDB = "$TARGET_COMPILE_PDB";
|
2012-10-03 19:19:47 +04:00
|
|
|
vars.ObjectDir = "$OBJECT_DIR";
|
2014-06-05 16:57:17 +04:00
|
|
|
vars.ObjectFileDir = "$OBJECT_FILE_DIR";
|
2012-06-13 02:52:46 +04:00
|
|
|
|
2012-06-09 00:01:57 +04:00
|
|
|
cmMakefile* mf = this->GetMakefile();
|
2012-06-13 02:52:46 +04:00
|
|
|
|
2013-10-18 14:59:47 +04:00
|
|
|
// Tell ninja dependency format so all deps can be loaded into a database
|
|
|
|
std::string deptype;
|
|
|
|
std::string depfile;
|
|
|
|
std::string cldeps;
|
|
|
|
std::string flags = "$FLAGS";
|
2015-01-29 19:02:06 +03:00
|
|
|
if (this->NeedDepTypeMSVC(lang))
|
2012-06-09 15:52:20 +04:00
|
|
|
{
|
2015-01-29 19:02:06 +03:00
|
|
|
deptype = "msvc";
|
|
|
|
depfile = "";
|
|
|
|
flags += " /showIncludes";
|
|
|
|
}
|
|
|
|
else if (lang == "RC" && this->NeedDepTypeMSVC("C"))
|
|
|
|
{
|
|
|
|
// For the MS resource compiler we need cmcldeps, but skip dependencies
|
|
|
|
// for source-file try_compile cases because they are always fresh.
|
|
|
|
if (!mf->GetIsSourceFileTryCompile())
|
2012-06-09 15:52:20 +04:00
|
|
|
{
|
2013-10-18 14:59:47 +04:00
|
|
|
deptype = "gcc";
|
|
|
|
depfile = "$DEP_FILE";
|
|
|
|
const std::string cl = mf->GetDefinition("CMAKE_C_COMPILER") ?
|
|
|
|
mf->GetSafeDefinition("CMAKE_C_COMPILER") :
|
|
|
|
mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
|
|
|
|
cldeps = "\"";
|
|
|
|
cldeps += mf->GetSafeDefinition("CMAKE_CMCLDEPS_EXECUTABLE");
|
|
|
|
cldeps += "\" " + lang + " $in \"$DEP_FILE\" $out \"";
|
|
|
|
cldeps += mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX");
|
|
|
|
cldeps += "\" \"" + cl + "\" ";
|
|
|
|
}
|
2012-06-09 15:52:20 +04:00
|
|
|
}
|
2013-10-18 14:59:47 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
deptype = "gcc";
|
2014-03-24 07:47:56 +04:00
|
|
|
const char* langdeptype = mf->GetDefinition("CMAKE_NINJA_DEPTYPE_" + lang);
|
|
|
|
if (langdeptype)
|
|
|
|
{
|
|
|
|
deptype = langdeptype;
|
|
|
|
}
|
2012-06-13 02:52:46 +04:00
|
|
|
depfile = "$DEP_FILE";
|
2013-10-18 14:59:47 +04:00
|
|
|
const std::string flagsName = "CMAKE_DEPFILE_FLAGS_" + lang;
|
2014-03-11 03:04:11 +04:00
|
|
|
std::string depfileFlags = mf->GetSafeDefinition(flagsName);
|
2013-11-04 16:18:47 +04:00
|
|
|
if (!depfileFlags.empty())
|
|
|
|
{
|
|
|
|
cmSystemTools::ReplaceString(depfileFlags, "<DEPFILE>", "$DEP_FILE");
|
|
|
|
cmSystemTools::ReplaceString(depfileFlags, "<OBJECT>", "$out");
|
|
|
|
cmSystemTools::ReplaceString(depfileFlags, "<CMAKE_C_COMPILER>",
|
|
|
|
mf->GetDefinition("CMAKE_C_COMPILER"));
|
|
|
|
flags += " " + depfileFlags;
|
|
|
|
}
|
2013-10-18 14:59:47 +04:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2013-10-18 14:59:47 +04:00
|
|
|
vars.Flags = flags.c_str();
|
|
|
|
vars.DependencyFile = depfile.c_str();
|
2012-03-07 02:41:40 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// Rule for compiling object file.
|
2013-10-18 14:59:47 +04:00
|
|
|
const std::string cmdVar = std::string("CMAKE_") + lang + "_COMPILE_OBJECT";
|
2014-03-11 03:04:11 +04:00
|
|
|
std::string compileCmd = mf->GetRequiredDefinition(cmdVar);
|
2012-02-27 08:05:31 +04:00
|
|
|
std::vector<std::string> compileCmds;
|
|
|
|
cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2015-05-18 21:39:25 +03:00
|
|
|
// Maybe insert an include-what-you-use runner.
|
|
|
|
if (!compileCmds.empty() && (lang == "C" || lang == "CXX"))
|
|
|
|
{
|
|
|
|
std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
|
|
|
|
const char *iwyu = this->Target->GetProperty(iwyu_prop);
|
|
|
|
if (iwyu && *iwyu)
|
|
|
|
{
|
|
|
|
std::string run_iwyu =
|
|
|
|
this->GetLocalGenerator()->ConvertToOutputFormat(
|
|
|
|
cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
|
|
|
|
run_iwyu += " -E __run_iwyu --iwyu=";
|
|
|
|
run_iwyu += this->GetLocalGenerator()->EscapeForShell(iwyu);
|
|
|
|
run_iwyu += " -- ";
|
|
|
|
compileCmds.front().insert(0, run_iwyu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 22:56:56 +03:00
|
|
|
// Maybe insert a compiler launcher like ccache or distcc
|
|
|
|
if (!compileCmds.empty() && (lang == "C" || lang == "CXX"))
|
|
|
|
{
|
|
|
|
std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
|
|
|
|
const char *clauncher = this->Target->GetProperty(clauncher_prop);
|
|
|
|
if (clauncher && *clauncher)
|
|
|
|
{
|
|
|
|
std::vector<std::string> launcher_cmd;
|
|
|
|
cmSystemTools::ExpandListArgument(clauncher, launcher_cmd, true);
|
|
|
|
for (std::vector<std::string>::iterator i = launcher_cmd.begin(),
|
|
|
|
e = launcher_cmd.end(); i != e; ++i)
|
|
|
|
{
|
|
|
|
*i = this->LocalGenerator->EscapeForShell(*i);
|
|
|
|
}
|
|
|
|
std::string const& run_launcher = cmJoin(launcher_cmd, " ") + " ";
|
|
|
|
compileCmds.front().insert(0, run_launcher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-23 02:34:28 +03:00
|
|
|
if (!compileCmds.empty())
|
|
|
|
{
|
|
|
|
compileCmds.front().insert(0, cldeps);
|
|
|
|
}
|
2012-11-30 06:38:25 +04:00
|
|
|
|
2012-02-27 08:05:31 +04:00
|
|
|
for (std::vector<std::string>::iterator i = compileCmds.begin();
|
|
|
|
i != compileCmds.end(); ++i)
|
|
|
|
this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
|
|
|
|
|
2012-11-30 06:38:25 +04:00
|
|
|
std::string cmdLine =
|
|
|
|
this->GetLocalGenerator()->BuildCommandLine(compileCmds);
|
2012-08-17 18:01:53 +04:00
|
|
|
|
2012-06-08 01:34:48 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// Write the rule for compiling file of the given language.
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream comment;
|
2013-10-18 14:59:47 +04:00
|
|
|
comment << "Rule for compiling " << lang << " files.";
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream description;
|
2013-10-18 14:59:47 +04:00
|
|
|
description << "Building " << lang << " object $out";
|
|
|
|
this->GetGlobalGenerator()->AddRule(this->LanguageCompilerRule(lang),
|
2012-02-27 08:05:31 +04:00
|
|
|
cmdLine,
|
2011-11-11 09:00:49 +04:00
|
|
|
description.str(),
|
|
|
|
comment.str(),
|
2013-10-18 14:59:47 +04:00
|
|
|
depfile,
|
|
|
|
deptype,
|
|
|
|
/*rspfile*/ "",
|
|
|
|
/*rspcontent*/ "",
|
2014-11-14 02:32:44 +03:00
|
|
|
/*restat*/ "",
|
2013-10-18 14:59:47 +04:00
|
|
|
/*generator*/ false);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmNinjaTargetGenerator
|
|
|
|
::WriteObjectBuildStatements()
|
|
|
|
{
|
|
|
|
// Write comments.
|
|
|
|
cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
|
|
|
|
this->GetBuildFileStream()
|
|
|
|
<< "# Object build statements for "
|
|
|
|
<< cmTarget::GetTargetTypeName(this->GetTarget()->GetType())
|
|
|
|
<< " target "
|
|
|
|
<< this->GetTargetName()
|
|
|
|
<< "\n\n";
|
|
|
|
|
2014-02-13 20:25:00 +04:00
|
|
|
std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
|
2014-03-13 02:06:05 +04:00
|
|
|
std::vector<cmSourceFile const*> customCommands;
|
2014-02-13 20:25:00 +04:00
|
|
|
this->GeneratorTarget->GetCustomCommands(customCommands, config);
|
2014-03-13 02:06:05 +04:00
|
|
|
for(std::vector<cmSourceFile const*>::const_iterator
|
2013-11-10 14:22:44 +04:00
|
|
|
si = customCommands.begin();
|
|
|
|
si != customCommands.end(); ++si)
|
2012-03-13 17:24:54 +04:00
|
|
|
{
|
|
|
|
cmCustomCommand const* cc = (*si)->GetCustomCommand();
|
|
|
|
this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget());
|
2014-04-04 19:09:56 +04:00
|
|
|
// Record the custom commands for this target. The container is used
|
|
|
|
// in WriteObjectBuildStatement when called in a loop below.
|
2014-03-11 05:07:31 +04:00
|
|
|
this->CustomCommands.push_back(cc);
|
2012-03-13 17:24:54 +04:00
|
|
|
}
|
2014-03-13 02:06:05 +04:00
|
|
|
std::vector<cmSourceFile const*> headerSources;
|
2014-02-13 20:25:00 +04:00
|
|
|
this->GeneratorTarget->GetHeaderSources(headerSources, config);
|
2012-07-16 19:34:22 +04:00
|
|
|
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
|
2013-11-10 14:22:44 +04:00
|
|
|
headerSources,
|
2012-07-18 14:17:39 +04:00
|
|
|
this->MacOSXContentGenerator);
|
2014-03-13 02:06:05 +04:00
|
|
|
std::vector<cmSourceFile const*> extraSources;
|
2014-02-13 20:25:00 +04:00
|
|
|
this->GeneratorTarget->GetExtraSources(extraSources, config);
|
2012-07-16 19:34:22 +04:00
|
|
|
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
|
2013-11-10 14:22:44 +04:00
|
|
|
extraSources,
|
2012-07-18 14:17:39 +04:00
|
|
|
this->MacOSXContentGenerator);
|
2014-03-13 02:06:05 +04:00
|
|
|
std::vector<cmSourceFile const*> externalObjects;
|
2014-02-13 20:25:00 +04:00
|
|
|
this->GeneratorTarget->GetExternalObjects(externalObjects, config);
|
2014-03-13 02:06:05 +04:00
|
|
|
for(std::vector<cmSourceFile const*>::const_iterator
|
2013-11-10 14:22:44 +04:00
|
|
|
si = externalObjects.begin();
|
|
|
|
si != externalObjects.end(); ++si)
|
2012-03-13 17:24:54 +04:00
|
|
|
{
|
|
|
|
this->Objects.push_back(this->GetSourceFilePath(*si));
|
|
|
|
}
|
2014-03-11 02:48:46 +04:00
|
|
|
|
|
|
|
cmNinjaDeps orderOnlyDeps;
|
|
|
|
this->GetLocalGenerator()->AppendTargetDepends(this->Target, orderOnlyDeps);
|
2014-03-11 05:07:31 +04:00
|
|
|
|
|
|
|
// Add order-only dependencies on custom command outputs.
|
|
|
|
for(std::vector<cmCustomCommand const*>::const_iterator
|
|
|
|
cci = this->CustomCommands.begin();
|
|
|
|
cci != this->CustomCommands.end(); ++cci)
|
|
|
|
{
|
|
|
|
cmCustomCommand const* cc = *cci;
|
|
|
|
cmCustomCommandGenerator ccg(*cc, this->GetConfigName(),
|
|
|
|
this->GetMakefile());
|
|
|
|
const std::vector<std::string>& ccoutputs = ccg.GetOutputs();
|
2014-11-14 02:54:52 +03:00
|
|
|
const std::vector<std::string>& ccbyproducts= ccg.GetByproducts();
|
2014-03-11 05:07:31 +04:00
|
|
|
std::transform(ccoutputs.begin(), ccoutputs.end(),
|
|
|
|
std::back_inserter(orderOnlyDeps), MapToNinjaPath());
|
2014-11-14 02:54:52 +03:00
|
|
|
std::transform(ccbyproducts.begin(), ccbyproducts.end(),
|
|
|
|
std::back_inserter(orderOnlyDeps), MapToNinjaPath());
|
2014-03-11 05:07:31 +04:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:13:52 +04:00
|
|
|
if (!orderOnlyDeps.empty())
|
|
|
|
{
|
|
|
|
cmNinjaDeps orderOnlyTarget;
|
|
|
|
orderOnlyTarget.push_back(this->OrderDependsTargetForTarget());
|
|
|
|
this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
|
|
|
|
"Order-only phony target for "
|
|
|
|
+ this->GetTargetName(),
|
|
|
|
orderOnlyTarget,
|
|
|
|
cmNinjaDeps(),
|
|
|
|
cmNinjaDeps(),
|
|
|
|
orderOnlyDeps);
|
|
|
|
}
|
2014-03-13 02:06:05 +04:00
|
|
|
std::vector<cmSourceFile const*> objectSources;
|
2014-02-13 20:25:00 +04:00
|
|
|
this->GeneratorTarget->GetObjectSources(objectSources, config);
|
2014-03-13 02:06:05 +04:00
|
|
|
for(std::vector<cmSourceFile const*>::const_iterator
|
2013-11-10 14:22:44 +04:00
|
|
|
si = objectSources.begin(); si != objectSources.end(); ++si)
|
2012-03-13 17:24:54 +04:00
|
|
|
{
|
2014-06-28 00:13:52 +04:00
|
|
|
this->WriteObjectBuildStatement(*si, !orderOnlyDeps.empty());
|
2012-03-13 17:24:54 +04:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
this->GetBuildFileStream() << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmNinjaTargetGenerator
|
2014-06-28 00:13:52 +04:00
|
|
|
::WriteObjectBuildStatement(
|
|
|
|
cmSourceFile const* source, bool writeOrderDependsTargetForTarget)
|
2011-11-11 09:00:49 +04:00
|
|
|
{
|
2015-07-15 21:16:11 +03:00
|
|
|
std::string const language = source->GetLanguage();
|
|
|
|
std::string const sourceFileName =
|
|
|
|
language=="RC" ? source->GetFullPath() : this->GetSourceFilePath(source);
|
|
|
|
std::string const objectDir = this->Target->GetSupportDirectory();
|
|
|
|
std::string const objectFileName = this->GetObjectFilePath(source);
|
|
|
|
std::string const objectFileDir =
|
|
|
|
cmSystemTools::GetFilenamePath(objectFileName);
|
|
|
|
|
|
|
|
cmNinjaVars vars;
|
|
|
|
vars["FLAGS"] = this->ComputeFlagsForObject(source, language);
|
|
|
|
vars["DEFINES"] = this->ComputeDefines(source, language);
|
|
|
|
vars["INCLUDES"] = this->GetIncludes(language);
|
|
|
|
if (!this->NeedDepTypeMSVC(language))
|
|
|
|
{
|
|
|
|
vars["DEP_FILE"] =
|
|
|
|
cmGlobalNinjaGenerator::EncodeDepfileSpace(objectFileName + ".d");
|
|
|
|
}
|
|
|
|
|
|
|
|
this->ExportObjectCompileCommand(
|
|
|
|
language, sourceFileName,
|
|
|
|
objectDir, objectFileName, objectFileDir,
|
|
|
|
vars["FLAGS"], vars["DEFINES"], vars["INCLUDES"]
|
|
|
|
);
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
std::string comment;
|
|
|
|
std::string rule = this->LanguageCompilerRule(language);
|
|
|
|
|
|
|
|
cmNinjaDeps outputs;
|
|
|
|
outputs.push_back(objectFileName);
|
|
|
|
// Add this object to the list of object files.
|
|
|
|
this->Objects.push_back(objectFileName);
|
|
|
|
|
|
|
|
cmNinjaDeps explicitDeps;
|
|
|
|
explicitDeps.push_back(sourceFileName);
|
|
|
|
|
2012-09-26 00:21:54 +04:00
|
|
|
cmNinjaDeps implicitDeps;
|
2011-11-11 09:00:49 +04:00
|
|
|
if(const char* objectDeps = source->GetProperty("OBJECT_DEPENDS")) {
|
|
|
|
std::vector<std::string> depList;
|
|
|
|
cmSystemTools::ExpandListArgument(objectDeps, depList);
|
2015-01-27 18:57:17 +03:00
|
|
|
for(std::vector<std::string>::iterator odi = depList.begin();
|
|
|
|
odi != depList.end(); ++odi)
|
|
|
|
{
|
|
|
|
if (cmSystemTools::FileIsFullPath(*odi))
|
|
|
|
{
|
|
|
|
*odi = cmSystemTools::CollapseFullPath(*odi);
|
|
|
|
}
|
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
std::transform(depList.begin(), depList.end(),
|
2012-09-26 00:21:54 +04:00
|
|
|
std::back_inserter(implicitDeps), MapToNinjaPath());
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2014-03-11 02:48:46 +04:00
|
|
|
cmNinjaDeps orderOnlyDeps;
|
2014-06-28 00:13:52 +04:00
|
|
|
if (writeOrderDependsTargetForTarget)
|
|
|
|
{
|
|
|
|
orderOnlyDeps.push_back(this->OrderDependsTargetForTarget());
|
|
|
|
}
|
2014-03-11 02:48:46 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// If the source file is GENERATED and does not have a custom command
|
|
|
|
// (either attached to this source file or another one), assume that one of
|
|
|
|
// the target dependencies, OBJECT_DEPENDS or header file custom commands
|
|
|
|
// will rebuild the file.
|
|
|
|
if (source->GetPropertyAsBool("GENERATED") && !source->GetCustomCommand() &&
|
|
|
|
!this->GetGlobalGenerator()->HasCustomCommandOutput(sourceFileName)) {
|
|
|
|
this->GetGlobalGenerator()->AddAssumedSourceDependencies(sourceFileName,
|
|
|
|
orderOnlyDeps);
|
|
|
|
}
|
|
|
|
|
2012-06-13 02:52:46 +04:00
|
|
|
EnsureParentDirectoryExists(objectFileName);
|
2012-06-12 06:17:55 +04:00
|
|
|
|
2013-04-11 18:22:44 +04:00
|
|
|
vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
|
2014-10-15 16:54:05 +04:00
|
|
|
ConvertToNinjaPath(objectDir),
|
2013-04-11 18:22:44 +04:00
|
|
|
cmLocalGenerator::SHELL);
|
2014-06-05 16:57:17 +04:00
|
|
|
vars["OBJECT_FILE_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
|
2014-10-15 16:54:05 +04:00
|
|
|
ConvertToNinjaPath(objectFileDir),
|
2014-06-05 16:57:17 +04:00
|
|
|
cmLocalGenerator::SHELL);
|
2012-10-03 19:19:47 +04:00
|
|
|
|
2013-11-23 13:49:36 +04:00
|
|
|
this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetTarget(), vars);
|
|
|
|
|
2012-08-22 14:37:55 +04:00
|
|
|
this->SetMsvcTargetPdbVariable(vars);
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2013-06-07 22:25:33 +04:00
|
|
|
this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(),
|
|
|
|
comment,
|
|
|
|
rule,
|
|
|
|
outputs,
|
|
|
|
explicitDeps,
|
|
|
|
implicitDeps,
|
|
|
|
orderOnlyDeps,
|
|
|
|
vars);
|
2012-03-18 00:49:36 +04:00
|
|
|
|
|
|
|
if(const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) {
|
|
|
|
std::vector<std::string> outputList;
|
|
|
|
cmSystemTools::ExpandListArgument(objectOutputs, outputList);
|
|
|
|
std::transform(outputList.begin(), outputList.end(), outputList.begin(),
|
|
|
|
MapToNinjaPath());
|
2013-06-07 22:25:33 +04:00
|
|
|
this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
|
|
|
|
"Additional output files.",
|
|
|
|
outputList,
|
|
|
|
outputs);
|
2012-03-18 00:49:36 +04:00
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
2012-03-07 02:41:40 +04:00
|
|
|
|
2015-07-15 21:16:11 +03:00
|
|
|
void
|
|
|
|
cmNinjaTargetGenerator
|
|
|
|
::ExportObjectCompileCommand(
|
|
|
|
std::string const& language,
|
|
|
|
std::string const& sourceFileName,
|
|
|
|
std::string const& objectDir,
|
|
|
|
std::string const& objectFileName,
|
|
|
|
std::string const& objectFileDir,
|
|
|
|
std::string const& flags,
|
|
|
|
std::string const& defines,
|
|
|
|
std::string const& includes
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if(!this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS"))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmLocalGenerator::RuleVariables compileObjectVars;
|
|
|
|
compileObjectVars.Language = language.c_str();
|
|
|
|
|
|
|
|
std::string escapedSourceFileName = sourceFileName;
|
|
|
|
|
|
|
|
if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str()))
|
|
|
|
{
|
|
|
|
escapedSourceFileName = cmSystemTools::CollapseFullPath(
|
|
|
|
escapedSourceFileName,
|
|
|
|
this->GetGlobalGenerator()->GetCMakeInstance()->
|
|
|
|
GetHomeOutputDirectory());
|
|
|
|
}
|
|
|
|
|
|
|
|
escapedSourceFileName =
|
|
|
|
this->LocalGenerator->ConvertToOutputFormat(
|
|
|
|
escapedSourceFileName, cmLocalGenerator::SHELL);
|
|
|
|
|
|
|
|
compileObjectVars.Source = escapedSourceFileName.c_str();
|
|
|
|
compileObjectVars.Object = objectFileName.c_str();
|
|
|
|
compileObjectVars.ObjectDir = objectDir.c_str();
|
|
|
|
compileObjectVars.ObjectFileDir = objectFileDir.c_str();
|
|
|
|
compileObjectVars.Flags = flags.c_str();
|
|
|
|
compileObjectVars.Defines = defines.c_str();
|
|
|
|
compileObjectVars.Includes = includes.c_str();
|
|
|
|
|
|
|
|
// Rule for compiling object file.
|
|
|
|
std::string compileCmdVar = "CMAKE_";
|
|
|
|
compileCmdVar += language;
|
|
|
|
compileCmdVar += "_COMPILE_OBJECT";
|
|
|
|
std::string compileCmd =
|
|
|
|
this->GetMakefile()->GetRequiredDefinition(compileCmdVar);
|
|
|
|
std::vector<std::string> compileCmds;
|
|
|
|
cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
|
|
|
|
|
|
|
|
for (std::vector<std::string>::iterator i = compileCmds.begin();
|
|
|
|
i != compileCmds.end(); ++i)
|
|
|
|
this->GetLocalGenerator()->ExpandRuleVariables(*i, compileObjectVars);
|
|
|
|
|
|
|
|
std::string cmdLine =
|
|
|
|
this->GetLocalGenerator()->BuildCommandLine(compileCmds);
|
|
|
|
|
|
|
|
this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine,
|
|
|
|
sourceFileName);
|
|
|
|
}
|
|
|
|
|
2012-06-13 02:52:46 +04:00
|
|
|
void
|
|
|
|
cmNinjaTargetGenerator
|
2012-10-03 18:14:45 +04:00
|
|
|
::EnsureDirectoryExists(const std::string& path) const
|
2012-06-13 02:52:46 +04:00
|
|
|
{
|
2012-10-03 18:14:45 +04:00
|
|
|
if (cmSystemTools::FileIsFullPath(path.c_str()))
|
|
|
|
{
|
|
|
|
cmSystemTools::MakeDirectory(path.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const std::string fullPath = std::string(this->GetGlobalGenerator()->
|
|
|
|
GetCMakeInstance()->GetHomeOutputDirectory())
|
|
|
|
+ "/" + path;
|
|
|
|
cmSystemTools::MakeDirectory(fullPath.c_str());
|
|
|
|
}
|
2012-06-13 02:52:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmNinjaTargetGenerator
|
2012-08-22 14:37:55 +04:00
|
|
|
::EnsureParentDirectoryExists(const std::string& path) const
|
2012-06-13 02:52:46 +04:00
|
|
|
{
|
2014-10-15 16:54:05 +04:00
|
|
|
EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path));
|
2012-06-13 02:52:46 +04:00
|
|
|
}
|
2012-07-10 22:13:01 +04:00
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-07-16 19:34:22 +04:00
|
|
|
void
|
|
|
|
cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
|
2014-03-13 02:45:43 +04:00
|
|
|
cmSourceFile const& source, const char* pkgloc)
|
2012-07-10 22:13:01 +04:00
|
|
|
{
|
|
|
|
// Skip OS X content when not building a Framework or Bundle.
|
2013-05-06 06:19:05 +04:00
|
|
|
if(!this->Generator->GetTarget()->IsBundleOnApple())
|
2012-07-10 22:13:01 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-16 19:34:22 +04:00
|
|
|
std::string macdir =
|
2012-07-17 01:03:40 +04:00
|
|
|
this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc);
|
2012-07-10 22:13:01 +04:00
|
|
|
|
|
|
|
// Get the input file location.
|
|
|
|
std::string input = source.GetFullPath();
|
2012-07-16 19:34:22 +04:00
|
|
|
input =
|
2014-10-15 16:54:05 +04:00
|
|
|
this->Generator->GetLocalGenerator()->ConvertToNinjaPath(input);
|
2012-07-10 22:13:01 +04:00
|
|
|
|
|
|
|
// Get the output file location.
|
|
|
|
std::string output = macdir;
|
|
|
|
output += "/";
|
|
|
|
output += cmSystemTools::GetFilenameName(input);
|
2012-07-16 19:34:22 +04:00
|
|
|
output =
|
2014-10-15 16:54:05 +04:00
|
|
|
this->Generator->GetLocalGenerator()->ConvertToNinjaPath(output);
|
2012-07-10 22:13:01 +04:00
|
|
|
|
|
|
|
// Write a build statement to copy the content into the bundle.
|
2012-07-16 19:34:22 +04:00
|
|
|
this->Generator->GetGlobalGenerator()->WriteMacOSXContentBuild(input,
|
|
|
|
output);
|
2012-07-10 22:13:01 +04:00
|
|
|
|
|
|
|
// Add as a dependency of all target so that it gets called.
|
2012-07-16 19:34:22 +04:00
|
|
|
this->Generator->GetGlobalGenerator()->AddDependencyToAll(output);
|
2012-07-10 22:13:01 +04:00
|
|
|
}
|
2013-11-23 13:49:36 +04:00
|
|
|
|
2014-03-11 02:32:00 +04:00
|
|
|
void cmNinjaTargetGenerator::addPoolNinjaVariable(
|
|
|
|
const std::string& pool_property,
|
|
|
|
cmTarget* target,
|
|
|
|
cmNinjaVars& vars)
|
2013-11-23 13:49:36 +04:00
|
|
|
{
|
|
|
|
const char* pool = target->GetProperty(pool_property);
|
|
|
|
if (pool)
|
|
|
|
{
|
|
|
|
vars["pool"] = pool;
|
|
|
|
}
|
|
|
|
}
|