1 cmake_minimum_required(VERSION 3.18)
2 project(Complex CXX CUDA)
3 #Goal for this example:
5 #build a cpp dynamic library base
6 #build a cuda static library base that uses separable compilation
8 #build a cuda dynamic library that uses the first dynamic library
9 #build a mixed cpp & cuda dynamic library uses all 3 previous libraries
11 #lastly build a cpp executable that uses this last cuda dynamic library
13 #this tests that we can properly handle linking cuda and cpp together
14 #and also building cpp targets that need cuda implicit libraries
16 set(CMAKE_CUDA_STANDARD 11)
17 set(CMAKE_CXX_STANDARD 11)
18 set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
19 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
21 add_library(CudaComplexCppBase SHARED dynamic.cpp)
22 add_library(CudaComplexSharedLib SHARED dynamic.cu)
23 target_link_libraries(CudaComplexSharedLib PUBLIC CudaComplexCppBase)
25 add_library(CudaComplexSeperableLib STATIC file1.cu file2.cu file3.cu)
26 add_library(CudaComplexMixedLib SHARED mixed.cpp mixed.cu)
27 target_link_libraries(CudaComplexMixedLib
28 PUBLIC CudaComplexSharedLib
29 PRIVATE CudaComplexSeperableLib)
31 add_executable(CudaComplex main.cpp)
32 target_link_libraries(CudaComplex PUBLIC CudaComplexMixedLib)
35 set_target_properties(CudaComplexMixedLib
36 CudaComplexSeperableLib
38 POSITION_INDEPENDENT_CODE ON
39 CUDA_SEPARABLE_COMPILATION ON
41 set_target_properties(CudaComplexMixedLib
44 CUDA_RUNTIME_LIBRARY shared
49 # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
50 set_property(TARGET CudaComplex PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
54 # Help the shared cuda runtime find libcudart as it is not located
55 # in a default system searched location
56 find_package(CUDAToolkit REQUIRED)
57 set_property(TARGET CudaComplexMixedLib PROPERTY BUILD_RPATH "${CUDAToolkit_LIBRARY_DIR}")