From 62f13ed588da428699d84a7e61b6d33b3563a374 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Wed, 2 Nov 2022 12:13:41 -0400 Subject: FindCUDAToolkit: Restore usage from multiple directories Fixes #24119 --- Modules/FindCUDAToolkit.cmake | 6 ++++-- Tests/CudaOnly/CMakeLists.txt | 1 + Tests/CudaOnly/ToolkitMultipleDirs/CMakeLists.txt | 22 ++++++++++++++++++++++ Tests/CudaOnly/ToolkitMultipleDirs/main.cu | 8 ++++++++ .../ToolkitMultipleDirs/subdir/CMakeLists.txt | 2 ++ 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 Tests/CudaOnly/ToolkitMultipleDirs/CMakeLists.txt create mode 100644 Tests/CudaOnly/ToolkitMultipleDirs/main.cu create mode 100644 Tests/CudaOnly/ToolkitMultipleDirs/subdir/CMakeLists.txt diff --git a/Modules/FindCUDAToolkit.cmake b/Modules/FindCUDAToolkit.cmake index b019f0b..94c86e9 100644 --- a/Modules/FindCUDAToolkit.cmake +++ b/Modules/FindCUDAToolkit.cmake @@ -1058,8 +1058,10 @@ if(CUDAToolkit_FOUND) _CUDAToolkit_find_and_add_import_lib(nvrtc DEPS cuda_driver) if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.1.0) - _CUDAToolkit_find_and_add_import_lib(nvptxcompiler_static DEPS cuda_driver) - target_link_libraries(CUDA::nvptxcompiler_static INTERFACE Threads::Threads) + if(NOT TARGET CUDA::nvptxcompiler_static) + _CUDAToolkit_find_and_add_import_lib(nvptxcompiler_static DEPS cuda_driver) + target_link_libraries(CUDA::nvptxcompiler_static INTERFACE Threads::Threads) + endif() endif() _CUDAToolkit_find_and_add_import_lib(nvml ALT nvidia-ml nvml) diff --git a/Tests/CudaOnly/CMakeLists.txt b/Tests/CudaOnly/CMakeLists.txt index 091872d..39634ac 100644 --- a/Tests/CudaOnly/CMakeLists.txt +++ b/Tests/CudaOnly/CMakeLists.txt @@ -13,6 +13,7 @@ add_cuda_test_macro(CudaOnly.SharedRuntimePlusToolkit CudaOnlySharedRuntimePlusT add_cuda_test_macro(CudaOnly.Standard98 CudaOnlyStandard98) add_cuda_test_macro(CudaOnly.Toolkit CudaOnlyToolkit) add_cuda_test_macro(CudaOnly.ToolkitBeforeLang CudaOnlyToolkitBeforeLang) +add_cuda_test_macro(CudaOnly.ToolkitMultipleDirs CudaOnlyToolkitMultipleDirs) add_cuda_test_macro(CudaOnly.WithDefs CudaOnlyWithDefs) add_cuda_test_macro(CudaOnly.CircularLinkLine CudaOnlyCircularLinkLine) add_cuda_test_macro(CudaOnly.ResolveDeviceSymbols CudaOnlyResolveDeviceSymbols) diff --git a/Tests/CudaOnly/ToolkitMultipleDirs/CMakeLists.txt b/Tests/CudaOnly/ToolkitMultipleDirs/CMakeLists.txt new file mode 100644 index 0000000..9255149 --- /dev/null +++ b/Tests/CudaOnly/ToolkitMultipleDirs/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.15) +project(CudaOnlyToolkitMultipleDirs CUDA) + +find_package(CUDAToolkit REQUIRED) + +add_subdirectory(subdir) + +if(NOT DEFINED CUDAToolkit_VERSION) + message(FATAL_ERROR "expected CUDAToolkit variable CUDAToolkit_VERSION not found") +endif() + +message(STATUS "CUDAToolkit_VERSION: ${CUDAToolkit_VERSION}") +message(STATUS "CUDAToolkit_VERSION_MAJOR: ${CUDAToolkit_VERSION_MAJOR}") +message(STATUS "CUDAToolkit_VERSION_MINOR: ${CUDAToolkit_VERSION_MINOR}") +message(STATUS "CUDAToolkit_VERSION_PATCH: ${CUDAToolkit_VERSION_PATCH}") +message(STATUS "CUDAToolkit_BIN_DIR: ${CUDAToolkit_BIN_DIR}") +message(STATUS "CUDAToolkit_INCLUDE_DIRS: ${CUDAToolkit_INCLUDE_DIRS}") +message(STATUS "CUDAToolkit_LIBRARY_DIR: ${CUDAToolkit_LIBRARY_DIR}") +message(STATUS "CUDAToolkit_NVCC_EXECUTABLE ${CUDAToolkit_NVCC_EXECUTABLE}") + +add_executable(CudaOnlyToolkitMultipleDirs main.cu) +target_link_libraries(CudaOnlyToolkitMultipleDirs PRIVATE CUDA::toolkit) diff --git a/Tests/CudaOnly/ToolkitMultipleDirs/main.cu b/Tests/CudaOnly/ToolkitMultipleDirs/main.cu new file mode 100644 index 0000000..0f3ccdc --- /dev/null +++ b/Tests/CudaOnly/ToolkitMultipleDirs/main.cu @@ -0,0 +1,8 @@ +// Only thing we care about is that these headers are found +#include +#include + +int main(int argc, char** argv) +{ + return 0; +} diff --git a/Tests/CudaOnly/ToolkitMultipleDirs/subdir/CMakeLists.txt b/Tests/CudaOnly/ToolkitMultipleDirs/subdir/CMakeLists.txt new file mode 100644 index 0000000..f1f4b89 --- /dev/null +++ b/Tests/CudaOnly/ToolkitMultipleDirs/subdir/CMakeLists.txt @@ -0,0 +1,2 @@ + +find_package(CUDAToolkit REQUIRED) -- cgit v0.12