CMakeLists.txt 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. cmake_minimum_required(VERSION 3.7)
  2. project (CudaOnlyResolveDeviceSymbols CUDA)
  3. # Find nm and dumpbin
  4. if(CMAKE_NM)
  5. set(dump_command ${CMAKE_NM})
  6. set(dump_args -g)
  7. else()
  8. include(GetPrerequisites)
  9. message(STATUS "calling list_prerequisites to find dumpbin")
  10. list_prerequisites("${CMAKE_COMMAND}" 0 0 0)
  11. if(gp_dumpbin)
  12. set(dump_command ${gp_dumpbin})
  13. set(dump_args /ARCHIVEMEMBERS)
  14. endif()
  15. endif()
  16. #Goal for this example:
  17. # Build a static library that defines multiple methods and kernels that
  18. # use each other.
  19. # Resolve the device symbols into that static library
  20. # Verify that we can't use those device symbols from anything that links
  21. # to the static library
  22. string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_30,code=[compute_30] -gencode arch=compute_50,code=\\\"compute_50\\\"")
  23. set(CMAKE_CXX_STANDARD 11)
  24. set(CMAKE_CUDA_STANDARD 11)
  25. add_library(CUDAResolveDeviceLib STATIC file1.cu file2.cu)
  26. set_target_properties(CUDAResolveDeviceLib
  27. PROPERTIES
  28. CUDA_SEPARABLE_COMPILATION ON
  29. CUDA_RESOLVE_DEVICE_SYMBOLS ON
  30. POSITION_INDEPENDENT_CODE ON)
  31. if(dump_command)
  32. add_custom_command(TARGET CUDAResolveDeviceLib POST_BUILD
  33. COMMAND ${CMAKE_COMMAND}
  34. -DDUMP_COMMAND=${dump_command}
  35. -DDUMP_ARGS=${dump_args}
  36. -DTEST_LIBRARY_PATH=$<TARGET_FILE:CUDAResolveDeviceLib>
  37. -P ${CMAKE_CURRENT_SOURCE_DIR}/verify.cmake
  38. )
  39. endif()
  40. add_executable(CudaOnlyResolveDeviceSymbols main.cu)
  41. set_target_properties(CudaOnlyResolveDeviceSymbols
  42. PROPERTIES
  43. CUDA_SEPARABLE_COMPILATION ON)
  44. target_link_libraries(CudaOnlyResolveDeviceSymbols PRIVATE CUDAResolveDeviceLib)
  45. if(APPLE)
  46. # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
  47. set_property(TARGET CudaOnlyResolveDeviceSymbols PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
  48. endif()