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"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
cmNinjaTargetGenerator *
|
|
|
|
cmNinjaTargetGenerator::New(cmTarget* target)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
cmMakefile *mf = target->GetMakefile();
|
|
|
|
if (strcmp(mf->GetStartDirectory(), mf->GetHomeDirectory()) == 0)
|
|
|
|
return new cmNinjaUtilityTargetGenerator(target);
|
|
|
|
// else fallthrough
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmTarget* target)
|
2012-07-10 22:13:01 +04:00
|
|
|
:
|
2012-07-18 14:17:39 +04:00
|
|
|
MacOSXContentGenerator(0),
|
2012-07-10 22:13:01 +04:00
|
|
|
OSXBundleGenerator(0),
|
|
|
|
MacContentFolders(),
|
|
|
|
Target(target),
|
2011-11-11 09:00:49 +04:00
|
|
|
Makefile(target->GetMakefile()),
|
|
|
|
LocalGenerator(
|
|
|
|
static_cast<cmLocalNinjaGenerator*>(Makefile->GetLocalGenerator())),
|
|
|
|
Objects()
|
|
|
|
{
|
2012-03-13 17:24:54 +04:00
|
|
|
this->GeneratorTarget =
|
|
|
|
this->GetGlobalGenerator()->GetGeneratorTarget(target);
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* cmNinjaTargetGenerator::GetConfigName() const
|
|
|
|
{
|
2012-07-18 13:27:49 +04:00
|
|
|
return this->LocalGenerator->GetConfigName();
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Picked up from cmMakefileTargetGenerator. Refactor it.
|
|
|
|
const char* cmNinjaTargetGenerator::GetFeature(const char* feature)
|
|
|
|
{
|
|
|
|
return this->Target->GetFeature(feature, this->GetConfigName());
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Picked up from cmMakefileTargetGenerator. Refactor it.
|
|
|
|
bool cmNinjaTargetGenerator::GetFeatureAsBool(const char* feature)
|
|
|
|
{
|
|
|
|
return cmSystemTools::IsOn(this->GetFeature(feature));
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Picked up from cmMakefileTargetGenerator. Refactor it.
|
|
|
|
void cmNinjaTargetGenerator::AddFeatureFlags(std::string& flags,
|
|
|
|
const char* lang)
|
|
|
|
{
|
|
|
|
// Add language-specific flags.
|
|
|
|
this->LocalGenerator->AddLanguageFlags(flags, lang, this->GetConfigName());
|
|
|
|
|
|
|
|
if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION"))
|
|
|
|
{
|
|
|
|
this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Most of the code is picked up from
|
|
|
|
// void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink),
|
|
|
|
// void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
|
|
|
|
// Refactor it.
|
|
|
|
std::string
|
|
|
|
cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile *source,
|
|
|
|
const std::string& language)
|
|
|
|
{
|
|
|
|
std::string flags;
|
|
|
|
|
|
|
|
this->AddFeatureFlags(flags, language.c_str());
|
|
|
|
|
|
|
|
this->GetLocalGenerator()->AddArchitectureFlags(flags,
|
2012-09-16 03:16:43 +04:00
|
|
|
this->GeneratorTarget,
|
2011-11-11 09:00:49 +04:00
|
|
|
language.c_str(),
|
|
|
|
this->GetConfigName());
|
|
|
|
|
|
|
|
// TODO: Fortran support.
|
|
|
|
// // Fortran-specific flags computed for this target.
|
|
|
|
// if(*l == "Fortran")
|
|
|
|
// {
|
|
|
|
// this->AddFortranFlags(flags);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Add shared-library flags if needed.
|
2012-05-30 22:13:09 +04:00
|
|
|
this->LocalGenerator->AddCMP0018Flags(flags, this->Target,
|
|
|
|
language.c_str());
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
// Add include directory flags.
|
|
|
|
{
|
2012-02-23 01:31:00 +04:00
|
|
|
std::vector<std::string> includes;
|
2012-10-15 12:42:42 +04:00
|
|
|
const char *config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE");
|
|
|
|
this->LocalGenerator->GetIncludeDirectories(includes,
|
|
|
|
this->GeneratorTarget,
|
|
|
|
language.c_str(), config);
|
2011-11-11 09:00:49 +04:00
|
|
|
std::string includeFlags =
|
2012-07-15 16:47:02 +04:00
|
|
|
this->LocalGenerator->GetIncludeFlags(includes, language.c_str(),
|
|
|
|
language == "RC" ? true : false); // full include paths for RC
|
|
|
|
// needed by cmcldeps
|
2012-06-12 15:52:32 +04:00
|
|
|
if(cmGlobalNinjaGenerator::IsMinGW())
|
|
|
|
cmSystemTools::ReplaceString(includeFlags, "\\", "/");
|
2012-07-15 16:47:02 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
this->LocalGenerator->AppendFlags(flags, includeFlags.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append old-style preprocessor definition flags.
|
|
|
|
this->LocalGenerator->AppendFlags(flags, this->Makefile->GetDefineFlags());
|
|
|
|
|
2012-08-22 02:11:17 +04:00
|
|
|
// Add target-specific flags.
|
|
|
|
if(this->Target->GetProperty("COMPILE_FLAGS"))
|
|
|
|
{
|
|
|
|
std::string langIncludeExpr = "CMAKE_";
|
|
|
|
langIncludeExpr += language;
|
|
|
|
langIncludeExpr += "_FLAG_REGEX";
|
|
|
|
const char* regex = this->Makefile->
|
|
|
|
GetDefinition(langIncludeExpr.c_str());
|
|
|
|
if(regex)
|
|
|
|
{
|
|
|
|
cmsys::RegularExpression r(regex);
|
|
|
|
std::vector<std::string> args;
|
|
|
|
cmSystemTools::ParseWindowsCommandLine(
|
|
|
|
this->Target->GetProperty("COMPILE_FLAGS"),
|
|
|
|
args);
|
|
|
|
for(std::vector<std::string>::iterator i = args.begin();
|
|
|
|
i != args.end(); ++i)
|
|
|
|
{
|
|
|
|
if(r.find(i->c_str()))
|
|
|
|
{
|
|
|
|
this->LocalGenerator->AppendFlags
|
|
|
|
(flags, i->c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->LocalGenerator->AppendFlags
|
|
|
|
(flags, this->Target->GetProperty("COMPILE_FLAGS"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add source file specific flags.
|
|
|
|
this->LocalGenerator->AppendFlags(flags,
|
|
|
|
source->GetProperty("COMPILE_FLAGS"));
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
// TODO: Handle Apple frameworks.
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Refactor with
|
|
|
|
// void cmMakefileTargetGenerator::WriteTargetLanguageFlags().
|
|
|
|
std::string
|
|
|
|
cmNinjaTargetGenerator::
|
|
|
|
ComputeDefines(cmSourceFile *source, const std::string& language)
|
|
|
|
{
|
2012-08-09 11:44:15 +04:00
|
|
|
std::set<std::string> defines;
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
// Add the export symbol definition for shared library objects.
|
|
|
|
if(const char* exportMacro = this->Target->GetExportMacro())
|
|
|
|
{
|
2012-08-09 11:44:15 +04:00
|
|
|
this->LocalGenerator->AppendDefines(defines, exportMacro);
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add preprocessor definitions for this target and configuration.
|
|
|
|
this->LocalGenerator->AppendDefines
|
|
|
|
(defines,
|
2012-09-17 21:56:50 +04:00
|
|
|
this->GeneratorTarget->GetCompileDefinitions());
|
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,
|
2012-09-17 21:56:50 +04:00
|
|
|
this->GeneratorTarget->GetCompileDefinitions(this->GetConfigName()));
|
2011-11-11 09:00:49 +04:00
|
|
|
this->LocalGenerator->AppendDefines
|
|
|
|
(defines,
|
2012-08-09 11:44:15 +04:00
|
|
|
source->GetProperty(defPropName.c_str()));
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
|
2012-08-09 11:44:15 +04:00
|
|
|
std::string definesString;
|
|
|
|
this->LocalGenerator->JoinDefines(defines, definesString,
|
|
|
|
language.c_str());
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2012-04-02 18:55:01 +04:00
|
|
|
result.push_back(this->ModuleDefinitionFile);
|
2012-03-07 02:41:40 +04:00
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
cmNinjaTargetGenerator
|
|
|
|
::GetSourceFilePath(cmSourceFile* source) const
|
|
|
|
{
|
|
|
|
return ConvertToNinjaPath(source->GetFullPath().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
cmNinjaTargetGenerator
|
|
|
|
::GetObjectFilePath(cmSourceFile* source) const
|
|
|
|
{
|
|
|
|
std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
|
|
|
|
if(!path.empty())
|
|
|
|
path += "/";
|
2012-03-13 17:30:23 +04:00
|
|
|
std::string const& objectName = this->GeneratorTarget->Objects[source];
|
|
|
|
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());
|
|
|
|
return ConvertToNinjaPath(dir.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
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
|
|
|
}
|
2012-02-22 00:18:05 +04:00
|
|
|
|
2012-08-22 14:37:55 +04:00
|
|
|
vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
|
|
|
|
ConvertToNinjaPath(pdbPath.c_str()).c_str(),
|
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
EnsureParentDirectoryExists(pdbPath);
|
|
|
|
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
|
|
|
|
::WriteCompileRule(const std::string& language)
|
|
|
|
{
|
|
|
|
cmLocalGenerator::RuleVariables vars;
|
|
|
|
vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
|
|
|
|
vars.CMTarget = this->GetTarget();
|
|
|
|
std::string lang = language;
|
|
|
|
vars.Language = lang.c_str();
|
|
|
|
vars.Source = "$in";
|
|
|
|
vars.Object = "$out";
|
|
|
|
std::string flags = "$FLAGS";
|
|
|
|
vars.Defines = "$DEFINES";
|
2012-02-22 00:18:05 +04:00
|
|
|
vars.TargetPDB = "$TARGET_PDB";
|
2012-10-03 19:19:47 +04:00
|
|
|
vars.ObjectDir = "$OBJECT_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
|
|
|
|
2012-06-09 15:52:20 +04:00
|
|
|
bool useClDeps = false;
|
2012-08-17 18:01:53 +04:00
|
|
|
std::string clBinary;
|
2012-06-13 02:52:46 +04:00
|
|
|
std::string clDepsBinary;
|
|
|
|
std::string clShowPrefix;
|
2012-06-13 19:14:16 +04:00
|
|
|
if (lang == "C" || lang == "CXX" || lang == "RC")
|
2012-06-09 15:52:20 +04:00
|
|
|
{
|
2012-08-17 18:01:53 +04:00
|
|
|
clDepsBinary = mf->GetSafeDefinition("CMAKE_CMCLDEPS_EXECUTABLE");
|
2012-09-05 03:44:11 +04:00
|
|
|
if (!clDepsBinary.empty() && !mf->GetIsSourceFileTryCompile())
|
2012-06-09 15:52:20 +04:00
|
|
|
{
|
2012-08-17 18:01:53 +04:00
|
|
|
clShowPrefix = mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDE_PREFIX");
|
|
|
|
clBinary = mf->GetDefinition("CMAKE_C_COMPILER") ?
|
|
|
|
mf->GetSafeDefinition("CMAKE_C_COMPILER") :
|
|
|
|
mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
|
|
|
|
if (!clBinary.empty() && !clShowPrefix.empty())
|
2012-06-13 02:52:46 +04:00
|
|
|
{
|
|
|
|
useClDeps = true;
|
2012-08-17 18:01:53 +04:00
|
|
|
const std::string quote = " \"";
|
|
|
|
clBinary = quote + clBinary + "\" ";
|
|
|
|
clDepsBinary = quote + clDepsBinary + "\" ";
|
|
|
|
clShowPrefix = quote + clShowPrefix + "\" ";
|
2012-06-13 02:52:46 +04:00
|
|
|
vars.DependencyFile = "$DEP_FILE";
|
|
|
|
}
|
2012-06-09 15:52:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 01:34:48 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
std::string depfile;
|
|
|
|
std::string depfileFlagsName = "CMAKE_DEPFILE_FLAGS_" + language;
|
2012-06-09 00:01:57 +04:00
|
|
|
const char *depfileFlags = mf->GetDefinition(depfileFlagsName.c_str());
|
2012-06-09 15:52:20 +04:00
|
|
|
if (depfileFlags || useClDeps) {
|
2012-06-13 02:52:46 +04:00
|
|
|
std::string depFlagsStr = depfileFlags ? depfileFlags : "";
|
|
|
|
depfile = "$DEP_FILE";
|
|
|
|
cmSystemTools::ReplaceString(depFlagsStr, "<DEPFILE>", "\"$DEP_FILE\"");
|
|
|
|
cmSystemTools::ReplaceString(depFlagsStr, "<OBJECT>", "$out");
|
|
|
|
cmSystemTools::ReplaceString(depFlagsStr, "<CMAKE_C_COMPILER>",
|
2012-06-09 00:01:57 +04:00
|
|
|
mf->GetDefinition("CMAKE_C_COMPILER"));
|
2012-06-13 02:52:46 +04:00
|
|
|
flags += " " + depFlagsStr;
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
|
|
|
vars.Flags = flags.c_str();
|
|
|
|
|
2012-03-07 02:41:40 +04:00
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
// Rule for compiling object file.
|
|
|
|
std::string compileCmdVar = "CMAKE_";
|
|
|
|
compileCmdVar += language;
|
|
|
|
compileCmdVar += "_COMPILE_OBJECT";
|
2012-06-09 00:01:57 +04:00
|
|
|
std::string compileCmd = mf->GetRequiredDefinition(compileCmdVar.c_str());
|
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
|
|
|
|
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-08-17 18:01:53 +04:00
|
|
|
std::string cmdLine;
|
2012-06-09 15:52:20 +04:00
|
|
|
if(useClDeps)
|
2012-06-08 18:31:54 +04:00
|
|
|
{
|
2012-08-17 18:01:53 +04:00
|
|
|
cmdLine = clDepsBinary + lang + " $in \"$DEP_FILE\" $out " +
|
|
|
|
clShowPrefix + clBinary;
|
2012-06-08 18:31:54 +04:00
|
|
|
}
|
2012-08-17 18:01:53 +04:00
|
|
|
cmdLine += this->GetLocalGenerator()->BuildCommandLine(compileCmds);
|
|
|
|
|
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.
|
2012-06-06 23:14:40 +04:00
|
|
|
cmOStringStream comment;
|
2011-11-11 09:00:49 +04:00
|
|
|
comment << "Rule for compiling " << language << " files.";
|
2012-06-06 23:14:40 +04:00
|
|
|
cmOStringStream description;
|
2011-11-11 09:00:49 +04:00
|
|
|
description << "Building " << language << " object $out";
|
|
|
|
this->GetGlobalGenerator()->AddRule(this->LanguageCompilerRule(language),
|
2012-02-27 08:05:31 +04:00
|
|
|
cmdLine,
|
2011-11-11 09:00:49 +04:00
|
|
|
description.str(),
|
|
|
|
comment.str(),
|
|
|
|
depfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
2012-03-13 17:24:54 +04:00
|
|
|
for(std::vector<cmSourceFile*>::const_iterator
|
|
|
|
si = this->GeneratorTarget->CustomCommands.begin();
|
|
|
|
si != this->GeneratorTarget->CustomCommands.end(); ++si)
|
|
|
|
{
|
|
|
|
cmCustomCommand const* cc = (*si)->GetCustomCommand();
|
|
|
|
this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget());
|
|
|
|
}
|
2012-07-16 19:34:22 +04:00
|
|
|
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
|
|
|
|
this->GeneratorTarget->HeaderSources,
|
2012-07-18 14:17:39 +04:00
|
|
|
this->MacOSXContentGenerator);
|
2012-07-16 19:34:22 +04:00
|
|
|
this->OSXBundleGenerator->GenerateMacOSXContentStatements(
|
|
|
|
this->GeneratorTarget->ExtraSources,
|
2012-07-18 14:17:39 +04:00
|
|
|
this->MacOSXContentGenerator);
|
2012-03-13 17:24:54 +04:00
|
|
|
for(std::vector<cmSourceFile*>::const_iterator
|
|
|
|
si = this->GeneratorTarget->ExternalObjects.begin();
|
|
|
|
si != this->GeneratorTarget->ExternalObjects.end(); ++si)
|
|
|
|
{
|
|
|
|
this->Objects.push_back(this->GetSourceFilePath(*si));
|
|
|
|
}
|
|
|
|
for(std::vector<cmSourceFile*>::const_iterator
|
|
|
|
si = this->GeneratorTarget->ObjectSources.begin();
|
|
|
|
si != this->GeneratorTarget->ObjectSources.end(); ++si)
|
|
|
|
{
|
|
|
|
this->WriteObjectBuildStatement(*si);
|
|
|
|
}
|
2012-04-02 18:55:01 +04:00
|
|
|
if(!this->GeneratorTarget->ModuleDefinitionFile.empty())
|
|
|
|
{
|
|
|
|
this->ModuleDefinitionFile = this->ConvertToNinjaPath(
|
|
|
|
this->GeneratorTarget->ModuleDefinitionFile.c_str());
|
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2012-03-15 16:56:40 +04:00
|
|
|
{
|
|
|
|
// Add object library contents as external objects.
|
|
|
|
std::vector<std::string> objs;
|
|
|
|
this->GeneratorTarget->UseObjectLibraries(objs);
|
|
|
|
for(std::vector<std::string>::iterator oi = objs.begin();
|
|
|
|
oi != objs.end(); ++oi)
|
|
|
|
{
|
|
|
|
this->Objects.push_back(ConvertToNinjaPath(oi->c_str()));
|
|
|
|
}
|
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
|
|
|
|
this->GetBuildFileStream() << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cmNinjaTargetGenerator
|
|
|
|
::WriteObjectBuildStatement(cmSourceFile* source)
|
|
|
|
{
|
|
|
|
std::string comment;
|
2012-07-17 20:54:56 +04:00
|
|
|
const std::string language = source->GetLanguage();
|
2011-11-11 09:00:49 +04:00
|
|
|
std::string rule = this->LanguageCompilerRule(language);
|
|
|
|
|
|
|
|
cmNinjaDeps outputs;
|
|
|
|
std::string objectFileName = this->GetObjectFilePath(source);
|
|
|
|
outputs.push_back(objectFileName);
|
|
|
|
// Add this object to the list of object files.
|
|
|
|
this->Objects.push_back(objectFileName);
|
|
|
|
|
|
|
|
cmNinjaDeps explicitDeps;
|
2012-07-17 20:54:56 +04:00
|
|
|
std::string sourceFileName;
|
|
|
|
if (language == "RC")
|
|
|
|
sourceFileName = source->GetFullPath();
|
|
|
|
else
|
|
|
|
sourceFileName = this->GetSourceFilePath(source);
|
2011-11-11 09:00:49 +04:00
|
|
|
explicitDeps.push_back(sourceFileName);
|
|
|
|
|
|
|
|
// Ensure that the target dependencies are built before any source file in
|
|
|
|
// the target, using order-only dependencies.
|
|
|
|
cmNinjaDeps orderOnlyDeps;
|
|
|
|
this->GetLocalGenerator()->AppendTargetDepends(this->Target, orderOnlyDeps);
|
|
|
|
|
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);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-03-13 17:24:54 +04:00
|
|
|
// Add order-only dependencies on custom command outputs.
|
|
|
|
for(std::vector<cmSourceFile*>::const_iterator
|
|
|
|
si = this->GeneratorTarget->CustomCommands.begin();
|
|
|
|
si != this->GeneratorTarget->CustomCommands.end(); ++si)
|
|
|
|
{
|
|
|
|
cmCustomCommand const* cc = (*si)->GetCustomCommand();
|
|
|
|
const std::vector<std::string>& ccoutputs = cc->GetOutputs();
|
|
|
|
std::transform(ccoutputs.begin(), ccoutputs.end(),
|
2012-10-03 20:09:49 +04:00
|
|
|
std::back_inserter(implicitDeps), MapToNinjaPath());
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmNinjaVars vars;
|
|
|
|
vars["FLAGS"] = this->ComputeFlagsForObject(source, language);
|
|
|
|
vars["DEFINES"] = this->ComputeDefines(source, language);
|
2012-06-13 02:52:46 +04:00
|
|
|
vars["DEP_FILE"] = objectFileName + ".d";;
|
|
|
|
EnsureParentDirectoryExists(objectFileName);
|
2012-06-12 06:17:55 +04:00
|
|
|
|
2012-10-03 19:19:47 +04:00
|
|
|
std::string objectDir = cmSystemTools::GetFilenamePath(objectFileName);
|
|
|
|
objectDir = this->GetLocalGenerator()->Convert(objectDir.c_str(),
|
|
|
|
cmLocalGenerator::START_OUTPUT,
|
|
|
|
cmLocalGenerator::SHELL);
|
|
|
|
vars["OBJECT_DIR"] = objectDir;
|
|
|
|
|
|
|
|
|
2012-08-22 14:37:55 +04:00
|
|
|
this->SetMsvcTargetPdbVariable(vars);
|
2011-11-11 09:00:49 +04:00
|
|
|
|
2012-05-10 01:47:37 +04:00
|
|
|
if(this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS"))
|
|
|
|
{
|
|
|
|
cmLocalGenerator::RuleVariables compileObjectVars;
|
|
|
|
std::string lang = language;
|
|
|
|
compileObjectVars.Language = lang.c_str();
|
2012-06-18 21:59:33 +04:00
|
|
|
|
2012-06-21 00:47:41 +04:00
|
|
|
std::string escapedSourceFileName = sourceFileName;
|
|
|
|
|
|
|
|
if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str()))
|
2012-06-18 21:59:33 +04:00
|
|
|
{
|
|
|
|
escapedSourceFileName = cmSystemTools::CollapseFullPath(
|
|
|
|
escapedSourceFileName.c_str(),
|
2012-06-19 22:49:13 +04:00
|
|
|
this->GetGlobalGenerator()->GetCMakeInstance()->
|
|
|
|
GetHomeOutputDirectory());
|
2012-06-18 21:59:33 +04:00
|
|
|
}
|
|
|
|
|
2012-06-21 00:47:41 +04:00
|
|
|
escapedSourceFileName =
|
2012-05-23 20:08:23 +04:00
|
|
|
this->LocalGenerator->ConvertToOutputFormat(
|
2012-06-21 00:47:41 +04:00
|
|
|
escapedSourceFileName.c_str(), cmLocalGenerator::SHELL);
|
|
|
|
|
2012-05-23 20:08:23 +04:00
|
|
|
compileObjectVars.Source = escapedSourceFileName.c_str();
|
2012-05-10 01:47:37 +04:00
|
|
|
compileObjectVars.Object = objectFileName.c_str();
|
2012-10-03 19:19:47 +04:00
|
|
|
compileObjectVars.ObjectDir = objectDir.c_str();
|
2012-05-10 01:47:37 +04:00
|
|
|
compileObjectVars.Flags = vars["FLAGS"].c_str();
|
|
|
|
compileObjectVars.Defines = vars["DEFINES"].c_str();
|
|
|
|
|
|
|
|
// Rule for compiling object file.
|
|
|
|
std::string compileCmdVar = "CMAKE_";
|
|
|
|
compileCmdVar += language;
|
|
|
|
compileCmdVar += "_COMPILE_OBJECT";
|
|
|
|
std::string compileCmd =
|
|
|
|
this->GetMakefile()->GetRequiredDefinition(compileCmdVar.c_str());
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-11-11 09:00:49 +04:00
|
|
|
cmGlobalNinjaGenerator::WriteBuild(this->GetBuildFileStream(),
|
|
|
|
comment,
|
|
|
|
rule,
|
|
|
|
outputs,
|
|
|
|
explicitDeps,
|
2012-09-26 00:21:54 +04:00
|
|
|
implicitDeps,
|
2011-11-11 09:00:49 +04:00
|
|
|
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());
|
|
|
|
cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(),
|
|
|
|
"Additional output files.",
|
|
|
|
outputList,
|
|
|
|
outputs);
|
|
|
|
}
|
2011-11-11 09:00:49 +04:00
|
|
|
}
|
2012-03-07 02:41:40 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmNinjaTargetGenerator
|
|
|
|
::AddModuleDefinitionFlag(std::string& flags)
|
|
|
|
{
|
2012-04-02 18:55:01 +04:00
|
|
|
if(this->ModuleDefinitionFile.empty())
|
2012-03-07 02:41:40 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Create a per-language flag variable.
|
|
|
|
const char* defFileFlag =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG");
|
|
|
|
if(!defFileFlag)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append the flag and value. Use ConvertToLinkReference to help
|
|
|
|
// vs6's "cl -link" pass it to the linker.
|
|
|
|
std::string flag = defFileFlag;
|
|
|
|
flag += (this->LocalGenerator->ConvertToLinkReference(
|
2012-04-02 18:55:01 +04:00
|
|
|
this->ModuleDefinitionFile.c_str()));
|
2012-03-07 02:41:40 +04:00
|
|
|
this->LocalGenerator->AppendFlags(flags, flag.c_str());
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path.c_str()));
|
|
|
|
}
|
2012-07-10 22:13:01 +04:00
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-07-16 19:34:22 +04:00
|
|
|
void
|
|
|
|
cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
|
2012-07-10 22:13:01 +04:00
|
|
|
cmSourceFile& source, const char* pkgloc)
|
|
|
|
{
|
|
|
|
// Skip OS X content when not building a Framework or Bundle.
|
2012-07-16 19:34:22 +04:00
|
|
|
if(this->Generator->OSXBundleGenerator->GetMacContentDirectory().empty())
|
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 =
|
|
|
|
this->Generator->GetLocalGenerator()->ConvertToNinjaPath(input.c_str());
|
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 =
|
|
|
|
this->Generator->GetLocalGenerator()->ConvertToNinjaPath(output.c_str());
|
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
|
|
|
}
|