summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r--Source/cmLocalGenerator.cxx147
1 files changed, 121 insertions, 26 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 7077bbb..307024a 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -13,7 +13,6 @@
#include "cmInstallScriptGenerator.h"
#include "cmInstallTargetGenerator.h"
#include "cmLinkLineComputer.h"
-#include "cmLinkLineDeviceComputer.h"
#include "cmMakefile.h"
#include "cmRulePlaceholderExpander.h"
#include "cmSourceFile.h"
@@ -31,9 +30,9 @@
#include "cmCryptoHash.h"
#endif
+#include "cmsys/RegularExpression.hxx"
#include <algorithm>
#include <assert.h>
-#include <cmsys/RegularExpression.hxx>
#include <iterator>
#include <sstream>
#include <stdio.h>
@@ -89,7 +88,19 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
std::vector<std::string> enabledLanguages =
this->GetState()->GetEnabledLanguages();
- this->CompilerSysroot = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
+ if (const char* sysrootCompile =
+ this->Makefile->GetDefinition("CMAKE_SYSROOT_COMPILE")) {
+ this->CompilerSysroot = sysrootCompile;
+ } else {
+ this->CompilerSysroot = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
+ }
+
+ if (const char* sysrootLink =
+ this->Makefile->GetDefinition("CMAKE_SYSROOT_LINK")) {
+ this->LinkerSysroot = sysrootLink;
+ } else {
+ this->LinkerSysroot = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
+ }
for (std::vector<std::string>::iterator i = enabledLanguages.begin();
i != enabledLanguages.end(); ++i) {
@@ -143,7 +154,8 @@ cmRulePlaceholderExpander* cmLocalGenerator::CreateRulePlaceholderExpander()
const
{
return new cmRulePlaceholderExpander(this->Compilers, this->VariableMappings,
- this->CompilerSysroot);
+ this->CompilerSysroot,
+ this->LinkerSysroot);
}
cmLocalGenerator::~cmLocalGenerator()
@@ -559,6 +571,31 @@ void cmLocalGenerator::ComputeTargetManifest()
}
}
+bool cmLocalGenerator::ComputeTargetCompileFeatures()
+{
+ // Collect the set of configuration types.
+ std::vector<std::string> configNames;
+ this->Makefile->GetConfigurations(configNames);
+ if (configNames.empty()) {
+ configNames.push_back("");
+ }
+
+ // Process compile features of all targets.
+ std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
+ for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
+ t != targets.end(); ++t) {
+ cmGeneratorTarget* target = *t;
+ for (std::vector<std::string>::iterator ci = configNames.begin();
+ ci != configNames.end(); ++ci) {
+ if (!target->ComputeCompileFeatures(*ci)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
bool cmLocalGenerator::IsRootMakefile() const
{
return !this->StateSnapshot.GetBuildsystemDirectoryParent().IsValid();
@@ -743,14 +780,6 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags,
this->AppendFlagEscape(flags, *i);
}
}
- std::vector<std::string> features;
- target->GetCompileFeatures(features, config);
- for (std::vector<std::string>::const_iterator it = features.begin();
- it != features.end(); ++it) {
- if (!this->Makefile->AddRequiredTargetFeature(target->Target, *it)) {
- return;
- }
- }
for (std::map<std::string, std::string>::const_iterator it =
target->GetMaxLanguageStandards().begin();
@@ -827,7 +856,13 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
return;
}
- std::string rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
+ std::string rootPath;
+ if (const char* sysrootCompile =
+ this->Makefile->GetDefinition("CMAKE_SYSROOT_COMPILE")) {
+ rootPath = sysrootCompile;
+ } else {
+ rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
+ }
std::vector<std::string> implicitDirs;
// Load implicit include directories for this language.
@@ -916,6 +951,9 @@ void cmLocalGenerator::GetTargetFlags(
const char* libraryLinkVariable =
"CMAKE_SHARED_LINKER_FLAGS"; // default to shared library
+ const std::string linkLanguage =
+ linkLineComputer->GetLinkerLanguage(target, buildType);
+
switch (target->GetType()) {
case cmStateEnums::STATIC_LIBRARY:
this->GetStaticLibraryFlags(linkFlags, buildType, target);
@@ -977,16 +1015,13 @@ void cmLocalGenerator::GetTargetFlags(
linkFlags += this->Makefile->GetSafeDefinition(build);
linkFlags += " ";
}
-
- const std::string linkLanguage =
- linkLineComputer->GetLinkerLanguage(target, buildType);
if (linkLanguage.empty()) {
cmSystemTools::Error(
"CMake can not determine linker language for target: ",
target->GetName().c_str());
return;
}
- this->AddLanguageFlags(flags, linkLanguage, buildType);
+ this->AddLanguageFlagsForLinking(flags, target, linkLanguage, buildType);
if (pcli) {
this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs,
frameworkPath, linkPath);
@@ -1041,6 +1076,8 @@ void cmLocalGenerator::GetTargetFlags(
default:
break;
}
+
+ this->AppendIPOLinkerFlags(linkFlags, target, config, linkLanguage);
}
void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target,
@@ -1051,11 +1088,7 @@ void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target,
cmMakefile* mf = this->GetMakefile();
// Add language-specific flags.
- this->AddLanguageFlags(flags, lang, config);
-
- if (target->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION", config)) {
- this->AppendFeatureOptions(flags, lang, "IPO");
- }
+ this->AddLanguageFlags(flags, target, lang, config);
this->AddArchitectureFlags(flags, target, lang, config);
@@ -1288,6 +1321,7 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
}
void cmLocalGenerator::AddLanguageFlags(std::string& flags,
+ cmGeneratorTarget const* target,
const std::string& lang,
const std::string& config)
{
@@ -1296,6 +1330,26 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
flagsVar += lang;
flagsVar += "_FLAGS";
this->AddConfigVariableFlags(flags, flagsVar, config);
+
+ if (target->IsIPOEnabled(config)) {
+ this->AppendFeatureOptions(flags, lang, "IPO");
+ }
+}
+
+void cmLocalGenerator::AddLanguageFlagsForLinking(
+ std::string& flags, cmGeneratorTarget const* target, const std::string& lang,
+ const std::string& config)
+{
+ if (this->Makefile->IsOn("CMAKE_" + lang +
+ "_LINK_WITH_STANDARD_COMPILE_OPTION")) {
+ // This toolchain requires use of the language standard flag
+ // when linking in order to use the matching standard library.
+ // FIXME: If CMake gains an abstraction for standard library
+ // selection, this will have to be reconciled with it.
+ this->AddCompilerRequirementFlag(flags, target, lang);
+ }
+
+ this->AddLanguageFlags(flags, target, lang, config);
}
cmGeneratorTarget* cmLocalGenerator::FindGeneratorTargetToUse(
@@ -1462,7 +1516,11 @@ void cmLocalGenerator::AddCompilerRequirementFlag(
"does not know the compile flags to use to enable it.";
this->IssueMessage(cmake::FATAL_ERROR, e.str());
} else {
- this->AppendFlagEscape(flags, opt);
+ std::vector<std::string> optVec;
+ cmSystemTools::ExpandListArgument(opt, optVec);
+ for (size_t i = 0; i < optVec.size(); ++i) {
+ this->AppendFlagEscape(flags, optVec[i]);
+ }
}
return;
}
@@ -1479,6 +1537,7 @@ void cmLocalGenerator::AddCompilerRequirementFlag(
langStdMap["C"].push_back("99");
langStdMap["C"].push_back("90");
+ langStdMap["CUDA"].push_back("14");
langStdMap["CUDA"].push_back("11");
langStdMap["CUDA"].push_back("98");
}
@@ -1769,6 +1828,38 @@ void cmLocalGenerator::AppendFlagEscape(std::string& flags,
this->AppendFlags(flags, this->EscapeForShell(rawFlag));
}
+void cmLocalGenerator::AppendIPOLinkerFlags(std::string& flags,
+ cmGeneratorTarget* target,
+ const std::string& config,
+ const std::string& lang)
+{
+ if (!target->IsIPOEnabled(config)) {
+ return;
+ }
+
+ switch (target->GetType()) {
+ case cmStateEnums::EXECUTABLE:
+ case cmStateEnums::SHARED_LIBRARY:
+ case cmStateEnums::MODULE_LIBRARY:
+ break;
+ default:
+ return;
+ }
+
+ const std::string name = "CMAKE_" + lang + "_LINK_OPTIONS_IPO";
+ const char* rawFlagsList = this->Makefile->GetDefinition(name);
+ if (rawFlagsList == CM_NULLPTR) {
+ return;
+ }
+
+ std::vector<std::string> flagsList;
+ cmSystemTools::ExpandListArgument(rawFlagsList, flagsList);
+ for (std::vector<std::string>::const_iterator oi = flagsList.begin();
+ oi != flagsList.end(); ++oi) {
+ this->AppendFlagEscape(flags, *oi);
+ }
+}
+
void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
const char* defines_list) const
{
@@ -2163,7 +2254,7 @@ bool cmLocalGenerator::IsNMake() const
std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
const cmSourceFile& source, std::string const& dir_max,
- bool* hasSourceExtension)
+ bool* hasSourceExtension, char const* customOutputExtension)
{
// Construct the object file name using the full path to the source
// file which is its only unique identification.
@@ -2224,7 +2315,7 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
}
// Remove the source extension if it is to be replaced.
- if (replaceExt) {
+ if (replaceExt || customOutputExtension) {
keptSourceExtension = false;
std::string::size_type dot_pos = objectName.rfind('.');
if (dot_pos != std::string::npos) {
@@ -2233,7 +2324,11 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
}
// Store the new extension.
- objectName += this->GlobalGenerator->GetLanguageOutputExtension(source);
+ if (customOutputExtension) {
+ objectName += customOutputExtension;
+ } else {
+ objectName += this->GlobalGenerator->GetLanguageOutputExtension(source);
+ }
}
if (hasSourceExtension) {
*hasSourceExtension = keptSourceExtension;