mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 13:51:33 -06:00
Merge topic 'cuda-no-device-link-when-disabled'
a4d502a5bf CUDA: Do not device link if CUDA is not an enabled language
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3491
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "cmAlgorithms.h"
|
||||
#include "cmComputeLinkInformation.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmGlobalGenerator.h"
|
||||
#include "cmLocalGenerator.h"
|
||||
#include "cmStateDirectory.h"
|
||||
#include "cmStateSnapshot.h"
|
||||
@@ -142,6 +143,9 @@ std::string cmLinkLineDeviceComputer::GetLinkerLanguage(cmGeneratorTarget*,
|
||||
bool requireDeviceLinking(cmGeneratorTarget& target, cmLocalGenerator& lg,
|
||||
const std::string& config)
|
||||
{
|
||||
if (!target.GetGlobalGenerator()->GetLanguageEnabled("CUDA")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target.GetType() == cmStateEnums::OBJECT_LIBRARY) {
|
||||
return false;
|
||||
|
||||
@@ -82,11 +82,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
|
||||
bool relink)
|
||||
{
|
||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||
if (!this->GlobalGenerator->GetLanguageEnabled("CUDA")) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool requiresDeviceLinking = requireDeviceLinking(
|
||||
const bool requiresDeviceLinking = requireDeviceLinking(
|
||||
*this->GeneratorTarget, *this->LocalGenerator, this->ConfigName);
|
||||
if (!requiresDeviceLinking) {
|
||||
return;
|
||||
|
||||
@@ -123,8 +123,7 @@ void cmMakefileLibraryTargetGenerator::WriteObjectLibraryRules()
|
||||
|
||||
void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
|
||||
{
|
||||
|
||||
bool requiresDeviceLinking = requireDeviceLinking(
|
||||
const bool requiresDeviceLinking = requireDeviceLinking(
|
||||
*this->GeneratorTarget, *this->LocalGenerator, this->ConfigName);
|
||||
if (requiresDeviceLinking) {
|
||||
std::string linkRuleVar = "CMAKE_CUDA_DEVICE_LINK_LIBRARY";
|
||||
@@ -152,7 +151,7 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
|
||||
}
|
||||
|
||||
if (!relink) {
|
||||
bool requiresDeviceLinking = requireDeviceLinking(
|
||||
const bool requiresDeviceLinking = requireDeviceLinking(
|
||||
*this->GeneratorTarget, *this->LocalGenerator, this->ConfigName);
|
||||
if (requiresDeviceLinking) {
|
||||
std::string linkRuleVar = "CMAKE_CUDA_DEVICE_LINK_LIBRARY";
|
||||
@@ -186,9 +185,8 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
|
||||
|
||||
void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
|
||||
{
|
||||
|
||||
if (!relink) {
|
||||
bool requiresDeviceLinking = requireDeviceLinking(
|
||||
const bool requiresDeviceLinking = requireDeviceLinking(
|
||||
*this->GeneratorTarget, *this->LocalGenerator, this->ConfigName);
|
||||
if (requiresDeviceLinking) {
|
||||
std::string linkRuleVar = "CMAKE_CUDA_DEVICE_LINK_LIBRARY";
|
||||
|
||||
@@ -3064,7 +3064,7 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions(
|
||||
Options& cudaLinkOptions = *pOptions;
|
||||
|
||||
// Determine if we need to do a device link
|
||||
bool doDeviceLinking = requireDeviceLinking(
|
||||
const bool doDeviceLinking = requireDeviceLinking(
|
||||
*this->GeneratorTarget, *this->LocalGenerator, configName);
|
||||
|
||||
cudaLinkOptions.AddFlag("PerformDeviceLink",
|
||||
|
||||
@@ -3,6 +3,7 @@ ADD_TEST_MACRO(Cuda.Complex CudaComplex)
|
||||
ADD_TEST_MACRO(Cuda.ConsumeCompileFeatures CudaConsumeCompileFeatures)
|
||||
ADD_TEST_MACRO(Cuda.ObjectLibrary CudaObjectLibrary)
|
||||
ADD_TEST_MACRO(Cuda.MixedStandardLevels MixedStandardLevels)
|
||||
ADD_TEST_MACRO(Cuda.NotEnabled CudaNotEnabled)
|
||||
ADD_TEST_MACRO(Cuda.ToolkitInclude CudaToolkitInclude)
|
||||
ADD_TEST_MACRO(Cuda.ProperDeviceLibraries ProperDeviceLibraries)
|
||||
ADD_TEST_MACRO(Cuda.ProperLinkFlags ProperLinkFlags)
|
||||
|
||||
14
Tests/Cuda/NotEnabled/CMakeLists.txt
Normal file
14
Tests/Cuda/NotEnabled/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
project(CudaNotEnabled CXX)
|
||||
|
||||
add_library(HasCudaProps lib.cxx)
|
||||
|
||||
target_compile_features(HasCudaProps PUBLIC cxx_std_11)
|
||||
#Verify that setting this variables in a project that doesn't have CUDA
|
||||
#enabled allow for the project to configure and build correctly.
|
||||
#Tests the fix for #19432
|
||||
set_property(TARGET HasCudaProps PROPERTY CUDA_SEPARABLE_COMPILATION ON)
|
||||
set_property(TARGET HasCudaProps PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON)
|
||||
|
||||
add_executable(CudaNotEnabled main.cxx)
|
||||
target_link_libraries(CudaNotEnabled PRIVATE HasCudaProps)
|
||||
5
Tests/Cuda/NotEnabled/lib.cxx
Normal file
5
Tests/Cuda/NotEnabled/lib.cxx
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
int cxx_function(int input)
|
||||
{
|
||||
return input;
|
||||
}
|
||||
9
Tests/Cuda/NotEnabled/main.cxx
Normal file
9
Tests/Cuda/NotEnabled/main.cxx
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// make sure we have c++11 enabled
|
||||
using returnv = std::integral_constant<int, 0>;
|
||||
return returnv::value;
|
||||
}
|
||||
Reference in New Issue
Block a user