NVIDIA-CUDA.cmake 5.75 KB
Newer Older
1
2
include(Compiler/CMakeCommonCompilerMacros)

3
set(CMAKE_CUDA_COMPILER_HAS_DEVICE_LINK_PHASE True)
4
set(CMAKE_CUDA_VERBOSE_FLAG "-v")
5
set(CMAKE_CUDA_VERBOSE_COMPILE_FLAG "-Xcompiler=-v")
6

7
set(_CMAKE_COMPILE_AS_CUDA_FLAG "-x cu")
8
set(_CMAKE_CUDA_PTX_FLAG "-ptx")
9
set(_CMAKE_CUDA_DEVICE_CODE "-dc")
10

11
if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  # The -forward-unknown-to-host-compiler flag was only
  # added to nvcc in 10.2 so before that we had no good
  # way to invoke the CUDA compiler and propagate unknown
  # flags such as -pthread to the host compiler
  set(_CMAKE_CUDA_EXTRA_FLAGS "-forward-unknown-to-host-compiler")
else()
  set(_CMAKE_CUDA_EXTRA_FLAGS "")
endif()

if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0.0")
  set(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS "-Wno-deprecated-gpu-targets")
else()
  set(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS "")
endif()

27
if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2.89)
28
29
30
  # The -MD flag was only added to nvcc in 10.2 so
  # before that we had to invoke the compiler twice
  # to get header dependency information
31
  set(CMAKE_DEPFILE_FLAGS_CUDA "-MD -MT <DEP_TARGET> -MF <DEP_FILE>")
32
else()
33
34
35
36
37
38
39
40
41
  if(CMAKE_CUDA_HOST_COMPILER AND NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
    # FIXME: Move the main -ccbin= flag from CMakeCUDAInformation to
    # a block above, remove this copy, and update the VS generator too.
    set(_CMAKE_CUDA_EXTRA_FLAGS_LOCAL " -ccbin=<CMAKE_CUDA_HOST_COMPILER>")
  else()
    set(_CMAKE_CUDA_EXTRA_FLAGS_LOCAL "")
  endif()
  set(CMAKE_CUDA_DEPENDS_EXTRA_COMMANDS "<CMAKE_CUDA_COMPILER> ${_CMAKE_CUDA_EXTRA_FLAGS}${_CMAKE_CUDA_EXTRA_FLAGS_LOCAL} <DEFINES> <INCLUDES> <FLAGS> ${_CMAKE_COMPILE_AS_CUDA_FLAG} -M <SOURCE> -MT <OBJECT> -o <DEP_FILE>")
  unset(_CMAKE_CUDA_EXTRA_FLAGS_LOCAL)
42
endif()
43
set(CMAKE_CUDA_DEPFILE_FORMAT gcc)
44
45
46
47
if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER)
    AND CMAKE_GENERATOR MATCHES "Makefiles|WMake")
  set(CMAKE_CUDA_DEPENDS_USE_COMPILER TRUE)
endif()
48

49
50
51
52
53
54
55
if(NOT "x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC")
  set(CMAKE_CUDA_COMPILE_OPTIONS_PIE -Xcompiler=-fPIE)
  set(CMAKE_CUDA_COMPILE_OPTIONS_PIC -Xcompiler=-fPIC)
  set(CMAKE_CUDA_COMPILE_OPTIONS_VISIBILITY -Xcompiler=-fvisibility=)
  # CMAKE_SHARED_LIBRARY_CUDA_FLAGS is sent to the host linker so we
  # don't need to forward it through nvcc.
  set(CMAKE_SHARED_LIBRARY_CUDA_FLAGS -fPIC)
