CMakeLists.txt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. cmake_minimum_required(VERSION 3.7)
  2. project (CudaOnlyWithDefs CUDA)
  3. #verify that we can pass explicit cuda arch flags
  4. string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_30,code=compute_30")
  5. if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 9)
  6. set(debug_compile_flags --generate-code arch=compute_32,code=sm_32)
  7. else()
  8. set(debug_compile_flags --generate-code arch=compute_20,code=sm_20)
  9. endif()
  10. if(CMAKE_CUDA_SIMULATE_ID STREQUAL "MSVC")
  11. list(APPEND debug_compile_flags -Xcompiler=-WX)
  12. else()
  13. list(APPEND debug_compile_flags -Xcompiler=-Werror)
  14. endif()
  15. set(release_compile_defs DEFREL)
  16. #Goal for this example:
  17. #build a executable that needs to be passed a complex define through add_defintions
  18. #this verifies we can pass things such as '_','(' to nvcc
  19. add_definitions("-DPACKED_DEFINE=__attribute__((packed))")
  20. add_executable(CudaOnlyWithDefs main.notcu)
  21. set_source_files_properties(main.notcu PROPERTIES LANGUAGE CUDA)
  22. target_compile_options(CudaOnlyWithDefs
  23. PRIVATE
  24. -DFLAG_COMPILE_LANG_$<COMPILE_LANGUAGE>
  25. -DFLAG_LANG_IS_CUDA=$<COMPILE_LANGUAGE:CUDA>
  26. -Xcompiler=-DHOST_DEFINE
  27. $<$<CONFIG:DEBUG>:$<BUILD_INTERFACE:${debug_compile_flags}>>
  28. )
  29. target_compile_definitions(CudaOnlyWithDefs
  30. PRIVATE
  31. $<$<CONFIG:RELEASE>:$<BUILD_INTERFACE:${release_compile_defs}>>
  32. -DDEF_COMPILE_LANG_$<COMPILE_LANGUAGE>
  33. -DDEF_LANG_IS_CUDA=$<COMPILE_LANGUAGE:CUDA>
  34. )
  35. target_include_directories(CudaOnlyWithDefs
  36. PRIVATE
  37. $<$<COMPILE_LANGUAGE:CUDA>:${CMAKE_CURRENT_SOURCE_DIR}/inc_cuda>
  38. )
  39. if(APPLE)
  40. # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
  41. set_property(TARGET CudaOnlyWithDefs PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
  42. endif()