summaryrefslogtreecommitdiffstats
path: root/Tests/Cuda
diff options
context:
space:
mode:
authorRobert Maynard <rmaynard@nvidia.com>2023-07-17 21:44:26 (GMT)
committerBrad King <brad.king@kitware.com>2023-07-18 17:21:01 (GMT)
commit7351d590ee6a846ed0f2bd4793384a33bf49ea0d (patch)
tree35ade287824ea6c02e450f3e215eaa67364e8338 /Tests/Cuda
parent83574a47726b8824d58b65a262c289573fb69bb0 (diff)
downloadCMake-7351d590ee6a846ed0f2bd4793384a33bf49ea0d.zip
CMake-7351d590ee6a846ed0f2bd4793384a33bf49ea0d.tar.gz
CMake-7351d590ee6a846ed0f2bd4793384a33bf49ea0d.tar.bz2
cmTarget: Add a way to represent imported shared library stubs
Shared library stubs can be used for linking, but not at runtime. Their role is similar to import libraries on Windows, so represent their location with the `IMPORTED_IMPLIB` target property. Fixes: #24940
Diffstat (limited to 'Tests/Cuda')
-rw-r--r--Tests/Cuda/CMakeLists.txt1
-rw-r--r--Tests/Cuda/StubRPATH/CMakeLists.txt21
-rw-r--r--Tests/Cuda/StubRPATH/main.cxx17
3 files changed, 39 insertions, 0 deletions
diff --git a/Tests/Cuda/CMakeLists.txt b/Tests/Cuda/CMakeLists.txt
index 0041b07..c737bcc 100644
--- a/Tests/Cuda/CMakeLists.txt
+++ b/Tests/Cuda/CMakeLists.txt
@@ -13,6 +13,7 @@ add_cuda_test_macro(Cuda.MixedStandardLevels4 MixedStandardLevels4)
add_cuda_test_macro(Cuda.MixedStandardLevels5 MixedStandardLevels5)
add_cuda_test_macro(Cuda.NotEnabled CudaNotEnabled)
add_cuda_test_macro(Cuda.SeparableCompCXXOnly SeparableCompCXXOnly)
+add_cuda_test_macro(Cuda.StubRPATH StubRPATH)
add_cuda_test_macro(Cuda.Toolkit Toolkit)
add_cuda_test_macro(Cuda.IncludePathNoToolkit IncludePathNoToolkit)
add_cuda_test_macro(Cuda.SharedRuntimePlusToolkit SharedRuntimePlusToolkit)
diff --git a/Tests/Cuda/StubRPATH/CMakeLists.txt b/Tests/Cuda/StubRPATH/CMakeLists.txt
new file mode 100644
index 0000000..93643c5
--- /dev/null
+++ b/Tests/Cuda/StubRPATH/CMakeLists.txt
@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 3.18)
+project(StubRPATH CXX)
+
+#Verify that linking to a stub library doesn't cause an `-rpath` entry
+
+# Needed for `CUDAToolkit_LIBRARY_SEARCH_DIRS`
+find_package(CUDAToolkit REQUIRED)
+
+find_library(CUDA_DRIVER_STUB_LIBRARY
+ NAMES cuda
+ HINTS ${CUDAToolkit_LIBRARY_SEARCH_DIRS}
+ ENV CUDA_PATH
+ PATH_SUFFIXES lib64/stubs lib/x64/stubs lib/stubs stubs
+)
+add_library(imported_stub IMPORTED SHARED)
+set_target_properties(imported_stub PROPERTIES IMPORTED_IMPLIB "${CUDA_DRIVER_STUB_LIBRARY}")
+set_target_properties(imported_stub PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CUDAToolkit_INCLUDE_DIRS}")
+
+set(CMAKE_CXX_STANDARD 11)
+add_executable(StubRPATH main.cxx)
+target_link_libraries(StubRPATH PRIVATE imported_stub)
diff --git a/Tests/Cuda/StubRPATH/main.cxx b/Tests/Cuda/StubRPATH/main.cxx
new file mode 100644
index 0000000..877856e
--- /dev/null
+++ b/Tests/Cuda/StubRPATH/main.cxx
@@ -0,0 +1,17 @@
+
+#include <iostream>
+
+#include <cuda.h>
+
+int main(int argc, char** argv)
+{
+ int nDevices = 0;
+ cuInit(0);
+ auto err = cuDeviceGetCount(&nDevices);
+ if (err != CUDA_SUCCESS) {
+ std::cerr << "Failed to retrieve the number of CUDA enabled devices "
+ << err << std::endl;
+ return 1;
+ }
+ return 0;
+}