56
57
58
59
60
  string(APPEND CMAKE_CUDA_FLAGS_INIT " ")
  string(APPEND CMAKE_CUDA_FLAGS_DEBUG_INIT " -g")
  string(APPEND CMAKE_CUDA_FLAGS_RELEASE_INIT " -O3 -DNDEBUG")
  string(APPEND CMAKE_CUDA_FLAGS_MINSIZEREL_INIT " -O1 -DNDEBUG")
  string(APPEND CMAKE_CUDA_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG")
61
endif()
62
63
64
set(CMAKE_SHARED_LIBRARY_CREATE_CUDA_FLAGS -shared)
set(CMAKE_INCLUDE_SYSTEM_FLAG_CUDA -isystem=)

65
66
67
68
69
70
71
72
if (CMAKE_CUDA_SIMULATE_ID STREQUAL "GNU")
  set(CMAKE_CUDA_LINKER_WRAPPER_FLAG "-Wl,")
  set(CMAKE_CUDA_LINKER_WRAPPER_FLAG_SEP ",")
elseif(CMAKE_CUDA_SIMULATE_ID STREQUAL "Clang")
  set(CMAKE_CUDA_LINKER_WRAPPER_FLAG "-Xlinker" " ")
  set(CMAKE_CUDA_LINKER_WRAPPER_FLAG_SEP)
endif()

73
74
75
76
77
set(CMAKE_CUDA_DEVICE_COMPILER_WRAPPER_FLAG "-Xcompiler=")
set(CMAKE_CUDA_DEVICE_COMPILER_WRAPPER_FLAG_SEP ",")
set(CMAKE_CUDA_DEVICE_LINKER_WRAPPER_FLAG "-Xlinker=")
set(CMAKE_CUDA_DEVICE_LINKER_WRAPPER_FLAG_SEP ",")

78
79
80
81
set(CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC  "cudadevrt;cudart_static")
set(CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_SHARED  "cudadevrt;cudart")
set(CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_NONE    "")

Jan Bernlöhr's avatar
Jan Bernlöhr committed
82
if(UNIX AND NOT (CMAKE_SYSTEM_NAME STREQUAL "QNX"))
83
84
85
  list(APPEND CMAKE_CUDA_RUNTIME_LIBRARY_LINK_OPTIONS_STATIC "rt" "pthread" "dl")
endif()

86
if("x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC")
87
  # MSVC requires c++14 as the minimum level
88
89
90
  set(CMAKE_CUDA03_STANDARD_COMPILE_OPTION "")
  set(CMAKE_CUDA03_EXTENSION_COMPILE_OPTION "")

91
  # MSVC requires c++14 as the minimum level
92
93
94
95
  set(CMAKE_CUDA11_STANDARD_COMPILE_OPTION "")
  set(CMAKE_CUDA11_EXTENSION_COMPILE_OPTION "")

  if (NOT CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 9.0)
96
97
98
99
100
101
102
    if(CMAKE_CUDA_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.10.25017)
      set(CMAKE_CUDA14_STANDARD_COMPILE_OPTION "-std=c++14")
      set(CMAKE_CUDA14_EXTENSION_COMPILE_OPTION "-std=c++14")
    else()
      set(CMAKE_CUDA14_STANDARD_COMPILE_OPTION "")
      set(CMAKE_CUDA14_EXTENSION_COMPILE_OPTION "")
    endif()
103
  endif()
104
105

  if (NOT CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 11.0)
106
107
108
109
    if(CMAKE_CUDA_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.11.25505)
      set(CMAKE_CUDA17_STANDARD_COMPILE_OPTION "-std=c++17")
      set(CMAKE_CUDA17_EXTENSION_COMPILE_OPTION "-std=c++17")
    endif()
110
111
  endif()

112
else()
113
114
115
  set(CMAKE_CUDA03_STANDARD_COMPILE_OPTION "")
  set(CMAKE_CUDA03_EXTENSION_COMPILE_OPTION "")

116
117
  set(CMAKE_CUDA11_STANDARD_COMPILE_OPTION "-std=c++11")
  set(CMAKE_CUDA11_EXTENSION_COMPILE_OPTION "-std=c++11")
118
119

  if (NOT CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 9.0)
120
121
    set(CMAKE_CUDA03_STANDARD_COMPILE_OPTION "-std=c++03")
    set(CMAKE_CUDA03_EXTENSION_COMPILE_OPTION "-std=c++03")
122
123
124
125
    set(CMAKE_CUDA14_STANDARD_COMPILE_OPTION "-std=c++14")
    set(CMAKE_CUDA14_EXTENSION_COMPILE_OPTION "-std=c++14")
  endif()

126
127
128
129
130
  if (NOT CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 11.0)
    set(CMAKE_CUDA17_STANDARD_COMPILE_OPTION "-std=c++17")
    set(CMAKE_CUDA17_EXTENSION_COMPILE_OPTION "-std=c++17")
  endif()

131
endif()
132
133
134
135
136
137

# FIXME: investigate use of --options-file.
# Tell Makefile generator that nvcc does not support @<rspfile> syntax.
set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_INCLUDES 0)
set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_OBJECTS 0)
138
139

if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "9.0")
140
  set(CMAKE_CUDA_RESPONSE_FILE_DEVICE_LINK_FLAG "--options-file ")
141
142
  set(CMAKE_CUDA_RESPONSE_FILE_FLAG "--options-file ")
endif()
143
144

__compiler_check_default_language_standard(CUDA 6.0 03)