2015-07-07 23:37:56 +03:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2015 Kitware, Inc., Insight Software Consortium
|
|
|
|
|
|
|
|
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 "cmCommonTargetGenerator.h"
|
|
|
|
|
2015-07-08 23:38:49 +03:00
|
|
|
#include "cmComputeLinkInformation.h"
|
2015-07-08 18:13:11 +03:00
|
|
|
#include "cmGeneratorTarget.h"
|
|
|
|
#include "cmGlobalCommonGenerator.h"
|
|
|
|
#include "cmLocalCommonGenerator.h"
|
2015-07-08 22:24:17 +03:00
|
|
|
#include "cmMakefile.h"
|
2015-07-08 22:52:42 +03:00
|
|
|
#include "cmSourceFile.h"
|
2015-07-08 22:50:25 +03:00
|
|
|
#include "cmSystemTools.h"
|
2015-07-08 18:13:11 +03:00
|
|
|
|
2016-06-16 17:54:20 +03:00
|
|
|
cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt)
|
|
|
|
: GeneratorTarget(gt)
|
2015-07-08 18:13:11 +03:00
|
|
|
, Makefile(gt->Makefile)
|
|
|
|
, LocalGenerator(static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator))
|
|
|
|
, GlobalGenerator(static_cast<cmGlobalCommonGenerator*>(
|
2016-05-16 17:34:04 +03:00
|
|
|
gt->LocalGenerator->GetGlobalGenerator()))
|
2015-07-08 22:02:11 +03:00
|
|
|
, ConfigName(LocalGenerator->GetConfigName())
|
2015-07-08 22:24:17 +03:00
|
|
|
, ModuleDefinitionFile(GeneratorTarget->GetModuleDefinitionFile(ConfigName))
|
2015-07-07 23:37:56 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cmCommonTargetGenerator::~cmCommonTargetGenerator()
|
|
|
|
{
|
|
|
|
}
|
2015-07-08 22:02:11 +03:00
|
|
|
|
|
|
|
std::string const& cmCommonTargetGenerator::GetConfigName() const
|
|
|
|
{
|
|
|
|
return this->ConfigName;
|
|
|
|
}
|
2015-07-08 21:49:04 +03:00
|
|
|
|
2015-07-08 22:49:03 +03:00
|
|
|
std::string cmCommonTargetGenerator::Convert(
|
2016-05-20 00:11:40 +03:00
|
|
|
std::string const& source, cmOutputConverter::RelativeRoot relative,
|
|
|
|
cmOutputConverter::OutputFormat output)
|
2015-07-08 22:49:03 +03:00
|
|
|
{
|
|
|
|
return this->LocalGenerator->Convert(source, relative, output);
|
|
|
|
}
|
|
|
|
|
2015-07-08 21:49:04 +03:00
|
|
|
const char* cmCommonTargetGenerator::GetFeature(const std::string& feature)
|
|
|
|
{
|
|
|
|
return this->GeneratorTarget->GetFeature(feature, this->ConfigName);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCommonTargetGenerator::GetFeatureAsBool(const std::string& feature)
|
|
|
|
{
|
|
|
|
return this->GeneratorTarget->GetFeatureAsBool(feature, this->ConfigName);
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCommonTargetGenerator::AddFeatureFlags(std::string& flags,
|
|
|
|
const std::string& lang)
|
2015-07-08 21:49:04 +03:00
|
|
|
{
|
|
|
|
// Add language-specific flags.
|
|
|
|
this->LocalGenerator->AddLanguageFlags(flags, lang, this->ConfigName);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION")) {
|
2015-07-08 21:49:04 +03:00
|
|
|
this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-08 21:49:04 +03:00
|
|
|
}
|
2015-07-08 22:24:17 +03:00
|
|
|
|
|
|
|
void cmCommonTargetGenerator::AddModuleDefinitionFlag(std::string& flags)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->ModuleDefinitionFile) {
|
2015-07-08 22:24:17 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-08 22:24:17 +03:00
|
|
|
|
|
|
|
// TODO: Create a per-language flag variable.
|
|
|
|
const char* defFileFlag =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!defFileFlag) {
|
2015-07-08 22:24:17 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-08 22:24:17 +03:00
|
|
|
|
|
|
|
// 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(
|
2016-05-16 17:34:04 +03:00
|
|
|
this->ModuleDefinitionFile->GetFullPath()));
|
2015-07-08 22:24:17 +03:00
|
|
|
this->LocalGenerator->AppendFlags(flags, flag);
|
|
|
|
}
|
2015-07-08 22:50:25 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCommonTargetGenerator::AppendFortranFormatFlags(
|
|
|
|
std::string& flags, cmSourceFile const& source)
|
2015-07-08 22:52:42 +03:00
|
|
|
{
|
|
|
|
const char* srcfmt = source.GetProperty("Fortran_FORMAT");
|
2016-05-20 00:11:40 +03:00
|
|
|
cmOutputConverter::FortranFormat format =
|
2016-06-06 00:44:39 +03:00
|
|
|
cmOutputConverter::GetFortranFormat(srcfmt);
|
2016-05-20 00:11:40 +03:00
|
|
|
if (format == cmOutputConverter::FortranFormatNone) {
|
2015-10-10 16:51:21 +03:00
|
|
|
const char* tgtfmt = this->GeneratorTarget->GetProperty("Fortran_FORMAT");
|
2016-06-06 00:44:39 +03:00
|
|
|
format = cmOutputConverter::GetFortranFormat(tgtfmt);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-06-27 23:44:16 +03:00
|
|
|
const char* var = CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (format) {
|
2016-05-20 00:11:40 +03:00
|
|
|
case cmOutputConverter::FortranFormatFixed:
|
2016-05-16 17:34:04 +03:00
|
|
|
var = "CMAKE_Fortran_FORMAT_FIXED_FLAG";
|
|
|
|
break;
|
2016-05-20 00:11:40 +03:00
|
|
|
case cmOutputConverter::FortranFormatFree:
|
2016-05-16 17:34:04 +03:00
|
|
|
var = "CMAKE_Fortran_FORMAT_FREE_FLAG";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (var) {
|
|
|
|
this->LocalGenerator->AppendFlags(flags,
|
|
|
|
this->Makefile->GetDefinition(var));
|
|
|
|
}
|
2015-07-08 22:52:42 +03:00
|
|
|
}
|
2015-07-08 23:38:49 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmCommonTargetGenerator::GetFlags(const std::string& l)
|
2015-07-09 17:05:12 +03:00
|
|
|
{
|
|
|
|
ByLanguageMap::iterator i = this->FlagsByLanguage.find(l);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i == this->FlagsByLanguage.end()) {
|
2015-07-09 17:05:12 +03:00
|
|
|
std::string flags;
|
|
|
|
|
2016-06-10 19:04:58 +03:00
|
|
|
this->LocalGenerator->GetTargetCompileFlags(this->GeneratorTarget,
|
|
|
|
this->ConfigName, l, flags);
|
2015-07-09 17:05:12 +03:00
|
|
|
|
|
|
|
ByLanguageMap::value_type entry(l, flags);
|
|
|
|
i = this->FlagsByLanguage.insert(entry).first;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-09 17:05:12 +03:00
|
|
|
return i->second;
|
|
|
|
}
|
2015-07-09 17:10:25 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmCommonTargetGenerator::GetDefines(const std::string& l)
|
2015-07-09 17:10:25 +03:00
|
|
|
{
|
|
|
|
ByLanguageMap::iterator i = this->DefinesByLanguage.find(l);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i == this->DefinesByLanguage.end()) {
|
2015-07-09 17:10:25 +03:00
|
|
|
std::set<std::string> defines;
|
2016-06-08 14:23:25 +03:00
|
|
|
this->LocalGenerator->GetTargetDefines(this->GeneratorTarget,
|
|
|
|
this->ConfigName, l, defines);
|
2015-07-09 17:10:25 +03:00
|
|
|
|
|
|
|
std::string definesString;
|
2016-06-08 14:23:25 +03:00
|
|
|
this->LocalGenerator->JoinDefines(defines, definesString, l);
|
2015-07-09 17:10:25 +03:00
|
|
|
|
|
|
|
ByLanguageMap::value_type entry(l, definesString);
|
|
|
|
i = this->DefinesByLanguage.insert(entry).first;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-09 17:10:25 +03:00
|
|
|
return i->second;
|
|
|
|
}
|
2015-07-13 17:35:04 +03:00
|
|
|
|
|
|
|
std::string cmCommonTargetGenerator::GetIncludes(std::string const& l)
|
|
|
|
{
|
|
|
|
ByLanguageMap::iterator i = this->IncludesByLanguage.find(l);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i == this->IncludesByLanguage.end()) {
|
2015-07-13 17:35:04 +03:00
|
|
|
std::string includes;
|
|
|
|
this->AddIncludeFlags(includes, l);
|
|
|
|
ByLanguageMap::value_type entry(l, includes);
|
|
|
|
i = this->IncludesByLanguage.insert(entry).first;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-13 17:35:04 +03:00
|
|
|
return i->second;
|
|
|
|
}
|
2015-07-28 21:05:34 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::vector<std::string> cmCommonTargetGenerator::GetLinkedTargetDirectories()
|
|
|
|
const
|
2015-07-28 21:05:34 +03:00
|
|
|
{
|
|
|
|
std::vector<std::string> dirs;
|
2015-10-08 02:37:30 +03:00
|
|
|
std::set<cmGeneratorTarget const*> emitted;
|
2015-07-28 21:05:34 +03:00
|
|
|
if (cmComputeLinkInformation* cli =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->GeneratorTarget->GetLinkInformation(this->ConfigName)) {
|
2015-07-28 21:05:34 +03:00
|
|
|
cmComputeLinkInformation::ItemVector const& items = cli->GetItems();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (cmComputeLinkInformation::ItemVector::const_iterator i =
|
|
|
|
items.begin();
|
|
|
|
i != items.end(); ++i) {
|
2015-10-08 01:49:38 +03:00
|
|
|
cmGeneratorTarget const* linkee = i->Target;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (linkee && !linkee->IsImported()
|
|
|
|
// We can ignore the INTERFACE_LIBRARY items because
|
|
|
|
// Target->GetLinkInformation already processed their
|
|
|
|
// link interface and they don't have any output themselves.
|
|
|
|
&& linkee->GetType() != cmState::INTERFACE_LIBRARY &&
|
|
|
|
emitted.insert(linkee).second) {
|
2015-10-08 01:49:38 +03:00
|
|
|
cmLocalGenerator* lg = linkee->GetLocalGenerator();
|
2015-10-16 20:19:49 +03:00
|
|
|
std::string di = lg->GetCurrentBinaryDirectory();
|
2015-07-28 21:05:34 +03:00
|
|
|
di += "/";
|
2015-10-09 23:27:46 +03:00
|
|
|
di += lg->GetTargetDirectory(linkee);
|
2015-07-28 21:05:34 +03:00
|
|
|
dirs.push_back(di);
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-07-28 21:05:34 +03:00
|
|
|
return dirs;
|
|
|
|
}
|
2015-09-16 17:24:16 +03:00
|
|
|
|
|
|
|
std::string cmCommonTargetGenerator::GetManifests()
|
|
|
|
{
|
|
|
|
std::vector<cmSourceFile const*> manifest_srcs;
|
|
|
|
this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
|
|
|
|
|
|
|
|
std::vector<std::string> manifests;
|
|
|
|
for (std::vector<cmSourceFile const*>::iterator mi = manifest_srcs.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
mi != manifest_srcs.end(); ++mi) {
|
|
|
|
manifests.push_back(this->Convert(
|
2016-06-16 17:54:20 +03:00
|
|
|
(*mi)->GetFullPath(), this->LocalGenerator->GetWorkingDirectory(),
|
|
|
|
cmOutputConverter::SHELL));
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-16 17:24:16 +03:00
|
|
|
|
|
|
|
return cmJoin(manifests, " ");
|
|
|
|
}
|
2016-02-20 22:35:18 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCommonTargetGenerator::AppendOSXVerFlag(std::string& flags,
|
|
|
|
const std::string& lang,
|
|
|
|
const char* name, bool so)
|
2016-02-20 22:35:18 +03:00
|
|
|
{
|
|
|
|
// Lookup the flag to specify the version.
|
|
|
|
std::string fvar = "CMAKE_";
|
|
|
|
fvar += lang;
|
|
|
|
fvar += "_OSX_";
|
|
|
|
fvar += name;
|
|
|
|
fvar += "_VERSION_FLAG";
|
|
|
|
const char* flag = this->Makefile->GetDefinition(fvar);
|
|
|
|
|
|
|
|
// Skip if no such flag.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!flag) {
|
2016-02-20 22:35:18 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-02-20 22:35:18 +03:00
|
|
|
|
|
|
|
// Lookup the target version information.
|
|
|
|
int major;
|
|
|
|
int minor;
|
|
|
|
int patch;
|
|
|
|
this->GeneratorTarget->GetTargetVersion(so, major, minor, patch);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (major > 0 || minor > 0 || patch > 0) {
|
2016-02-20 22:35:18 +03:00
|
|
|
// Append the flag since a non-zero version is specified.
|
|
|
|
std::ostringstream vflag;
|
|
|
|
vflag << flag << major << "." << minor << "." << patch;
|
|
|
|
this->LocalGenerator->AppendFlags(flags, vflag.str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-02-20 22:35:18 +03:00
|
|
|
}
|