summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-09-22 13:18:43 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-09-22 13:18:53 (GMT)
commitd2655c59dc914ec24f2bca142a748612caeb9e3d (patch)
tree389ee99aeb3b58b7bc92b78398fbd9ba2f238392 /Source
parent2dafd1f09227915197eb268cac6affdb37a24647 (diff)
parentb32ea7cff050574c00b5207035762e3b24f8a405 (diff)
downloadCMake-d2655c59dc914ec24f2bca142a748612caeb9e3d.zip
CMake-d2655c59dc914ec24f2bca142a748612caeb9e3d.tar.gz
CMake-d2655c59dc914ec24f2bca142a748612caeb9e3d.tar.bz2
Merge topic 'cuda-factor-out-lang'
b32ea7cff0 CUDA: Factor out helper to generate CUDA architecture flags b3a1f17567 CUDA: Factor out helper to validate CMAKE_CUDA_ARCHITECTURES 8617c28221 CUDA: Factor out helper for detecting native CUDA architectures 0db0fe7958 CUDA: Factor out helper to compute all CUDA architectures c16f1e2b93 CUDA: Factor out helper to find CUDA Toolkit for compiler a6841a967b CUDA: Factor out helper to filter implicit link libraries deff0e638d CUDA: Factor out helper to parse NVCC implicit compiler and linker flags e1b2a5062f CUDA: Factor out some NVCC compiler information ... Acked-by: Kitware Robot <kwrobot@kitware.com> Reviewed-by: Raul Tambre <raul@tambre.ee> Merge-request: !8816
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGeneratorTarget.cxx90
-rw-r--r--Source/cmGeneratorTarget.h6
2 files changed, 56 insertions, 40 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 764618e..80e3392 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -3387,12 +3387,12 @@ void cmGeneratorTarget::AddExplicitLanguageFlags(std::string& flags,
}
void cmGeneratorTarget::AddCUDAArchitectureFlags(cmBuildStep compileOrLink,
- const std::string& config,
+ std::string const& config,
std::string& flags) const
{
- std::string property = this->GetSafeProperty("CUDA_ARCHITECTURES");
+ std::string arch = this->GetSafeProperty("CUDA_ARCHITECTURES");
- if (property.empty()) {
+ if (arch.empty()) {
switch (this->GetPolicyStatusCMP0104()) {
case cmPolicies::WARN:
if (!this->LocalGenerator->GetCMakeInstance()->GetIsInTryCompile()) {
@@ -3414,48 +3414,60 @@ void cmGeneratorTarget::AddCUDAArchitectureFlags(cmBuildStep compileOrLink,
}
// If CUDA_ARCHITECTURES is false we don't add any architectures.
- if (cmIsOff(property)) {
+ if (cmIsOff(arch)) {
return;
}
- std::string const& compiler =
- this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID");
- const bool ipoEnabled = this->IsIPOEnabled("CUDA", config);
+ return this->AddCUDAArchitectureFlagsImpl(compileOrLink, config, "CUDA",
+ std::move(arch), flags);
+}
+
+void cmGeneratorTarget::AddCUDAArchitectureFlagsImpl(cmBuildStep compileOrLink,
+ std::string const& config,
+ std::string const& lang,
+ std::string arch,
+ std::string& flags) const
+{
+ std::string const& compiler = this->Makefile->GetSafeDefinition(
+ cmStrCat("CMAKE_", lang, "_COMPILER_ID"));
+ const bool ipoEnabled = this->IsIPOEnabled(lang, config);
// Check for special modes: `all`, `all-major`.
- if (property == "all" || property == "all-major") {
+ if (arch == "all" || arch == "all-major") {
if (compiler == "NVIDIA" &&
- cmSystemTools::VersionCompare(
- cmSystemTools::OP_GREATER_EQUAL,
- this->Makefile->GetDefinition("CMAKE_CUDA_COMPILER_VERSION"),
- "11.5")) {
- flags = cmStrCat(flags, " -arch=", property);
+ cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL,
+ this->Makefile->GetDefinition(cmStrCat(
+ "CMAKE_", lang, "_COMPILER_VERSION")),
+ "11.5")) {
+ flags = cmStrCat(flags, " -arch=", arch);
return;
}
- if (property == "all") {
- property =
- *this->Makefile->GetDefinition("CMAKE_CUDA_ARCHITECTURES_ALL");
- } else if (property == "all-major") {
- property =
- *this->Makefile->GetDefinition("CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR");
+ if (arch == "all") {
+ arch = *this->Makefile->GetDefinition(
+ cmStrCat("CMAKE_", lang, "_ARCHITECTURES_ALL"));
+ } else if (arch == "all-major") {
+ arch = *this->Makefile->GetDefinition(
+ cmStrCat("CMAKE_", lang, "_ARCHITECTURES_ALL_MAJOR"));
}
- } else if (property == "native") {
- cmValue native =
- this->Makefile->GetDefinition("CMAKE_CUDA_ARCHITECTURES_NATIVE");
+ } else if (arch == "native") {
+ cmValue native = this->Makefile->GetDefinition(
+ cmStrCat("CMAKE_", lang, "_ARCHITECTURES_NATIVE"));
if (native.IsEmpty()) {
this->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
- "CUDA_ARCHITECTURES is set to \"native\", but no GPU was detected.");
+ cmStrCat(lang,
+ "_ARCHITECTURES is set to \"native\", but no NVIDIA GPU was "
+ "detected."));
}
if (compiler == "NVIDIA" &&
- cmSystemTools::VersionCompare(
- cmSystemTools::OP_GREATER_EQUAL,
- this->Makefile->GetDefinition("CMAKE_CUDA_COMPILER_VERSION"),
- "11.6")) {
- flags = cmStrCat(flags, " -arch=", property);
+ cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL,
+ this->Makefile->GetDefinition(cmStrCat(
+ "CMAKE_", lang, "_COMPILER_VERSION")),
+ "11.6")) {
+ flags = cmStrCat(flags, " -arch=", arch);
return;
}
- property = *native;
+ arch = *native;
}
struct CudaArchitecture
@@ -3467,7 +3479,7 @@ void cmGeneratorTarget::AddCUDAArchitectureFlags(cmBuildStep compileOrLink,
std::vector<CudaArchitecture> architectures;
{
- cmList options(property);
+ cmList options(arch);
for (auto& option : options) {
CudaArchitecture architecture;
@@ -3500,8 +3512,8 @@ void cmGeneratorTarget::AddCUDAArchitectureFlags(cmBuildStep compileOrLink,
if (compiler == "NVIDIA") {
if (ipoEnabled && compileOrLink == cmBuildStep::Link) {
- if (cmValue cudaIPOFlags =
- this->Makefile->GetDefinition("CMAKE_CUDA_LINK_OPTIONS_IPO")) {
+ if (cmValue cudaIPOFlags = this->Makefile->GetDefinition(
+ cmStrCat("CMAKE_", lang, "_LINK_OPTIONS_IPO"))) {
flags += *cudaIPOFlags;
}
}
@@ -3549,10 +3561,10 @@ void cmGeneratorTarget::AddCUDAArchitectureFlags(cmBuildStep compileOrLink,
void cmGeneratorTarget::AddISPCTargetFlags(std::string& flags) const
{
- const std::string& property = this->GetSafeProperty("ISPC_INSTRUCTION_SETS");
+ const std::string& arch = this->GetSafeProperty("ISPC_INSTRUCTION_SETS");
// If ISPC_TARGET is false we don't add any architectures.
- if (cmIsOff(property)) {
+ if (cmIsOff(arch)) {
return;
}
@@ -3560,7 +3572,7 @@ void cmGeneratorTarget::AddISPCTargetFlags(std::string& flags) const
this->Makefile->GetSafeDefinition("CMAKE_ISPC_COMPILER_ID");
if (compiler == "Intel") {
- cmList targets(property);
+ cmList targets(arch);
if (!targets.empty()) {
flags += cmStrCat(" --target=", cmWrap("", targets, "", ","));
}
@@ -3569,20 +3581,20 @@ void cmGeneratorTarget::AddISPCTargetFlags(std::string& flags) const
void cmGeneratorTarget::AddHIPArchitectureFlags(std::string& flags) const
{
- const std::string& property = this->GetSafeProperty("HIP_ARCHITECTURES");
+ const std::string& arch = this->GetSafeProperty("HIP_ARCHITECTURES");
- if (property.empty()) {
+ if (arch.empty()) {
this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"HIP_ARCHITECTURES is empty for target \"" +
this->GetName() + "\".");
}
// If HIP_ARCHITECTURES is false we don't add any architectures.
- if (cmIsOff(property)) {
+ if (cmIsOff(arch)) {
return;
}
- cmList options(property);
+ cmList options(arch);
for (std::string& option : options) {
flags += " --offload-arch=" + option;
diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h
index 7673bef..6a385ea 100644
--- a/Source/cmGeneratorTarget.h
+++ b/Source/cmGeneratorTarget.h
@@ -496,8 +496,12 @@ public:
cmSourceFile const& sf) const;
void AddCUDAArchitectureFlags(cmBuildStep compileOrLink,
- const std::string& config,
+ std::string const& config,
std::string& flags) const;
+ void AddCUDAArchitectureFlagsImpl(cmBuildStep compileOrLink,
+ std::string const& config,
+ std::string const& lang, std::string arch,
+ std::string& flags) const;
void AddCUDAToolkitFlags(std::string& flags) const;
void AddHIPArchitectureFlags(std::string& flags) const;