CMakeLists.txt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. cmake_minimum_required(VERSION 3.7)
  2. project (CudaComplex CXX CUDA)
  3. #Goal for this example:
  4. #build a cpp dynamic library base
  5. #build a cuda static library base that uses separable compilation
  6. #build a cuda dynamic library that uses the first dynamic library
  7. #build a mixed cpp & cuda dynamic library uses all 3 previous libraries
  8. #lastly build a cpp executable that uses this last cuda dynamic library
  9. #this tests that we can properly handle linking cuda and cpp together
  10. #and also building cpp targets that need cuda implicit libraries
  11. #verify that we can pass explicit cuda arch flags
  12. string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_30,code=compute_30")
  13. set(CMAKE_CUDA_STANDARD 11)
  14. set(CMAKE_CXX_STANDARD 11)
  15. set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
  16. set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
  17. add_library(CudaComplexCppBase SHARED dynamic.cpp)
  18. add_library(CudaComplexSeperableLib STATIC file1.cu file2.cu file3.cu)
  19. set_target_properties(CudaComplexSeperableLib
  20. PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
  21. set_target_properties( CudaComplexSeperableLib
  22. PROPERTIES POSITION_INDEPENDENT_CODE ON)
  23. add_library(CudaComplexSharedLib SHARED dynamic.cu)
  24. target_link_libraries(CudaComplexSharedLib PUBLIC CudaComplexCppBase)
  25. add_library(CudaComplexMixedLib SHARED mixed.cpp mixed.cu)
  26. set_target_properties(CudaComplexMixedLib
  27. PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
  28. target_link_libraries(CudaComplexMixedLib
  29. PUBLIC CudaComplexSharedLib
  30. PRIVATE CudaComplexSeperableLib)
  31. add_executable(CudaComplex main.cpp)
  32. target_link_libraries(CudaComplex PUBLIC CudaComplexMixedLib)
  33. if(APPLE)
  34. # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
  35. set_property(TARGET CudaComplex PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
  36. endif()