mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-19 21:50:39 -06:00
CUDA: Fix crash on linking to a CUDA target without CUDA enabled
Do not try to device link or add CUDA runtime libraries if the language is not enabled. Fixes: #18673 Issue: #18614
This commit is contained in:
@@ -84,6 +84,10 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
|
|||||||
bool relink)
|
bool relink)
|
||||||
{
|
{
|
||||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||||
|
if (!this->GlobalGenerator->GetLanguageEnabled("CUDA")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string cuda_lang("CUDA");
|
const std::string cuda_lang("CUDA");
|
||||||
cmGeneratorTarget::LinkClosure const* closure =
|
cmGeneratorTarget::LinkClosure const* closure =
|
||||||
this->GeneratorTarget->GetLinkClosure(this->ConfigName);
|
this->GeneratorTarget->GetLinkClosure(this->ConfigName);
|
||||||
|
|||||||
@@ -558,6 +558,10 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
|
|||||||
|
|
||||||
void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
|
void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
|
||||||
{
|
{
|
||||||
|
if (!this->GetGlobalGenerator()->GetLanguageEnabled("CUDA")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cmGeneratorTarget& genTarget = *this->GetGeneratorTarget();
|
cmGeneratorTarget& genTarget = *this->GetGeneratorTarget();
|
||||||
|
|
||||||
// determine if we need to do any device linking for this target
|
// determine if we need to do any device linking for this target
|
||||||
|
|||||||
@@ -3331,7 +3331,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
|
|||||||
std::vector<std::string> vsTargetVec;
|
std::vector<std::string> vsTargetVec;
|
||||||
this->AddLibraries(cli, libVec, vsTargetVec, config);
|
this->AddLibraries(cli, libVec, vsTargetVec, config);
|
||||||
if (std::find(linkClosure->Languages.begin(), linkClosure->Languages.end(),
|
if (std::find(linkClosure->Languages.begin(), linkClosure->Languages.end(),
|
||||||
"CUDA") != linkClosure->Languages.end()) {
|
"CUDA") != linkClosure->Languages.end() &&
|
||||||
|
this->CudaOptions[config] != nullptr) {
|
||||||
switch (this->CudaOptions[config]->GetCudaRuntime()) {
|
switch (this->CudaOptions[config]->GetCudaRuntime()) {
|
||||||
case cmVisualStudioGeneratorOptions::CudaRuntimeStatic:
|
case cmVisualStudioGeneratorOptions::CudaRuntimeStatic:
|
||||||
libVec.push_back("cudadevrt.lib");
|
libVec.push_back("cudadevrt.lib");
|
||||||
|
|||||||
8
Tests/RunCMake/Languages/ExternalCUDA.cmake
Normal file
8
Tests/RunCMake/Languages/ExternalCUDA.cmake
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
enable_language(C)
|
||||||
|
|
||||||
|
add_library(ext_cuda IMPORTED STATIC)
|
||||||
|
set_property(TARGET ext_cuda PROPERTY IMPORTED_LOCATION "/does_not_exist")
|
||||||
|
set_property(TARGET ext_cuda PROPERTY IMPORTED_LINK_INTERFACE_LANGUAGES "CUDA")
|
||||||
|
|
||||||
|
add_executable(main empty.c)
|
||||||
|
target_link_libraries(main ext_cuda)
|
||||||
@@ -6,3 +6,5 @@ run_cmake(link-libraries-TARGET_FILE-genex)
|
|||||||
run_cmake(link-libraries-TARGET_FILE-genex-ok)
|
run_cmake(link-libraries-TARGET_FILE-genex-ok)
|
||||||
|
|
||||||
run_cmake(DetermineFail)
|
run_cmake(DetermineFail)
|
||||||
|
|
||||||
|
run_cmake(ExternalCUDA)
|
||||||
|
|||||||
0
Tests/RunCMake/Languages/empty.c
Normal file
0
Tests/RunCMake/Languages/empty.c
Normal file
Reference in New Issue
Block a user