~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/cmake/FindCUDA.cmake

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#.rst:
 
2
# FindCUDA
 
3
# --------
 
4
#
 
5
# Tools for building CUDA C files: libraries and build dependencies.
 
6
#
 
7
# This script locates the NVIDIA CUDA C tools.  It should work on linux,
 
8
# windows, and mac and should be reasonably up to date with CUDA C
 
9
# releases.
 
10
#
 
11
# This script makes use of the standard find_package arguments of
 
12
# <VERSION>, REQUIRED and QUIET.  CUDA_FOUND will report if an
 
13
# acceptable version of CUDA was found.
 
14
#
 
15
# The script will prompt the user to specify CUDA_TOOLKIT_ROOT_DIR if
 
16
# the prefix cannot be determined by the location of nvcc in the system
 
17
# path and REQUIRED is specified to find_package().  To use a different
 
18
# installed version of the toolkit set the environment variable
 
19
# CUDA_BIN_PATH before running cmake (e.g.
 
20
# CUDA_BIN_PATH=/usr/local/cuda1.0 instead of the default
 
21
# /usr/local/cuda) or set CUDA_TOOLKIT_ROOT_DIR after configuring.  If
 
22
# you change the value of CUDA_TOOLKIT_ROOT_DIR, various components that
 
23
# depend on the path will be relocated.
 
24
#
 
25
# It might be necessary to set CUDA_TOOLKIT_ROOT_DIR manually on certain
 
26
# platforms, or to use a cuda runtime not installed in the default
 
27
# location.  In newer versions of the toolkit the cuda library is
 
28
# included with the graphics driver- be sure that the driver version
 
29
# matches what is needed by the cuda runtime version.
 
30
#
 
31
# The following variables affect the behavior of the macros in the
 
32
# script (in alphebetical order).  Note that any of these flags can be
 
33
# changed multiple times in the same directory before calling
 
34
# CUDA_ADD_EXECUTABLE, CUDA_ADD_LIBRARY, CUDA_COMPILE, CUDA_COMPILE_PTX,
 
35
# CUDA_COMPILE_FATBIN, CUDA_COMPILE_CUBIN or CUDA_WRAP_SRCS::
 
36
#
 
37
#   CUDA_64_BIT_DEVICE_CODE (Default matches host bit size)
 
38
#   -- Set to ON to compile for 64 bit device code, OFF for 32 bit device code.
 
39
#      Note that making this different from the host code when generating object
 
40
#      or C files from CUDA code just won't work, because size_t gets defined by
 
41
#      nvcc in the generated source.  If you compile to PTX and then load the
 
42
#      file yourself, you can mix bit sizes between device and host.
 
43
#
 
44
#   CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE (Default ON)
 
45
#   -- Set to ON if you want the custom build rule to be attached to the source
 
46
#      file in Visual Studio.  Turn OFF if you add the same cuda file to multiple
 
47
#      targets.
 
48
#
 
49
#      This allows the user to build the target from the CUDA file; however, bad
 
50
#      things can happen if the CUDA source file is added to multiple targets.
 
51
#      When performing parallel builds it is possible for the custom build
 
52
#      command to be run more than once and in parallel causing cryptic build
 
53
#      errors.  VS runs the rules for every source file in the target, and a
 
54
#      source can have only one rule no matter how many projects it is added to.
 
55
#      When the rule is run from multiple targets race conditions can occur on
 
56
#      the generated file.  Eventually everything will get built, but if the user
 
57
#      is unaware of this behavior, there may be confusion.  It would be nice if
 
58
#      this script could detect the reuse of source files across multiple targets
 
59
#      and turn the option off for the user, but no good solution could be found.
 
60
#
 
61
#   CUDA_BUILD_CUBIN (Default OFF)
 
62
#   -- Set to ON to enable and extra compilation pass with the -cubin option in
 
63
#      Device mode. The output is parsed and register, shared memory usage is
 
64
#      printed during build.
 
65
#
 
66
#   CUDA_BUILD_EMULATION (Default OFF for device mode)
 
67
#   -- Set to ON for Emulation mode. -D_DEVICEEMU is defined for CUDA C files
 
68
#      when CUDA_BUILD_EMULATION is TRUE.
 
69
#
 
70
#   CUDA_GENERATED_OUTPUT_DIR (Default CMAKE_CURRENT_BINARY_DIR)
 
71
#   -- Set to the path you wish to have the generated files placed.  If it is
 
72
#      blank output files will be placed in CMAKE_CURRENT_BINARY_DIR.
 
73
#      Intermediate files will always be placed in
 
74
#      CMAKE_CURRENT_BINARY_DIR/CMakeFiles.
 
75
#
 
76
#   CUDA_HOST_COMPILATION_CPP (Default ON)
 
77
#   -- Set to OFF for C compilation of host code.
 
78
#
 
79
#   CUDA_HOST_COMPILER (Default CMAKE_C_COMPILER, $(VCInstallDir)/bin for VS)
 
80
#   -- Set the host compiler to be used by nvcc.  Ignored if -ccbin or
 
81
#      --compiler-bindir is already present in the CUDA_NVCC_FLAGS or
 
82
#      CUDA_NVCC_FLAGS_<CONFIG> variables.  For Visual Studio targets
 
83
#      $(VCInstallDir)/bin is a special value that expands out to the path when
 
84
#      the command is run from withing VS.
 
85
#
 
86
#   CUDA_NVCC_FLAGS
 
87
#   CUDA_NVCC_FLAGS_<CONFIG>
 
88
#   -- Additional NVCC command line arguments.  NOTE: multiple arguments must be
 
89
#      semi-colon delimited (e.g. --compiler-options;-Wall)
 
90
#
 
91
#   CUDA_PROPAGATE_HOST_FLAGS (Default ON)
 
92
#   -- Set to ON to propagate CMAKE_{C,CXX}_FLAGS and their configuration
 
93
#      dependent counterparts (e.g. CMAKE_C_FLAGS_DEBUG) automatically to the
 
94
#      host compiler through nvcc's -Xcompiler flag.  This helps make the
 
95
#      generated host code match the rest of the system better.  Sometimes
 
96
#      certain flags give nvcc problems, and this will help you turn the flag
 
97
#      propagation off.  This does not affect the flags supplied directly to nvcc
 
98
#      via CUDA_NVCC_FLAGS or through the OPTION flags specified through
 
99
#      CUDA_ADD_LIBRARY, CUDA_ADD_EXECUTABLE, or CUDA_WRAP_SRCS.  Flags used for
 
100
#      shared library compilation are not affected by this flag.
 
101
#
 
102
#   CUDA_SEPARABLE_COMPILATION (Default OFF)
 
103
#   -- If set this will enable separable compilation for all CUDA runtime object
 
104
#      files.  If used outside of CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY
 
105
#      (e.g. calling CUDA_WRAP_SRCS directly),
 
106
#      CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME and
 
107
#      CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS should be called.
 
108
#
 
109
#   CUDA_VERBOSE_BUILD (Default OFF)
 
110
#   -- Set to ON to see all the commands used when building the CUDA file.  When
 
111
#      using a Makefile generator the value defaults to VERBOSE (run make
 
112
#      VERBOSE=1 to see output), although setting CUDA_VERBOSE_BUILD to ON will
 
113
#      always print the output.
 
114
#
 
115
# The script creates the following macros (in alphebetical order)::
 
116
#
 
117
#   CUDA_ADD_CUFFT_TO_TARGET( cuda_target )
 
118
#   -- Adds the cufft library to the target (can be any target).  Handles whether
 
119
#      you are in emulation mode or not.
 
120
#
 
121
#   CUDA_ADD_CUBLAS_TO_TARGET( cuda_target )
 
122
#   -- Adds the cublas library to the target (can be any target).  Handles
 
123
#      whether you are in emulation mode or not.
 
124
#
 
125
#   CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ...
 
126
#                        [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] [OPTIONS ...] )
 
127
#   -- Creates an executable "cuda_target" which is made up of the files
 
128
#      specified.  All of the non CUDA C files are compiled using the standard
 
129
#      build rules specified by CMAKE and the cuda files are compiled to object
 
130
#      files using nvcc and the host compiler.  In addition CUDA_INCLUDE_DIRS is
 
131
#      added automatically to include_directories().  Some standard CMake target
 
132
#      calls can be used on the target after calling this macro
 
133
#      (e.g. set_target_properties and target_link_libraries), but setting
 
134
#      properties that adjust compilation flags will not affect code compiled by
 
135
#      nvcc.  Such flags should be modified before calling CUDA_ADD_EXECUTABLE,
 
136
#      CUDA_ADD_LIBRARY or CUDA_WRAP_SRCS.
 
137
#
 
138
#   CUDA_ADD_LIBRARY( cuda_target file0 file1 ...
 
139
#                     [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] [OPTIONS ...] )
 
140
#   -- Same as CUDA_ADD_EXECUTABLE except that a library is created.
 
141
#
 
142
#   CUDA_BUILD_CLEAN_TARGET()
 
143
#   -- Creates a convience target that deletes all the dependency files
 
144
#      generated.  You should make clean after running this target to ensure the
 
145
#      dependency files get regenerated.
 
146
#
 
147
#   CUDA_COMPILE( generated_files file0 file1 ... [STATIC | SHARED | MODULE]
 
148
#                 [OPTIONS ...] )
 
149
#   -- Returns a list of generated files from the input source files to be used
 
150
#      with ADD_LIBRARY or ADD_EXECUTABLE.
 
151
#
 
152
#   CUDA_COMPILE_PTX( generated_files file0 file1 ... [OPTIONS ...] )
 
153
#   -- Returns a list of PTX files generated from the input source files.
 
154
#
 
155
#   CUDA_COMPILE_FATBIN( generated_files file0 file1 ... [OPTIONS ...] )
 
156
#   -- Returns a list of FATBIN files generated from the input source files.
 
157
#
 
158
#   CUDA_COMPILE_CUBIN( generated_files file0 file1 ... [OPTIONS ...] )
 
159
#   -- Returns a list of CUBIN files generated from the input source files.
 
160
#
 
161
#   CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME( output_file_var
 
162
#                                                        cuda_target
 
163
#                                                        object_files )
 
164
#   -- Compute the name of the intermediate link file used for separable
 
165
#      compilation.  This file name is typically passed into
 
166
#      CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS.  output_file_var is produced
 
167
#      based on cuda_target the list of objects files that need separable
 
168
#      compilation as specified by object_files.  If the object_files list is
 
169
#      empty, then output_file_var will be empty.  This function is called
 
170
#      automatically for CUDA_ADD_LIBRARY and CUDA_ADD_EXECUTABLE.  Note that
 
171
#      this is a function and not a macro.
 
172
#
 
173
#   CUDA_INCLUDE_DIRECTORIES( path0 path1 ... )
 
174
#   -- Sets the directories that should be passed to nvcc
 
175
#      (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu
 
176
#      files.
 
177
#
 
178
#
 
179
#
 
180
#   CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS( output_file_var cuda_target
 
181
#                                            nvcc_flags object_files)
 
182
#
 
183
#   -- Generates the link object required by separable compilation from the given
 
184
#      object files.  This is called automatically for CUDA_ADD_EXECUTABLE and
 
185
#      CUDA_ADD_LIBRARY, but can be called manually when using CUDA_WRAP_SRCS
 
186
#      directly.  When called from CUDA_ADD_LIBRARY or CUDA_ADD_EXECUTABLE the
 
187
#      nvcc_flags passed in are the same as the flags passed in via the OPTIONS
 
188
#      argument.  The only nvcc flag added automatically is the bitness flag as
 
189
#      specified by CUDA_64_BIT_DEVICE_CODE.  Note that this is a function
 
190
#      instead of a macro.
 
191
#
 
192
#   CUDA_WRAP_SRCS ( cuda_target format generated_files file0 file1 ...
 
193
#                    [STATIC | SHARED | MODULE] [OPTIONS ...] )
 
194
#   -- This is where all the magic happens.  CUDA_ADD_EXECUTABLE,
 
195
#      CUDA_ADD_LIBRARY, CUDA_COMPILE, and CUDA_COMPILE_PTX all call this
 
196
#      function under the hood.
 
197
#
 
198
#      Given the list of files (file0 file1 ... fileN) this macro generates
 
199
#      custom commands that generate either PTX or linkable objects (use "PTX" or
 
200
#      "OBJ" for the format argument to switch).  Files that don't end with .cu
 
201
#      or have the HEADER_FILE_ONLY property are ignored.
 
202
#
 
203
#      The arguments passed in after OPTIONS are extra command line options to
 
204
#      give to nvcc.  You can also specify per configuration options by
 
205
#      specifying the name of the configuration followed by the options.  General
 
206
#      options must preceed configuration specific options.  Not all
 
207
#      configurations need to be specified, only the ones provided will be used.
 
208
#
 
209
#         OPTIONS -DFLAG=2 "-DFLAG_OTHER=space in flag"
 
210
#         DEBUG -g
 
211
#         RELEASE --use_fast_math
 
212
#         RELWITHDEBINFO --use_fast_math;-g
 
213
#         MINSIZEREL --use_fast_math
 
214
#
 
215
#      For certain configurations (namely VS generating object files with
 
216
#      CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE set to ON), no generated file will
 
217
#      be produced for the given cuda file.  This is because when you add the
 
218
#      cuda file to Visual Studio it knows that this file produces an object file
 
219
#      and will link in the resulting object file automatically.
 
220
#
 
221
#      This script will also generate a separate cmake script that is used at
 
222
#      build time to invoke nvcc.  This is for several reasons.
 
223
#
 
224
#        1. nvcc can return negative numbers as return values which confuses
 
225
#        Visual Studio into thinking that the command succeeded.  The script now
 
226
#        checks the error codes and produces errors when there was a problem.
 
227
#
 
228
#        2. nvcc has been known to not delete incomplete results when it
 
229
#        encounters problems.  This confuses build systems into thinking the
 
230
#        target was generated when in fact an unusable file exists.  The script
 
231
#        now deletes the output files if there was an error.
 
232
#
 
233
#        3. By putting all the options that affect the build into a file and then
 
234
#        make the build rule dependent on the file, the output files will be
 
235
#        regenerated when the options change.
 
236
#
 
237
#      This script also looks at optional arguments STATIC, SHARED, or MODULE to
 
238
#      determine when to target the object compilation for a shared library.
 
239
#      BUILD_SHARED_LIBS is ignored in CUDA_WRAP_SRCS, but it is respected in
 
240
#      CUDA_ADD_LIBRARY.  On some systems special flags are added for building
 
241
#      objects intended for shared libraries.  A preprocessor macro,
 
242
#      <target_name>_EXPORTS is defined when a shared library compilation is
 
243
#      detected.
 
244
#
 
245
#      Flags passed into add_definitions with -D or /D are passed along to nvcc.
 
246
#
 
247
#
 
248
#
 
249
# The script defines the following variables::
 
250
#
 
251
#   CUDA_VERSION_MAJOR    -- The major version of cuda as reported by nvcc.
 
252
#   CUDA_VERSION_MINOR    -- The minor version.
 
253
#   CUDA_VERSION
 
254
#   CUDA_VERSION_STRING   -- CUDA_VERSION_MAJOR.CUDA_VERSION_MINOR
 
255
#
 
256
#   CUDA_TOOLKIT_ROOT_DIR -- Path to the CUDA Toolkit (defined if not set).
 
257
#   CUDA_SDK_ROOT_DIR     -- Path to the CUDA SDK.  Use this to find files in the
 
258
#                            SDK.  This script will not directly support finding
 
259
#                            specific libraries or headers, as that isn't
 
260
#                            supported by NVIDIA.  If you want to change
 
261
#                            libraries when the path changes see the
 
262
#                            FindCUDA.cmake script for an example of how to clear
 
263
#                            these variables.  There are also examples of how to
 
264
#                            use the CUDA_SDK_ROOT_DIR to locate headers or
 
265
#                            libraries, if you so choose (at your own risk).
 
266
#   CUDA_INCLUDE_DIRS     -- Include directory for cuda headers.  Added automatically
 
267
#                            for CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY.
 
268
#   CUDA_LIBRARIES        -- Cuda RT library.
 
269
#   CUDA_CUFFT_LIBRARIES  -- Device or emulation library for the Cuda FFT
 
270
#                            implementation (alternative to:
 
271
#                            CUDA_ADD_CUFFT_TO_TARGET macro)
 
272
#   CUDA_CUBLAS_LIBRARIES -- Device or emulation library for the Cuda BLAS
 
273
#                            implementation (alterative to:
 
274
#                            CUDA_ADD_CUBLAS_TO_TARGET macro).
 
275
#   CUDA_cupti_LIBRARY    -- CUDA Profiling Tools Interface library.
 
276
#                            Only available for CUDA version 4.0+.
 
277
#   CUDA_curand_LIBRARY   -- CUDA Random Number Generation library.
 
278
#                            Only available for CUDA version 3.2+.
 
279
#   CUDA_cusparse_LIBRARY -- CUDA Sparse Matrix library.
 
280
#                            Only available for CUDA version 3.2+.
 
281
#   CUDA_npp_LIBRARY      -- NVIDIA Performance Primitives lib.
 
282
#                            Only available for CUDA version 4.0+.
 
283
#   CUDA_nppc_LIBRARY     -- NVIDIA Performance Primitives lib (core).
 
284
#                            Only available for CUDA version 5.5+.
 
285
#   CUDA_nppi_LIBRARY     -- NVIDIA Performance Primitives lib (image processing).
 
286
#                            Only available for CUDA version 5.5+.
 
287
#   CUDA_npps_LIBRARY     -- NVIDIA Performance Primitives lib (signal processing).
 
288
#                            Only available for CUDA version 5.5+.
 
289
#   CUDA_nvcuvenc_LIBRARY -- CUDA Video Encoder library.
 
290
#                            Only available for CUDA version 3.2+.
 
291
#                            Windows only.
 
292
#   CUDA_nvcuvid_LIBRARY  -- CUDA Video Decoder library.
 
293
#                            Only available for CUDA version 3.2+.
 
294
#                            Windows only.
 
295
#
 
296
 
 
297
#   James Bigler, NVIDIA Corp (nvidia.com - jbigler)
 
298
#   Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
 
299
#
 
300
#   Copyright (c) 2008 - 2009 NVIDIA Corporation.  All rights reserved.
 
301
#
 
302
#   Copyright (c) 2007-2009
 
303
#   Scientific Computing and Imaging Institute, University of Utah
 
304
#
 
305
#   This code is licensed under the MIT License.  See the FindCUDA.cmake script
 
306
#   for the text of the license.
 
307
 
 
308
# The MIT License
 
309
#
 
310
# License for the specific language governing rights and limitations under
 
311
# Permission is hereby granted, free of charge, to any person obtaining a
 
312
# copy of this software and associated documentation files (the "Software"),
 
313
# to deal in the Software without restriction, including without limitation
 
314
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
315
# and/or sell copies of the Software, and to permit persons to whom the
 
316
# Software is furnished to do so, subject to the following conditions:
 
317
#
 
318
# The above copyright notice and this permission notice shall be included
 
319
# in all copies or substantial portions of the Software.
 
320
#
 
321
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
322
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
323
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
324
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
325
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
326
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
327
# DEALINGS IN THE SOFTWARE.
 
328
#
 
329
###############################################################################
 
330
 
 
331
# FindCUDA.cmake
 
332
 
 
333
# This macro helps us find the location of helper files we will need the full path to
 
334
macro(CUDA_FIND_HELPER_FILE _name _extension)
 
335
  set(_full_name "${_name}.${_extension}")
 
336
  # CMAKE_CURRENT_LIST_FILE contains the full path to the file currently being
 
337
  # processed.  Using this variable, we can pull out the current path, and
 
338
  # provide a way to get access to the other files we need local to here.
 
339
  get_filename_component(CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
 
340
  set(CUDA_${_name} "${CMAKE_CURRENT_LIST_DIR}/FindCUDA/${_full_name}")
 
341
  if(NOT EXISTS "${CUDA_${_name}}")
 
342
    set(error_message "${_full_name} not found in ${CMAKE_CURRENT_LIST_DIR}/FindCUDA")
 
343
    if(CUDA_FIND_REQUIRED)
 
344
      message(FATAL_ERROR "${error_message}")
 
345
    else()
 
346
      if(NOT CUDA_FIND_QUIETLY)
 
347
        message(STATUS "${error_message}")
 
348
      endif()
 
349
    endif()
 
350
  endif()
 
351
  # Set this variable as internal, so the user isn't bugged with it.
 
352
  set(CUDA_${_name} ${CUDA_${_name}} CACHE INTERNAL "Location of ${_full_name}" FORCE)
 
353
endmacro()
 
354
 
 
355
#####################################################################
 
356
## CUDA_INCLUDE_NVCC_DEPENDENCIES
 
357
##
 
358
 
 
359
# So we want to try and include the dependency file if it exists.  If
 
360
# it doesn't exist then we need to create an empty one, so we can
 
361
# include it.
 
362
 
 
363
# If it does exist, then we need to check to see if all the files it
 
364
# depends on exist.  If they don't then we should clear the dependency
 
365
# file and regenerate it later.  This covers the case where a header
 
366
# file has disappeared or moved.
 
367
 
 
368
macro(CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file)
 
369
  set(CUDA_NVCC_DEPEND)
 
370
  set(CUDA_NVCC_DEPEND_REGENERATE FALSE)
 
371
 
 
372
 
 
373
  # Include the dependency file.  Create it first if it doesn't exist .  The
 
374
  # INCLUDE puts a dependency that will force CMake to rerun and bring in the
 
375
  # new info when it changes.  DO NOT REMOVE THIS (as I did and spent a few
 
376
  # hours figuring out why it didn't work.
 
377
  if(NOT EXISTS ${dependency_file})
 
378
    file(WRITE ${dependency_file} "#FindCUDA.cmake generated file.  Do not edit.\n")
 
379
  endif()
 
380
  # Always include this file to force CMake to run again next
 
381
  # invocation and rebuild the dependencies.
 
382
  #message("including dependency_file = ${dependency_file}")
 
383
  include(${dependency_file})
 
384
 
 
385
  # Now we need to verify the existence of all the included files
 
386
  # here.  If they aren't there we need to just blank this variable and
 
387
  # make the file regenerate again.
 
388
#   if(DEFINED CUDA_NVCC_DEPEND)
 
389
#     message("CUDA_NVCC_DEPEND set")
 
390
#   else()
 
391
#     message("CUDA_NVCC_DEPEND NOT set")
 
392
#   endif()
 
393
  if(CUDA_NVCC_DEPEND)
 
394
    #message("CUDA_NVCC_DEPEND found")
 
395
    foreach(f ${CUDA_NVCC_DEPEND})
 
396
      # message("searching for ${f}")
 
397
      if(NOT EXISTS ${f})
 
398
        #message("file ${f} not found")
 
399
        set(CUDA_NVCC_DEPEND_REGENERATE TRUE)
 
400
      endif()
 
401
    endforeach()
 
402
  else()
 
403
    #message("CUDA_NVCC_DEPEND false")
 
404
    # No dependencies, so regenerate the file.
 
405
    set(CUDA_NVCC_DEPEND_REGENERATE TRUE)
 
406
  endif()
 
407
 
 
408
  #message("CUDA_NVCC_DEPEND_REGENERATE = ${CUDA_NVCC_DEPEND_REGENERATE}")
 
409
  # No incoming dependencies, so we need to generate them.  Make the
 
410
  # output depend on the dependency file itself, which should cause the
 
411
  # rule to re-run.
 
412
  if(CUDA_NVCC_DEPEND_REGENERATE)
 
413
    set(CUDA_NVCC_DEPEND ${dependency_file})
 
414
    #message("Generating an empty dependency_file: ${dependency_file}")
 
415
    file(WRITE ${dependency_file} "#FindCUDA.cmake generated file.  Do not edit.\n")
 
416
  endif()
 
417
 
 
418
endmacro()
 
419
 
 
420
###############################################################################
 
421
###############################################################################
 
422
# Setup variables' defaults
 
423
###############################################################################
 
424
###############################################################################
 
425
 
 
426
# Allow the user to specify if the device code is supposed to be 32 or 64 bit.
 
427
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
 
428
  set(CUDA_64_BIT_DEVICE_CODE_DEFAULT ON)
 
429
else()
 
430
  set(CUDA_64_BIT_DEVICE_CODE_DEFAULT OFF)
 
431
endif()
 
432
option(CUDA_64_BIT_DEVICE_CODE "Compile device code in 64 bit mode" ${CUDA_64_BIT_DEVICE_CODE_DEFAULT})
 
433
 
 
434
# Attach the build rule to the source file in VS.  This option
 
435
option(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE "Attach the build rule to the CUDA source file.  Enable only when the CUDA source file is added to at most one target." ON)
 
436
 
 
437
# Prints out extra information about the cuda file during compilation
 
438
option(CUDA_BUILD_CUBIN "Generate and parse .cubin files in Device mode." OFF)
 
439
 
 
440
# Set whether we are using emulation or device mode.
 
441
option(CUDA_BUILD_EMULATION "Build in Emulation mode" OFF)
 
442
 
 
443
# Where to put the generated output.
 
444
set(CUDA_GENERATED_OUTPUT_DIR "" CACHE PATH "Directory to put all the output files.  If blank it will default to the CMAKE_CURRENT_BINARY_DIR")
 
445
 
 
446
# Parse HOST_COMPILATION mode.
 
447
option(CUDA_HOST_COMPILATION_CPP "Generated file extension" ON)
 
448
 
 
449
# Extra user settable flags
 
450
set(CUDA_NVCC_FLAGS "" CACHE STRING "Semi-colon delimit multiple arguments.")
 
451
 
 
452
if(CMAKE_GENERATOR MATCHES "Visual Studio")
 
453
  set(CUDA_HOST_COMPILER "$(VCInstallDir)bin" CACHE FILEPATH "Host side compiler used by NVCC")
 
454
else()
 
455
  # Using cc which is symlink to clang may let NVCC think it is GCC and issue
 
456
  # unhandled -dumpspecs option to clang. Also in case neither
 
457
  # CMAKE_C_COMPILER is defined (project does not use C language) nor
 
458
  # CUDA_HOST_COMPILER is specified manually we should skip -ccbin and let
 
459
  # nvcc use its own default C compiler.
 
460
  if(DEFINED CMAKE_C_COMPILER AND NOT DEFINED CUDA_HOST_COMPILER)
 
461
    get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH)
 
462
  else()
 
463
    set(c_compiler_realpath "")
 
464
  endif()
 
465
  set(CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC")
 
466
endif()
 
467
 
 
468
# Propagate the host flags to the host compiler via -Xcompiler
 
469
option(CUDA_PROPAGATE_HOST_FLAGS "Propage C/CXX_FLAGS and friends to the host compiler via -Xcompile" ON)
 
470
 
 
471
# Enable CUDA_SEPARABLE_COMPILATION
 
472
option(CUDA_SEPARABLE_COMPILATION "Compile CUDA objects with separable compilation enabled.  Requires CUDA 5.0+" OFF)
 
473
 
 
474
# Specifies whether the commands used when compiling the .cu file will be printed out.
 
475
option(CUDA_VERBOSE_BUILD "Print out the commands run while compiling the CUDA source file.  With the Makefile generator this defaults to VERBOSE variable specified on the command line, but can be forced on with this option." OFF)
 
476
 
 
477
mark_as_advanced(
 
478
  CUDA_64_BIT_DEVICE_CODE
 
479
  CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE
 
480
  CUDA_GENERATED_OUTPUT_DIR
 
481
  CUDA_HOST_COMPILATION_CPP
 
482
  CUDA_NVCC_FLAGS
 
483
  CUDA_PROPAGATE_HOST_FLAGS
 
484
  )
 
485
 
 
486
# Makefile and similar generators don't define CMAKE_CONFIGURATION_TYPES, so we
 
487
# need to add another entry for the CMAKE_BUILD_TYPE.  We also need to add the
 
488
# standerd set of 4 build types (Debug, MinSizeRel, Release, and RelWithDebInfo)
 
489
# for completeness.  We need run this loop in order to accomodate the addition
 
490
# of extra configuration types.  Duplicate entries will be removed by
 
491
# REMOVE_DUPLICATES.
 
492
set(CUDA_configuration_types ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug MinSizeRel Release RelWithDebInfo)
 
493
list(REMOVE_DUPLICATES CUDA_configuration_types)
 
494
foreach(config ${CUDA_configuration_types})
 
495
    string(TOUPPER ${config} config_upper)
 
496
    set(CUDA_NVCC_FLAGS_${config_upper} "" CACHE STRING "Semi-colon delimit multiple arguments.")
 
497
    mark_as_advanced(CUDA_NVCC_FLAGS_${config_upper})
 
498
endforeach()
 
499
 
 
500
###############################################################################
 
501
###############################################################################
 
502
# Locate CUDA, Set Build Type, etc.
 
503
###############################################################################
 
504
###############################################################################
 
505
 
 
506
macro(cuda_unset_include_and_libraries)
 
507
  unset(CUDA_TOOLKIT_INCLUDE CACHE)
 
508
  unset(CUDA_CUDART_LIBRARY CACHE)
 
509
  unset(CUDA_CUDA_LIBRARY CACHE)
 
510
  # Make sure you run this before you unset CUDA_VERSION.
 
511
  if(CUDA_VERSION VERSION_EQUAL "3.0")
 
512
    # This only existed in the 3.0 version of the CUDA toolkit
 
513
    unset(CUDA_CUDARTEMU_LIBRARY CACHE)
 
514
  endif()
 
515
  unset(CUDA_cupti_LIBRARY CACHE)
 
516
  unset(CUDA_cublas_LIBRARY CACHE)
 
517
  unset(CUDA_cublasemu_LIBRARY CACHE)
 
518
  unset(CUDA_cufft_LIBRARY CACHE)
 
519
  unset(CUDA_cufftemu_LIBRARY CACHE)
 
520
  unset(CUDA_curand_LIBRARY CACHE)
 
521
  unset(CUDA_cusparse_LIBRARY CACHE)
 
522
  unset(CUDA_npp_LIBRARY CACHE)
 
523
  unset(CUDA_nppc_LIBRARY CACHE)
 
524
  unset(CUDA_nppi_LIBRARY CACHE)
 
525
  unset(CUDA_npps_LIBRARY CACHE)
 
526
  unset(CUDA_nvcuvenc_LIBRARY CACHE)
 
527
  unset(CUDA_nvcuvid_LIBRARY CACHE)
 
528
endmacro()
 
529
 
 
530
# Check to see if the CUDA_TOOLKIT_ROOT_DIR and CUDA_SDK_ROOT_DIR have changed,
 
531
# if they have then clear the cache variables, so that will be detected again.
 
532
if(DEFINED CUDA_TOOLKIT_ROOT_DIR_INTERNAL AND (NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}"))
 
533
  unset(CUDA_TARGET_TRIPLET CACHE)
 
534
  unset(CUDA_TOOLKIT_TARGET_DIR CACHE)
 
535
  unset(CUDA_NVCC_EXECUTABLE CACHE)
 
536
  unset(CUDA_VERSION CACHE)
 
537
  cuda_unset_include_and_libraries()
 
538
endif()
 
539
 
 
540
if(DEFINED CUDA_TARGET_TRIPLET_INTERNAL AND (NOT "${CUDA_TARGET_TRIPLET}" STREQUAL "${CUDA_TARGET_TRIPLET_INTERNAL}") OR
 
541
   (DEFINED CUDA_TOOLKIT_TARGET_DIR  AND DEFINED CUDA_TOOLKIT_TARGET_DIR_INTERNAL AND NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL}"))
 
542
  cuda_unset_include_and_libraries()
 
543
endif()
 
544
 
 
545
if(NOT "${CUDA_SDK_ROOT_DIR}" STREQUAL "${CUDA_SDK_ROOT_DIR_INTERNAL}")
 
546
  # No specific variables to catch.  Use this kind of code before calling
 
547
  # find_package(CUDA) to clean up any variables that may depend on this path.
 
548
 
 
549
  #   unset(MY_SPECIAL_CUDA_SDK_INCLUDE_DIR CACHE)
 
550
  #   unset(MY_SPECIAL_CUDA_SDK_LIBRARY CACHE)
 
551
endif()
 
552
 
 
553
# Search for the cuda distribution.
 
554
if(NOT CUDA_TOOLKIT_ROOT_DIR)
 
555
 
 
556
  # Search in the CUDA_BIN_PATH first.
 
557
  find_path(CUDA_TOOLKIT_ROOT_DIR
 
558
    NAMES nvcc nvcc.exe
 
559
    PATHS
 
560
      ENV CUDA_PATH
 
561
      ENV CUDA_BIN_PATH
 
562
    PATH_SUFFIXES bin bin64
 
563
    DOC "Toolkit location."
 
564
    NO_DEFAULT_PATH
 
565
    )
 
566
  # Now search default paths
 
567
  find_path(CUDA_TOOLKIT_ROOT_DIR
 
568
    NAMES nvcc nvcc.exe
 
569
    PATHS /usr/local/bin
 
570
          /usr/local/cuda/bin
 
571
    DOC "Toolkit location."
 
572
    )
 
573
 
 
574
  if (CUDA_TOOLKIT_ROOT_DIR)
 
575
    string(REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR})
 
576
    # We need to force this back into the cache.
 
577
    set(CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR} CACHE PATH "Toolkit location." FORCE)
 
578
  endif()
 
579
  if (NOT EXISTS ${CUDA_TOOLKIT_ROOT_DIR})
 
580
    if(CUDA_FIND_REQUIRED)
 
581
      message(FATAL_ERROR "Specify CUDA_TOOLKIT_ROOT_DIR")
 
582
    elseif(NOT CUDA_FIND_QUIETLY)
 
583
      message("CUDA_TOOLKIT_ROOT_DIR not found or specified")
 
584
    endif()
 
585
  endif ()
 
586
endif ()
 
587
 
 
588
# CUDA_NVCC_EXECUTABLE
 
589
find_program(CUDA_NVCC_EXECUTABLE
 
590
  NAMES nvcc
 
591
  PATHS "${CUDA_TOOLKIT_ROOT_DIR}"
 
592
  ENV CUDA_PATH
 
593
  ENV CUDA_BIN_PATH
 
594
  PATH_SUFFIXES bin bin64
 
595
  NO_DEFAULT_PATH
 
596
  )
 
597
# Search default search paths, after we search our own set of paths.
 
598
find_program(CUDA_NVCC_EXECUTABLE nvcc)
 
599
mark_as_advanced(CUDA_NVCC_EXECUTABLE)
 
600
 
 
601
if(CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION)
 
602
  # Compute the version.
 
603
  execute_process (COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
 
604
  string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${NVCC_OUT})
 
605
  string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${NVCC_OUT})
 
606
  set(CUDA_VERSION "${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" CACHE STRING "Version of CUDA as computed from nvcc.")
 
607
  mark_as_advanced(CUDA_VERSION)
 
608
else()
 
609
  # Need to set these based off of the cached value
 
610
  string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR "${CUDA_VERSION}")
 
611
  string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR "${CUDA_VERSION}")
 
612
endif()
 
613
 
 
614
# Always set this convenience variable
 
615
set(CUDA_VERSION_STRING "${CUDA_VERSION}")
 
616
 
 
617
# Target CPU architecture
 
618
if(DEFINED CUDA_TARGET_CPU_ARCH)
 
619
  set(_cuda_target_cpu_arch_initial "${CUDA_TARGET_CPU_ARCH}")
 
620
elseif(CUDA_VERSION VERSION_GREATER "5.0" AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|ARM)")
 
621
  set(_cuda_target_cpu_arch_initial "ARM")
 
622
elseif(CUDA_VERSION VERSION_GREATER "6.5" AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|AARCH64)")
 
623
  set(_cuda_target_cpu_arch_initial "AARCH64")
 
624
else()
 
625
  set(_cuda_target_cpu_arch_initial "")
 
626
endif()
 
627
set(CUDA_TARGET_CPU_ARCH "${_cuda_target_cpu_arch_initial}" CACHE STRING "Specify the name of the class of CPU architecture for which the input files must be compiled.")
 
628
mark_as_advanced(CUDA_TARGET_CPU_ARCH)
 
629
 
 
630
# Target OS variant
 
631
if(DEFINED CUDA_TARGET_OS_VARIANT)
 
632
  set(_cuda_target_os_variant_initial "${CUDA_TARGET_OS_VARIANT}")
 
633
else()
 
634
  set(_cuda_target_os_variant_initial "")
 
635
endif()
 
636
set(CUDA_TARGET_OS_VARIANT "${_cuda_target_os_variant_initial}" CACHE STRING "Specify the name of the class of OS for which the input files must be compiled.")
 
637
mark_as_advanced(CUDA_TARGET_OS_VARIANT)
 
638
 
 
639
# Target triplet
 
640
if(DEFINED CUDA_TARGET_TRIPLET)
 
641
  set(_cuda_target_triplet_initial "${CUDA_TARGET_TRIPLET}")
 
642
elseif(CUDA_VERSION VERSION_GREATER "5.0" AND CMAKE_CROSSCOMPILING AND "x${CUDA_TARGET_CPU_ARCH}" STREQUAL "xARM")
 
643
  if("${CUDA_TARGET_OS_VARIANT}" STREQUAL "Android" AND EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/armv7-linux-androideabi")
 
644
    set(_cuda_target_triplet_initial "armv7-linux-androideabi")
 
645
  elseif(EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/armv7-linux-gnueabihf")
 
646
    set(_cuda_target_triplet_initial "armv7-linux-gnueabihf")
 
647
  endif()
 
648
elseif(CUDA_VERSION VERSION_GREATER "6.5" AND CMAKE_CROSSCOMPILING AND "x${CUDA_TARGET_CPU_ARCH}" STREQUAL "xAARCH64")
 
649
  if("${CUDA_TARGET_OS_VARIANT}" STREQUAL "Android" AND EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/aarch64-linux-androideabi")
 
650
    set(_cuda_target_triplet_initial "aarch64-linux-androideabi")
 
651
  elseif(EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/aarch64-linux-gnueabihf")
 
652
    set(_cuda_target_triplet_initial "aarch64-linux-gnueabihf")
 
653
  endif()
 
654
endif()
 
655
set(CUDA_TARGET_TRIPLET "${_cuda_target_triplet_initial}" CACHE STRING "Specify the target triplet for which the input files must be compiled.")
 
656
file(GLOB __cuda_available_target_tiplets RELATIVE "${CUDA_TOOLKIT_ROOT_DIR}/targets" "${CUDA_TOOLKIT_ROOT_DIR}/targets/*" )
 
657
set_property(CACHE CUDA_TARGET_TRIPLET PROPERTY STRINGS ${__cuda_available_target_tiplets})
 
658
mark_as_advanced(CUDA_TARGET_TRIPLET)
 
659
 
 
660
# Target directory
 
661
if(NOT DEFINED CUDA_TOOLKIT_TARGET_DIR AND CUDA_TARGET_TRIPLET AND EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/${CUDA_TARGET_TRIPLET}")
 
662
  set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}/targets/${CUDA_TARGET_TRIPLET}")
 
663
endif()
 
664
 
 
665
# CUDA_TOOLKIT_INCLUDE
 
666
find_path(CUDA_TOOLKIT_INCLUDE
 
667
  device_functions.h # Header included in toolkit
 
668
  PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}"
 
669
  ENV CUDA_PATH
 
670
  ENV CUDA_INC_PATH
 
671
  PATH_SUFFIXES include
 
672
  NO_DEFAULT_PATH
 
673
  )
 
674
# Search default search paths, after we search our own set of paths.
 
675
find_path(CUDA_TOOLKIT_INCLUDE device_functions.h)
 
676
mark_as_advanced(CUDA_TOOLKIT_INCLUDE)
 
677
 
 
678
# Set the user list of include dir to nothing to initialize it.
 
679
set (CUDA_NVCC_INCLUDE_ARGS_USER "")
 
680
set (CUDA_INCLUDE_DIRS ${CUDA_TOOLKIT_INCLUDE})
 
681
 
 
682
macro(cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext )
 
683
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
 
684
    # CUDA 3.2+ on Windows moved the library directories, so we need the new
 
685
    # and old paths.
 
686
    set(_cuda_64bit_lib_dir "${_path_ext}lib/x64" "${_path_ext}lib64" "${_path_ext}libx64" )
 
687
  endif()
 
688
  if(CMAKE_CROSSCOMPILING AND (ARM OR AARCH64))
 
689
    set(_cuda_cross_arm_lib_dir "${_path_ext}lib/stubs")
 
690
  endif()
 
691
  if(CUDA_VERSION VERSION_GREATER "6.0")
 
692
    set(_cuda_static_lib_names "")
 
693
    foreach(name ${_names})
 
694
      list(APPEND _cuda_static_lib_names "${name}_static")
 
695
    endforeach()
 
696
  endif()
 
697
  # CUDA 3.2+ on Windows moved the library directories, so we need to new
 
698
  # (lib/Win32) and the old path (lib).
 
699
  find_library(${_var}
 
700
    NAMES ${_names} ${_cuda_static_lib_names}
 
701
    PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}"
 
702
    ENV CUDA_PATH
 
703
    ENV CUDA_LIB_PATH
 
704
    PATH_SUFFIXES ${_cuda_64bit_lib_dir} ${_cuda_cross_arm_lib_dir} "${_path_ext}lib/Win32" "${_path_ext}lib" "${_path_ext}libWin32"
 
705
    DOC ${_doc}
 
706
    NO_DEFAULT_PATH
 
707
    )
 
708
  # Search default search paths, after we search our own set of paths.
 
709
  find_library(${_var}
 
710
    NAMES ${_names} ${_cuda_static_lib_names}
 
711
    PATHS "/usr/lib/nvidia-current"
 
712
    DOC ${_doc}
 
713
    )
 
714
endmacro()
 
715
 
 
716
macro(cuda_find_library_local_first _var _names _doc)
 
717
  cuda_find_library_local_first_with_path_ext( "${_var}" "${_names}" "${_doc}" "" )
 
718
endmacro()
 
719
 
 
720
macro(find_library_local_first _var _names _doc )
 
721
  cuda_find_library_local_first( "${_var}" "${_names}" "${_doc}" "" )
 
722
endmacro()
 
723
 
 
724
 
 
725
# CUDA_LIBRARIES
 
726
cuda_find_library_local_first(CUDA_CUDART_LIBRARY cudart "\"cudart\" library")
 
727
if(CUDA_VERSION VERSION_EQUAL "3.0")
 
728
  # The cudartemu library only existed for the 3.0 version of CUDA.
 
729
  cuda_find_library_local_first(CUDA_CUDARTEMU_LIBRARY cudartemu "\"cudartemu\" library")
 
730
  mark_as_advanced(
 
731
    CUDA_CUDARTEMU_LIBRARY
 
732
    )
 
733
endif()
 
734
 
 
735
# CUPTI library showed up in cuda toolkit 4.0
 
736
if(NOT CUDA_VERSION VERSION_LESS "4.0")
 
737
  cuda_find_library_local_first_with_path_ext(CUDA_cupti_LIBRARY cupti "\"cupti\" library" "extras/CUPTI/")
 
738
  mark_as_advanced(CUDA_cupti_LIBRARY)
 
739
endif()
 
740
 
 
741
# If we are using emulation mode and we found the cudartemu library then use
 
742
# that one instead of cudart.
 
743
if(CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY)
 
744
  set(CUDA_LIBRARIES ${CUDA_CUDARTEMU_LIBRARY})
 
745
else()
 
746
  set(CUDA_LIBRARIES ${CUDA_CUDART_LIBRARY})
 
747
endif()
 
748
 
 
749
# 1.1 toolkit on linux doesn't appear to have a separate library on
 
750
# some platforms.
 
751
cuda_find_library_local_first(CUDA_CUDA_LIBRARY cuda "\"cuda\" library (older versions only).")
 
752
 
 
753
mark_as_advanced(
 
754
  CUDA_CUDA_LIBRARY
 
755
  CUDA_CUDART_LIBRARY
 
756
  )
 
757
 
 
758
#######################
 
759
# Look for some of the toolkit helper libraries
 
760
macro(FIND_CUDA_HELPER_LIBS _name)
 
761
  cuda_find_library_local_first(CUDA_${_name}_LIBRARY ${_name} "\"${_name}\" library")
 
762
  mark_as_advanced(CUDA_${_name}_LIBRARY)
 
763
endmacro()
 
764
 
 
765
#######################
 
766
# Disable emulation for v3.1 onward
 
767
if(CUDA_VERSION VERSION_GREATER "3.0")
 
768
  if(CUDA_BUILD_EMULATION)
 
769
    message(FATAL_ERROR "CUDA_BUILD_EMULATION is not supported in version 3.1 and onwards.  You must disable it to proceed.  You have version ${CUDA_VERSION}.")
 
770
  endif()
 
771
endif()
 
772
 
 
773
# Search for additional CUDA toolkit libraries.
 
774
if(CUDA_VERSION VERSION_LESS "3.1")
 
775
  # Emulation libraries aren't available in version 3.1 onward.
 
776
  find_cuda_helper_libs(cufftemu)
 
777
  find_cuda_helper_libs(cublasemu)
 
778
endif()
 
779
find_cuda_helper_libs(cufft)
 
780
find_cuda_helper_libs(cublas)
 
781
if(NOT CUDA_VERSION VERSION_LESS "3.2")
 
782
  # cusparse showed up in version 3.2
 
783
  find_cuda_helper_libs(cusparse)
 
784
  find_cuda_helper_libs(curand)
 
785
  if (WIN32)
 
786
    find_cuda_helper_libs(nvcuvenc)
 
787
    find_cuda_helper_libs(nvcuvid)
 
788
  endif()
 
789
endif()
 
790
if(CUDA_VERSION VERSION_GREATER "5.0")
 
791
  # In CUDA 5.5 NPP was splitted onto 3 separate libraries.
 
792
  find_cuda_helper_libs(nppc)
 
793
  find_cuda_helper_libs(nppi)
 
794
  find_cuda_helper_libs(npps)
 
795
  set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")
 
796
elseif(NOT CUDA_VERSION VERSION_LESS "4.0")
 
797
  find_cuda_helper_libs(npp)
 
798
endif()
 
799
 
 
800
if (CUDA_BUILD_EMULATION)
 
801
  set(CUDA_CUFFT_LIBRARIES ${CUDA_cufftemu_LIBRARY})
 
802
  set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublasemu_LIBRARY})
 
803
else()
 
804
  set(CUDA_CUFFT_LIBRARIES ${CUDA_cufft_LIBRARY})
 
805
  set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublas_LIBRARY})
 
806
endif()
 
807
 
 
808
########################
 
809
# Look for the SDK stuff.  As of CUDA 3.0 NVSDKCUDA_ROOT has been replaced with
 
810
# NVSDKCOMPUTE_ROOT with the old CUDA C contents moved into the C subdirectory
 
811
find_path(CUDA_SDK_ROOT_DIR common/inc/cutil.h
 
812
 HINTS
 
813
  "$ENV{NVSDKCOMPUTE_ROOT}/C"
 
814
  ENV NVSDKCUDA_ROOT
 
815
  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Installed Products\\NVIDIA SDK 10\\Compute;InstallDir]"
 
816
 PATHS
 
817
  "/Developer/GPU\ Computing/C"
 
818
  )
 
819
 
 
820
# Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the
 
821
# environment variables.
 
822
set(CUDA_SDK_SEARCH_PATH
 
823
  "${CUDA_SDK_ROOT_DIR}"
 
824
  "${CUDA_TOOLKIT_ROOT_DIR}/local/NVSDK0.2"
 
825
  "${CUDA_TOOLKIT_ROOT_DIR}/NVSDK0.2"
 
826
  "${CUDA_TOOLKIT_ROOT_DIR}/NV_CUDA_SDK"
 
827
  "$ENV{HOME}/NVIDIA_CUDA_SDK"
 
828
  "$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX"
 
829
  "/Developer/CUDA"
 
830
  )
 
831
 
 
832
# Example of how to find an include file from the CUDA_SDK_ROOT_DIR
 
833
 
 
834
# find_path(CUDA_CUT_INCLUDE_DIR
 
835
#   cutil.h
 
836
#   PATHS ${CUDA_SDK_SEARCH_PATH}
 
837
#   PATH_SUFFIXES "common/inc"
 
838
#   DOC "Location of cutil.h"
 
839
#   NO_DEFAULT_PATH
 
840
#   )
 
841
# # Now search system paths
 
842
# find_path(CUDA_CUT_INCLUDE_DIR cutil.h DOC "Location of cutil.h")
 
843
 
 
844
# mark_as_advanced(CUDA_CUT_INCLUDE_DIR)
 
845
 
 
846
 
 
847
# Example of how to find a library in the CUDA_SDK_ROOT_DIR
 
848
 
 
849
# # cutil library is called cutil64 for 64 bit builds on windows.  We don't want
 
850
# # to get these confused, so we are setting the name based on the word size of
 
851
# # the build.
 
852
 
 
853
# if(CMAKE_SIZEOF_VOID_P EQUAL 8)
 
854
#   set(cuda_cutil_name cutil64)
 
855
# else()
 
856
#   set(cuda_cutil_name cutil32)
 
857
# endif()
 
858
 
 
859
# find_library(CUDA_CUT_LIBRARY
 
860
#   NAMES cutil ${cuda_cutil_name}
 
861
#   PATHS ${CUDA_SDK_SEARCH_PATH}
 
862
#   # The new version of the sdk shows up in common/lib, but the old one is in lib
 
863
#   PATH_SUFFIXES "common/lib" "lib"
 
864
#   DOC "Location of cutil library"
 
865
#   NO_DEFAULT_PATH
 
866
#   )
 
867
# # Now search system paths
 
868
# find_library(CUDA_CUT_LIBRARY NAMES cutil ${cuda_cutil_name} DOC "Location of cutil library")
 
869
# mark_as_advanced(CUDA_CUT_LIBRARY)
 
870
# set(CUDA_CUT_LIBRARIES ${CUDA_CUT_LIBRARY})
 
871
 
 
872
 
 
873
 
 
874
#############################
 
875
# Check for required components
 
876
set(CUDA_FOUND TRUE)
 
877
 
 
878
set(CUDA_TOOLKIT_ROOT_DIR_INTERNAL "${CUDA_TOOLKIT_ROOT_DIR}" CACHE INTERNAL
 
879
  "This is the value of the last time CUDA_TOOLKIT_ROOT_DIR was set successfully." FORCE)
 
880
set(CUDA_TARGET_TRIPLET_INTERNAL "${CUDA_TARGET_TRIPLET}" CACHE INTERNAL
 
881
  "This is the value of the last time CUDA_TARGET_TRIPLET was set successfully." FORCE)
 
882
set(CUDA_TOOLKIT_TARGET_DIR_INTERNAL "${CUDA_TOOLKIT_TARGET_DIR}" CACHE INTERNAL
 
883
  "This is the value of the last time CUDA_TOOLKIT_TARGET_DIR was set successfully." FORCE)
 
884
set(CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL
 
885
  "This is the value of the last time CUDA_SDK_ROOT_DIR was set successfully." FORCE)
 
886
 
 
887
include(FindPackageHandleStandardArgs)
 
888
find_package_handle_standard_args(CUDA
 
889
  REQUIRED_VARS
 
890
    CUDA_TOOLKIT_ROOT_DIR
 
891
    CUDA_NVCC_EXECUTABLE
 
892
    CUDA_INCLUDE_DIRS
 
893
    CUDA_CUDART_LIBRARY
 
894
  VERSION_VAR
 
895
    CUDA_VERSION
 
896
  )
 
897
 
 
898
 
 
899
 
 
900
###############################################################################
 
901
###############################################################################
 
902
# Macros
 
903
###############################################################################
 
904
###############################################################################
 
905
 
 
906
###############################################################################
 
907
# Add include directories to pass to the nvcc command.
 
908
macro(CUDA_INCLUDE_DIRECTORIES)
 
909
  foreach(dir ${ARGN})
 
910
    list(APPEND CUDA_NVCC_INCLUDE_ARGS_USER -I${dir})
 
911
  endforeach()
 
912
endmacro()
 
913
 
 
914
 
 
915
##############################################################################
 
916
cuda_find_helper_file(parse_cubin cmake)
 
917
cuda_find_helper_file(make2cmake cmake)
 
918
cuda_find_helper_file(run_nvcc cmake)
 
919
 
 
920
##############################################################################
 
921
# Separate the OPTIONS out from the sources
 
922
#
 
923
macro(CUDA_GET_SOURCES_AND_OPTIONS _sources _cmake_options _options)
 
924
  set( ${_sources} )
 
925
  set( ${_cmake_options} )
 
926
  set( ${_options} )
 
927
  set( _found_options FALSE )
 
928
  foreach(arg ${ARGN})
 
929
    if("x${arg}" STREQUAL "xOPTIONS")
 
930
      set( _found_options TRUE )
 
931
    elseif(
 
932
        "x${arg}" STREQUAL "xWIN32" OR
 
933
        "x${arg}" STREQUAL "xMACOSX_BUNDLE" OR
 
934
        "x${arg}" STREQUAL "xEXCLUDE_FROM_ALL" OR
 
935
        "x${arg}" STREQUAL "xSTATIC" OR
 
936
        "x${arg}" STREQUAL "xSHARED" OR
 
937
        "x${arg}" STREQUAL "xMODULE"
 
938
        )
 
939
      list(APPEND ${_cmake_options} ${arg})
 
940
    else()
 
941
      if ( _found_options )
 
942
        list(APPEND ${_options} ${arg})
 
943
      else()
 
944
        # Assume this is a file
 
945
        list(APPEND ${_sources} ${arg})
 
946
      endif()
 
947
    endif()
 
948
  endforeach()
 
949
endmacro()
 
950
 
 
951
##############################################################################
 
952
# Parse the OPTIONS from ARGN and set the variables prefixed by _option_prefix
 
953
#
 
954
macro(CUDA_PARSE_NVCC_OPTIONS _option_prefix)
 
955
  set( _found_config )
 
956
  foreach(arg ${ARGN})
 
957
    # Determine if we are dealing with a perconfiguration flag
 
958
    foreach(config ${CUDA_configuration_types})
 
959
      string(TOUPPER ${config} config_upper)
 
960
      if (arg STREQUAL "${config_upper}")
 
961
        set( _found_config _${arg})
 
962
        # Set arg to nothing to keep it from being processed further
 
963
        set( arg )
 
964
      endif()
 
965
    endforeach()
 
966
 
 
967
    if ( arg )
 
968
      list(APPEND ${_option_prefix}${_found_config} "${arg}")
 
969
    endif()
 
970
  endforeach()
 
971
endmacro()
 
972
 
 
973
##############################################################################
 
974
# Helper to add the include directory for CUDA only once
 
975
function(CUDA_ADD_CUDA_INCLUDE_ONCE)
 
976
  get_directory_property(_include_directories INCLUDE_DIRECTORIES)
 
977
  set(_add TRUE)
 
978
  if(_include_directories)
 
979
    foreach(dir ${_include_directories})
 
980
      if("${dir}" STREQUAL "${CUDA_INCLUDE_DIRS}")
 
981
        set(_add FALSE)
 
982
      endif()
 
983
    endforeach()
 
984
  endif()
 
985
  if(_add)
 
986
    include_directories(${CUDA_INCLUDE_DIRS})
 
987
  endif()
 
988
endfunction()
 
989
 
 
990
function(CUDA_BUILD_SHARED_LIBRARY shared_flag)
 
991
  set(cmake_args ${ARGN})
 
992
  # If SHARED, MODULE, or STATIC aren't already in the list of arguments, then
 
993
  # add SHARED or STATIC based on the value of BUILD_SHARED_LIBS.
 
994
  list(FIND cmake_args SHARED _cuda_found_SHARED)
 
995
  list(FIND cmake_args MODULE _cuda_found_MODULE)
 
996
  list(FIND cmake_args STATIC _cuda_found_STATIC)
 
997
  if( _cuda_found_SHARED GREATER -1 OR
 
998
      _cuda_found_MODULE GREATER -1 OR
 
999
      _cuda_found_STATIC GREATER -1)
 
1000
    set(_cuda_build_shared_libs)
 
1001
  else()
 
1002
    if (BUILD_SHARED_LIBS)
 
1003
      set(_cuda_build_shared_libs SHARED)
 
1004
    else()
 
1005
      set(_cuda_build_shared_libs STATIC)
 
1006
    endif()
 
1007
  endif()
 
1008
  set(${shared_flag} ${_cuda_build_shared_libs} PARENT_SCOPE)
 
1009
endfunction()
 
1010
 
 
1011
##############################################################################
 
1012
# Helper to avoid clashes of files with the same basename but different paths.
 
1013
# This doesn't attempt to do exactly what CMake internals do, which is to only
 
1014
# add this path when there is a conflict, since by the time a second collision
 
1015
# in names is detected it's already too late to fix the first one.  For
 
1016
# consistency sake the relative path will be added to all files.
 
1017
function(CUDA_COMPUTE_BUILD_PATH path build_path)
 
1018
  #message("CUDA_COMPUTE_BUILD_PATH([${path}] ${build_path})")
 
1019
  # Only deal with CMake style paths from here on out
 
1020
  file(TO_CMAKE_PATH "${path}" bpath)
 
1021
  if (IS_ABSOLUTE "${bpath}")
 
1022
    # Absolute paths are generally unnessary, especially if something like
 
1023
    # file(GLOB_RECURSE) is used to pick up the files.
 
1024
 
 
1025
    string(FIND "${bpath}" "${CMAKE_CURRENT_BINARY_DIR}" _binary_dir_pos)
 
1026
    if (_binary_dir_pos EQUAL 0)
 
1027
      file(RELATIVE_PATH bpath "${CMAKE_CURRENT_BINARY_DIR}" "${bpath}")
 
1028
    else()
 
1029
      file(RELATIVE_PATH bpath "${CMAKE_CURRENT_SOURCE_DIR}" "${bpath}")
 
1030
    endif()
 
1031
  endif()
 
1032
 
 
1033
  # This recipe is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the
 
1034
  # CMake source.
 
1035
 
 
1036
  # Remove leading /
 
1037
  string(REGEX REPLACE "^[/]+" "" bpath "${bpath}")
 
1038
  # Avoid absolute paths by removing ':'
 
1039
  string(REPLACE ":" "_" bpath "${bpath}")
 
1040
  # Avoid relative paths that go up the tree
 
1041
  string(REPLACE "../" "__/" bpath "${bpath}")
 
1042
  # Avoid spaces
 
1043
  string(REPLACE " " "_" bpath "${bpath}")
 
1044
 
 
1045
  # Strip off the filename.  I wait until here to do it, since removin the
 
1046
  # basename can make a path that looked like path/../basename turn into
 
1047
  # path/.. (notice the trailing slash).
 
1048
  get_filename_component(bpath "${bpath}" PATH)
 
1049
 
 
1050
  set(${build_path} "${bpath}" PARENT_SCOPE)
 
1051
  #message("${build_path} = ${bpath}")
 
1052
endfunction()
 
1053
 
 
1054
##############################################################################
 
1055
# This helper macro populates the following variables and setups up custom
 
1056
# commands and targets to invoke the nvcc compiler to generate C or PTX source
 
1057
# dependent upon the format parameter.  The compiler is invoked once with -M
 
1058
# to generate a dependency file and a second time with -cuda or -ptx to generate
 
1059
# a .cpp or .ptx file.
 
1060
# INPUT:
 
1061
#   cuda_target         - Target name
 
1062
#   format              - PTX, CUBIN, FATBIN or OBJ
 
1063
#   FILE1 .. FILEN      - The remaining arguments are the sources to be wrapped.
 
1064
#   OPTIONS             - Extra options to NVCC
 
1065
# OUTPUT:
 
1066
#   generated_files     - List of generated files
 
1067
##############################################################################
 
1068
##############################################################################
 
1069
 
 
1070
macro(CUDA_WRAP_SRCS cuda_target format generated_files)
 
1071
 
 
1072
  # If CMake doesn't support separable compilation, complain
 
1073
  if(CUDA_SEPARABLE_COMPILATION AND CMAKE_VERSION VERSION_LESS "2.8.10.1")
 
1074
    message(SEND_ERROR "CUDA_SEPARABLE_COMPILATION isn't supported for CMake versions less than 2.8.10.1")
 
1075
  endif()
 
1076
 
 
1077
  # Set up all the command line flags here, so that they can be overridden on a per target basis.
 
1078
 
 
1079
  set(nvcc_flags "")
 
1080
 
 
1081
  # Emulation if the card isn't present.
 
1082
  if (CUDA_BUILD_EMULATION)
 
1083
    # Emulation.
 
1084
    set(nvcc_flags ${nvcc_flags} --device-emulation -D_DEVICEEMU -g)
 
1085
  else()
 
1086
    # Device mode.  No flags necessary.
 
1087
  endif()
 
1088
 
 
1089
  if(CUDA_HOST_COMPILATION_CPP)
 
1090
    set(CUDA_C_OR_CXX CXX)
 
1091
  else()
 
1092
    if(CUDA_VERSION VERSION_LESS "3.0")
 
1093
      set(nvcc_flags ${nvcc_flags} --host-compilation C)
 
1094
    else()
 
1095
      message(WARNING "--host-compilation flag is deprecated in CUDA version >= 3.0.  Removing --host-compilation C flag" )
 
1096
    endif()
 
1097
    set(CUDA_C_OR_CXX C)
 
1098
  endif()
 
1099
 
 
1100
  set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION})
 
1101
 
 
1102
  if(CUDA_64_BIT_DEVICE_CODE)
 
1103
    set(nvcc_flags ${nvcc_flags} -m64)
 
1104
  else()
 
1105
    set(nvcc_flags ${nvcc_flags} -m32)
 
1106
  endif()
 
1107
 
 
1108
  if(CUDA_TARGET_CPU_ARCH AND CUDA_VERSION VERSION_LESS "7.0")
 
1109
    # CPU architecture is either ARM or X86. Patch AARCH64 to be ARM
 
1110
    string(REPLACE "AARCH64" "ARM" CUDA_TARGET_CPU_ARCH_patched ${CUDA_TARGET_CPU_ARCH})
 
1111
    set(nvcc_flags ${nvcc_flags} "--target-cpu-architecture=${CUDA_TARGET_CPU_ARCH_patched}")
 
1112
  endif()
 
1113
 
 
1114
  if(CUDA_TARGET_OS_VARIANT AND CUDA_VERSION VERSION_LESS "7.0")
 
1115
    set(nvcc_flags ${nvcc_flags} "-target-os-variant=${CUDA_TARGET_OS_VARIANT}")
 
1116
  endif()
 
1117
 
 
1118
  # This needs to be passed in at this stage, because VS needs to fill out the
 
1119
  # value of VCInstallDir from within VS.  Note that CCBIN is only used if
 
1120
  # -ccbin or --compiler-bindir isn't used and CUDA_HOST_COMPILER matches
 
1121
  # $(VCInstallDir)/bin.
 
1122
  if(CMAKE_GENERATOR MATCHES "Visual Studio")
 
1123
    set(ccbin_flags -D "\"CCBIN:PATH=$(VCInstallDir)bin\"" )
 
1124
  else()
 
1125
    set(ccbin_flags)
 
1126
  endif()
 
1127
 
 
1128
  # Figure out which configure we will use and pass that in as an argument to
 
1129
  # the script.  We need to defer the decision until compilation time, because
 
1130
  # for VS projects we won't know if we are making a debug or release build
 
1131
  # until build time.
 
1132
  if(CMAKE_GENERATOR MATCHES "Visual Studio")
 
1133
    set( CUDA_build_configuration "$(ConfigurationName)" )
 
1134
  else()
 
1135
    set( CUDA_build_configuration "${CMAKE_BUILD_TYPE}")
 
1136
  endif()
 
1137
 
 
1138
  # Initialize our list of includes with the user ones followed by the CUDA system ones.
 
1139
  set(CUDA_NVCC_INCLUDE_ARGS ${CUDA_NVCC_INCLUDE_ARGS_USER} "-I${CUDA_INCLUDE_DIRS}")
 
1140
  # Get the include directories for this directory and use them for our nvcc command.
 
1141
  # Remove duplicate entries which may be present since include_directories
 
1142
  # in CMake >= 2.8.8 does not remove them.
 
1143
  get_directory_property(CUDA_NVCC_INCLUDE_DIRECTORIES INCLUDE_DIRECTORIES)
 
1144
  list(REMOVE_DUPLICATES CUDA_NVCC_INCLUDE_DIRECTORIES)
 
1145
  if(CUDA_NVCC_INCLUDE_DIRECTORIES)
 
1146
    foreach(dir ${CUDA_NVCC_INCLUDE_DIRECTORIES})
 
1147
      list(APPEND CUDA_NVCC_INCLUDE_ARGS -I${dir})
 
1148
    endforeach()
 
1149
  endif()
 
1150
 
 
1151
  # Reset these variables
 
1152
  set(CUDA_WRAP_OPTION_NVCC_FLAGS)
 
1153
  foreach(config ${CUDA_configuration_types})
 
1154
    string(TOUPPER ${config} config_upper)
 
1155
    set(CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper})
 
1156
  endforeach()
 
1157
 
 
1158
  CUDA_GET_SOURCES_AND_OPTIONS(_cuda_wrap_sources _cuda_wrap_cmake_options _cuda_wrap_options ${ARGN})
 
1159
  CUDA_PARSE_NVCC_OPTIONS(CUDA_WRAP_OPTION_NVCC_FLAGS ${_cuda_wrap_options})
 
1160
 
 
1161
  # Figure out if we are building a shared library.  BUILD_SHARED_LIBS is
 
1162
  # respected in CUDA_ADD_LIBRARY.
 
1163
  set(_cuda_build_shared_libs FALSE)
 
1164
  # SHARED, MODULE
 
1165
  list(FIND _cuda_wrap_cmake_options SHARED _cuda_found_SHARED)
 
1166
  list(FIND _cuda_wrap_cmake_options MODULE _cuda_found_MODULE)
 
1167
  if(_cuda_found_SHARED GREATER -1 OR _cuda_found_MODULE GREATER -1)
 
1168
    set(_cuda_build_shared_libs TRUE)
 
1169
  endif()
 
1170
  # STATIC
 
1171
  list(FIND _cuda_wrap_cmake_options STATIC _cuda_found_STATIC)
 
1172
  if(_cuda_found_STATIC GREATER -1)
 
1173
    set(_cuda_build_shared_libs FALSE)
 
1174
  endif()
 
1175
 
 
1176
  # CUDA_HOST_FLAGS
 
1177
  if(_cuda_build_shared_libs)
 
1178
    # If we are setting up code for a shared library, then we need to add extra flags for
 
1179
    # compiling objects for shared libraries.
 
1180
    set(CUDA_HOST_SHARED_FLAGS ${CMAKE_SHARED_LIBRARY_${CUDA_C_OR_CXX}_FLAGS})
 
1181
  else()
 
1182
    set(CUDA_HOST_SHARED_FLAGS)
 
1183
  endif()
 
1184
  # Only add the CMAKE_{C,CXX}_FLAGS if we are propagating host flags.  We
 
1185
  # always need to set the SHARED_FLAGS, though.
 
1186
  if(CUDA_PROPAGATE_HOST_FLAGS)
 
1187
    set(_cuda_host_flags "set(CMAKE_HOST_FLAGS ${CMAKE_${CUDA_C_OR_CXX}_FLAGS} ${CUDA_HOST_SHARED_FLAGS})")
 
1188
  else()
 
1189
    set(_cuda_host_flags "set(CMAKE_HOST_FLAGS ${CUDA_HOST_SHARED_FLAGS})")
 
1190
  endif()
 
1191
 
 
1192
  set(_cuda_nvcc_flags_config "# Build specific configuration flags")
 
1193
  # Loop over all the configuration types to generate appropriate flags for run_nvcc.cmake
 
1194
  foreach(config ${CUDA_configuration_types})
 
1195
    string(TOUPPER ${config} config_upper)
 
1196
    # CMAKE_FLAGS are strings and not lists.  By not putting quotes around CMAKE_FLAGS
 
1197
    # we convert the strings to lists (like we want).
 
1198
 
 
1199
    if(CUDA_PROPAGATE_HOST_FLAGS)
 
1200
      # nvcc chokes on -g3 in versions previous to 3.0, so replace it with -g
 
1201
      set(_cuda_fix_g3 FALSE)
 
1202
 
 
1203
      if(CMAKE_COMPILER_IS_GNUCC)
 
1204
        if (CUDA_VERSION VERSION_LESS  "3.0" OR
 
1205
            CUDA_VERSION VERSION_EQUAL "4.1" OR
 
1206
            CUDA_VERSION VERSION_EQUAL "4.2"
 
1207
            )
 
1208
          set(_cuda_fix_g3 TRUE)
 
1209
        endif()
 
1210
      endif()
 
1211
      if(_cuda_fix_g3)
 
1212
        string(REPLACE "-g3" "-g" _cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}")
 
1213
      else()
 
1214
        set(_cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}")
 
1215
      endif()
 
1216
 
 
1217
      set(_cuda_host_flags "${_cuda_host_flags}\nset(CMAKE_HOST_FLAGS_${config_upper} ${_cuda_C_FLAGS})")
 
1218
    endif()
 
1219
 
 
1220
    # Note that if we ever want CUDA_NVCC_FLAGS_<CONFIG> to be string (instead of a list
 
1221
    # like it is currently), we can remove the quotes around the
 
1222
    # ${CUDA_NVCC_FLAGS_${config_upper}} variable like the CMAKE_HOST_FLAGS_<CONFIG> variable.
 
1223
    set(_cuda_nvcc_flags_config "${_cuda_nvcc_flags_config}\nset(CUDA_NVCC_FLAGS_${config_upper} ${CUDA_NVCC_FLAGS_${config_upper}} ;; ${CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper}})")
 
1224
  endforeach()
 
1225
 
 
1226
  # Get the list of definitions from the directory property
 
1227
  get_directory_property(CUDA_NVCC_DEFINITIONS COMPILE_DEFINITIONS)
 
1228
  if(CUDA_NVCC_DEFINITIONS)
 
1229
    foreach(_definition ${CUDA_NVCC_DEFINITIONS})
 
1230
      list(APPEND nvcc_flags "-D${_definition}")
 
1231
    endforeach()
 
1232
  endif()
 
1233
 
 
1234
  if(_cuda_build_shared_libs)
 
1235
    list(APPEND nvcc_flags "-D${cuda_target}_EXPORTS")
 
1236
  endif()
 
1237
 
 
1238
  # Reset the output variable
 
1239
  set(_cuda_wrap_generated_files "")
 
1240
 
 
1241
  # Iterate over the macro arguments and create custom
 
1242
  # commands for all the .cu files.
 
1243
  foreach(file ${ARGN})
 
1244
    # Ignore any file marked as a HEADER_FILE_ONLY
 
1245
    get_source_file_property(_is_header ${file} HEADER_FILE_ONLY)
 
1246
    if(${file} MATCHES "\\.cu$" AND NOT _is_header)
 
1247
 
 
1248
      # Allow per source file overrides of the format.
 
1249
      get_source_file_property(_cuda_source_format ${file} CUDA_SOURCE_PROPERTY_FORMAT)
 
1250
      if(NOT _cuda_source_format)
 
1251
        set(_cuda_source_format ${format})
 
1252
      endif()
 
1253
 
 
1254
      if( ${_cuda_source_format} MATCHES "OBJ")
 
1255
        set( cuda_compile_to_external_module OFF )
 
1256
      else()
 
1257
        set( cuda_compile_to_external_module ON )
 
1258
        if( ${_cuda_source_format} MATCHES "PTX" )
 
1259
          set( cuda_compile_to_external_module_type "ptx" )
 
1260
        elseif( ${_cuda_source_format} MATCHES "CUBIN")
 
1261
          set( cuda_compile_to_external_module_type "cubin" )
 
1262
        elseif( ${_cuda_source_format} MATCHES "FATBIN")
 
1263
          set( cuda_compile_to_external_module_type "fatbin" )
 
1264
        else()
 
1265
          message( FATAL_ERROR "Invalid format flag passed to CUDA_WRAP_SRCS for file '${file}': '${_cuda_source_format}'.  Use OBJ, PTX, CUBIN or FATBIN.")
 
1266
        endif()
 
1267
      endif()
 
1268
 
 
1269
      if(cuda_compile_to_external_module)
 
1270
        # Don't use any of the host compilation flags for PTX targets.
 
1271
        set(CUDA_HOST_FLAGS)
 
1272
        set(CUDA_NVCC_FLAGS_CONFIG)
 
1273
      else()
 
1274
        set(CUDA_HOST_FLAGS ${_cuda_host_flags})
 
1275
        set(CUDA_NVCC_FLAGS_CONFIG ${_cuda_nvcc_flags_config})
 
1276
      endif()
 
1277
 
 
1278
      # Determine output directory
 
1279
      cuda_compute_build_path("${file}" cuda_build_path)
 
1280
      set(cuda_compile_intermediate_directory "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${cuda_build_path}")
 
1281
      if(CUDA_GENERATED_OUTPUT_DIR)
 
1282
        set(cuda_compile_output_dir "${CUDA_GENERATED_OUTPUT_DIR}")
 
1283
      else()
 
1284
        if ( cuda_compile_to_external_module )
 
1285
          set(cuda_compile_output_dir "${CMAKE_CURRENT_BINARY_DIR}")
 
1286
        else()
 
1287
          set(cuda_compile_output_dir "${cuda_compile_intermediate_directory}")
 
1288
        endif()
 
1289
      endif()
 
1290
 
 
1291
      # Add a custom target to generate a c or ptx file. ######################
 
1292
 
 
1293
      get_filename_component( basename ${file} NAME )
 
1294
      if( cuda_compile_to_external_module )
 
1295
        set(generated_file_path "${cuda_compile_output_dir}")
 
1296
        set(generated_file_basename "${cuda_target}_generated_${basename}.${cuda_compile_to_external_module_type}")
 
1297
        set(format_flag "-${cuda_compile_to_external_module_type}")
 
1298
        file(MAKE_DIRECTORY "${cuda_compile_output_dir}")
 
1299
      else()
 
1300
        set(generated_file_path "${cuda_compile_output_dir}/${CMAKE_CFG_INTDIR}")
 
1301
        set(generated_file_basename "${cuda_target}_generated_${basename}${generated_extension}")
 
1302
        if(CUDA_SEPARABLE_COMPILATION)
 
1303
          set(format_flag "-dc")
 
1304
        else()
 
1305
          set(format_flag "-c")
 
1306
        endif()
 
1307
      endif()
 
1308
 
 
1309
      # Set all of our file names.  Make sure that whatever filenames that have
 
1310
      # generated_file_path in them get passed in through as a command line
 
1311
      # argument, so that the ${CMAKE_CFG_INTDIR} gets expanded at run time
 
1312
      # instead of configure time.
 
1313
      set(generated_file "${generated_file_path}/${generated_file_basename}")
 
1314
      set(cmake_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.depend")
 
1315
      set(NVCC_generated_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.NVCC-depend")
 
1316
      set(generated_cubin_file "${generated_file_path}/${generated_file_basename}.cubin.txt")
 
1317
      set(custom_target_script "${cuda_compile_intermediate_directory}/${generated_file_basename}.cmake")
 
1318
 
 
1319
      # Setup properties for obj files:
 
1320
      if( NOT cuda_compile_to_external_module )
 
1321
        set_source_files_properties("${generated_file}"
 
1322
          PROPERTIES
 
1323
          EXTERNAL_OBJECT true # This is an object file not to be compiled, but only be linked.
 
1324
          )
 
1325
      endif()
 
1326
 
 
1327
      # Don't add CMAKE_CURRENT_SOURCE_DIR if the path is already an absolute path.
 
1328
      get_filename_component(file_path "${file}" PATH)
 
1329
      if(IS_ABSOLUTE "${file_path}")
 
1330
        set(source_file "${file}")
 
1331
      else()
 
1332
        set(source_file "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
 
1333
      endif()
 
1334
 
 
1335
      if( NOT cuda_compile_to_external_module AND CUDA_SEPARABLE_COMPILATION)
 
1336
        list(APPEND ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS "${generated_file}")
 
1337
      endif()
 
1338
 
 
1339
      # Bring in the dependencies.  Creates a variable CUDA_NVCC_DEPEND #######
 
1340
      cuda_include_nvcc_dependencies(${cmake_dependency_file})
 
1341
 
 
1342
      # Convience string for output ###########################################
 
1343
      if(CUDA_BUILD_EMULATION)
 
1344
        set(cuda_build_type "Emulation")
 
1345
      else()
 
1346
        set(cuda_build_type "Device")
 
1347
      endif()
 
1348
 
 
1349
      # Build the NVCC made dependency file ###################################
 
1350
      set(build_cubin OFF)
 
1351
      if ( NOT CUDA_BUILD_EMULATION AND CUDA_BUILD_CUBIN )
 
1352
         if ( NOT cuda_compile_to_external_module )
 
1353
           set ( build_cubin ON )
 
1354
         endif()
 
1355
      endif()
 
1356
 
 
1357
      # Configure the build script
 
1358
      configure_file("${CUDA_run_nvcc}" "${custom_target_script}" @ONLY)
 
1359
 
 
1360
      # So if a user specifies the same cuda file as input more than once, you
 
1361
      # can have bad things happen with dependencies.  Here we check an option
 
1362
      # to see if this is the behavior they want.
 
1363
      if(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE)
 
1364
        set(main_dep MAIN_DEPENDENCY ${source_file})
 
1365
      else()
 
1366
        set(main_dep DEPENDS ${source_file})
 
1367
      endif()
 
1368
 
 
1369
      if(CUDA_VERBOSE_BUILD)
 
1370
        set(verbose_output ON)
 
1371
      elseif(CMAKE_GENERATOR MATCHES "Makefiles")
 
1372
        set(verbose_output "$(VERBOSE)")
 
1373
      else()
 
1374
        set(verbose_output OFF)
 
1375
      endif()
 
1376
 
 
1377
      # Create up the comment string
 
1378
      file(RELATIVE_PATH generated_file_relative_path "${CMAKE_BINARY_DIR}" "${generated_file}")
 
1379
      if(cuda_compile_to_external_module)
 
1380
        set(cuda_build_comment_string "Building NVCC ${cuda_compile_to_external_module_type} file ${generated_file_relative_path}")
 
1381
      else()
 
1382
        set(cuda_build_comment_string "Building NVCC (${cuda_build_type}) object ${generated_file_relative_path}")
 
1383
      endif()
 
1384
 
 
1385
      # Build the generated file and dependency file ##########################
 
1386
      add_custom_command(
 
1387
        OUTPUT ${generated_file}
 
1388
        # These output files depend on the source_file and the contents of cmake_dependency_file
 
1389
        ${main_dep}
 
1390
        DEPENDS ${CUDA_NVCC_DEPEND}
 
1391
        DEPENDS ${custom_target_script}
 
1392
        # Make sure the output directory exists before trying to write to it.
 
1393
        COMMAND ${CMAKE_COMMAND} -E make_directory "${generated_file_path}"
 
1394
        COMMAND ${CMAKE_COMMAND} ARGS
 
1395
          -D verbose:BOOL=${verbose_output}
 
1396
          ${ccbin_flags}
 
1397
          -D build_configuration:STRING=${CUDA_build_configuration}
 
1398
          -D "generated_file:STRING=${generated_file}"
 
1399
          -D "generated_cubin_file:STRING=${generated_cubin_file}"
 
1400
          -P "${custom_target_script}"
 
1401
        WORKING_DIRECTORY "${cuda_compile_intermediate_directory}"
 
1402
        COMMENT "${cuda_build_comment_string}"
 
1403
        )
 
1404
 
 
1405
      # Make sure the build system knows the file is generated.
 
1406
      set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE)
 
1407
 
 
1408
      list(APPEND _cuda_wrap_generated_files ${generated_file})
 
1409
 
 
1410
      # Add the other files that we want cmake to clean on a cleanup ##########
 
1411
      list(APPEND CUDA_ADDITIONAL_CLEAN_FILES "${cmake_dependency_file}")
 
1412
      list(REMOVE_DUPLICATES CUDA_ADDITIONAL_CLEAN_FILES)
 
1413
      set(CUDA_ADDITIONAL_CLEAN_FILES ${CUDA_ADDITIONAL_CLEAN_FILES} CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.")
 
1414
 
 
1415
    endif()
 
1416
  endforeach()
 
1417
 
 
1418
  # Set the return parameter
 
1419
  set(${generated_files} ${_cuda_wrap_generated_files})
 
1420
endmacro()
 
1421
 
 
1422
function(_cuda_get_important_host_flags important_flags flag_string)
 
1423
  if(CMAKE_GENERATOR MATCHES "Visual Studio")
 
1424
    string(REGEX MATCHALL "/M[DT][d]?" flags ${flag_string})
 
1425
    list(APPEND ${important_flags} ${flags})
 
1426
  else()
 
1427
    string(REGEX MATCHALL "-fPIC" flags ${flag_string})
 
1428
    list(APPEND ${important_flags} ${flags})
 
1429
  endif()
 
1430
  set(${important_flags} ${${important_flags}} PARENT_SCOPE)
 
1431
endfunction()
 
1432
 
 
1433
###############################################################################
 
1434
###############################################################################
 
1435
# Separable Compilation Link
 
1436
###############################################################################
 
1437
###############################################################################
 
1438
 
 
1439
# Compute the filename to be used by CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS
 
1440
function(CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME output_file_var cuda_target object_files)
 
1441
  if (object_files)
 
1442
    set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION})
 
1443
    set(output_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${CMAKE_CFG_INTDIR}/${cuda_target}_intermediate_link${generated_extension}")
 
1444
  else()
 
1445
    set(output_file)
 
1446
  endif()
 
1447
 
 
1448
  set(${output_file_var} "${output_file}" PARENT_SCOPE)
 
1449
endfunction()
 
1450
 
 
1451
# Setup the build rule for the separable compilation intermediate link file.
 
1452
function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options object_files)
 
1453
  if (object_files)
 
1454
 
 
1455
    set_source_files_properties("${output_file}"
 
1456
      PROPERTIES
 
1457
      EXTERNAL_OBJECT TRUE # This is an object file not to be compiled, but only
 
1458
                           # be linked.
 
1459
      GENERATED TRUE       # This file is generated during the build
 
1460
      )
 
1461
 
 
1462
    # For now we are ignoring all the configuration specific flags.
 
1463
    set(nvcc_flags)
 
1464
    CUDA_PARSE_NVCC_OPTIONS(nvcc_flags ${options})
 
1465
    if(CUDA_64_BIT_DEVICE_CODE)
 
1466
      list(APPEND nvcc_flags -m64)
 
1467
    else()
 
1468
      list(APPEND nvcc_flags -m32)
 
1469
    endif()
 
1470
    # If -ccbin, --compiler-bindir has been specified, don't do anything.  Otherwise add it here.
 
1471
    list( FIND nvcc_flags "-ccbin" ccbin_found0 )
 
1472
    list( FIND nvcc_flags "--compiler-bindir" ccbin_found1 )
 
1473
    if( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 AND CUDA_HOST_COMPILER )
 
1474
      list(APPEND nvcc_flags -ccbin "\"${CUDA_HOST_COMPILER}\"")
 
1475
    endif()
 
1476
    # Create a list of flags specified by CUDA_NVCC_FLAGS_${CONFIG}
 
1477
    set(config_specific_flags)
 
1478
    set(flags)
 
1479
    foreach(config ${CUDA_configuration_types})
 
1480
      string(TOUPPER ${config} config_upper)
 
1481
      # Add config specific flags
 
1482
      foreach(f ${CUDA_NVCC_FLAGS_${config_upper}})
 
1483
        list(APPEND config_specific_flags $<$<CONFIG:${config}>:${f}>)
 
1484
      endforeach()
 
1485
      set(important_host_flags)
 
1486
      _cuda_get_important_host_flags(important_host_flags ${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}})
 
1487
      foreach(f ${important_host_flags})
 
1488
        list(APPEND flags $<$<CONFIG:${config}>:-Xcompiler> $<$<CONFIG:${config}>:${f}>)
 
1489
      endforeach()
 
1490
    endforeach()
 
1491
    # Add our general CUDA_NVCC_FLAGS with the configuration specifig flags
 
1492
    set(nvcc_flags ${CUDA_NVCC_FLAGS} ${config_specific_flags} ${nvcc_flags})
 
1493
 
 
1494
    file(RELATIVE_PATH output_file_relative_path "${CMAKE_BINARY_DIR}" "${output_file}")
 
1495
 
 
1496
    # Some generators don't handle the multiple levels of custom command
 
1497
    # dependencies correctly (obj1 depends on file1, obj2 depends on obj1), so
 
1498
    # we work around that issue by compiling the intermediate link object as a
 
1499
    # pre-link custom command in that situation.
 
1500
    set(do_obj_build_rule TRUE)
 
1501
    if (MSVC_VERSION GREATER 1599)
 
1502
      # VS 2010 and 2012 have this problem.  If future versions fix this issue,
 
1503
      # it should still work, it just won't be as nice as the other method.
 
1504
      set(do_obj_build_rule FALSE)
 
1505
    endif()
 
1506
 
 
1507
    if (do_obj_build_rule)
 
1508
      add_custom_command(
 
1509
        OUTPUT ${output_file}
 
1510
        DEPENDS ${object_files}
 
1511
        COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file}
 
1512
        ${flags}
 
1513
        COMMENT "Building NVCC intermediate link file ${output_file_relative_path}"
 
1514
        )
 
1515
    else()
 
1516
      add_custom_command(
 
1517
        TARGET ${cuda_target}
 
1518
        PRE_LINK
 
1519
        COMMAND ${CMAKE_COMMAND} -E echo "Building NVCC intermediate link file ${output_file_relative_path}"
 
1520
        COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} ${flags} -dlink ${object_files} -o "${output_file}"
 
1521
        )
 
1522
    endif()
 
1523
 endif()
 
1524
endfunction()
 
1525
 
 
1526
###############################################################################
 
1527
###############################################################################
 
1528
# ADD LIBRARY
 
1529
###############################################################################
 
1530
###############################################################################
 
1531
macro(CUDA_ADD_LIBRARY cuda_target)
 
1532
 
 
1533
  CUDA_ADD_CUDA_INCLUDE_ONCE()
 
1534
 
 
1535
  # Separate the sources from the options
 
1536
  CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
 
1537
  CUDA_BUILD_SHARED_LIBRARY(_cuda_shared_flag ${ARGN})
 
1538
  # Create custom commands and targets for each file.
 
1539
  CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources}
 
1540
    ${_cmake_options} ${_cuda_shared_flag}
 
1541
    OPTIONS ${_options} )
 
1542
 
 
1543
  # Compute the file name of the intermedate link file used for separable
 
1544
  # compilation.
 
1545
  CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME(link_file ${cuda_target} "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}")
 
1546
 
 
1547
  # Add the library.
 
1548
  add_library(${cuda_target} ${_cmake_options}
 
1549
    ${_generated_files}
 
1550
    ${_sources}
 
1551
    ${link_file}
 
1552
    )
 
1553
 
 
1554
  # Add a link phase for the separable compilation if it has been enabled.  If
 
1555
  # it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS
 
1556
  # variable will have been defined.
 
1557
  CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}")
 
1558
 
 
1559
  target_link_libraries(${cuda_target}
 
1560
    ${CUDA_LIBRARIES}
 
1561
    )
 
1562
 
 
1563
  # We need to set the linker language based on what the expected generated file
 
1564
  # would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP.
 
1565
  set_target_properties(${cuda_target}
 
1566
    PROPERTIES
 
1567
    LINKER_LANGUAGE ${CUDA_C_OR_CXX}
 
1568
    )
 
1569
 
 
1570
endmacro()
 
1571
 
 
1572
 
 
1573
###############################################################################
 
1574
###############################################################################
 
1575
# ADD EXECUTABLE
 
1576
###############################################################################
 
1577
###############################################################################
 
1578
macro(CUDA_ADD_EXECUTABLE cuda_target)
 
1579
 
 
1580
  CUDA_ADD_CUDA_INCLUDE_ONCE()
 
1581
 
 
1582
  # Separate the sources from the options
 
1583
  CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
 
1584
  # Create custom commands and targets for each file.
 
1585
  CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources} OPTIONS ${_options} )
 
1586
 
 
1587
  # Compute the file name of the intermedate link file used for separable
 
1588
  # compilation.
 
1589
  CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME(link_file ${cuda_target} "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}")
 
1590
 
 
1591
  # Add the library.
 
1592
  add_executable(${cuda_target} ${_cmake_options}
 
1593
    ${_generated_files}
 
1594
    ${_sources}
 
1595
    ${link_file}
 
1596
    )
 
1597
 
 
1598
  # Add a link phase for the separable compilation if it has been enabled.  If
 
1599
  # it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS
 
1600
  # variable will have been defined.
 
1601
  CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}")
 
1602
 
 
1603
  target_link_libraries(${cuda_target}
 
1604
    ${CUDA_LIBRARIES}
 
1605
    )
 
1606
 
 
1607
  # We need to set the linker language based on what the expected generated file
 
1608
  # would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP.
 
1609
  set_target_properties(${cuda_target}
 
1610
    PROPERTIES
 
1611
    LINKER_LANGUAGE ${CUDA_C_OR_CXX}
 
1612
    )
 
1613
 
 
1614
endmacro()
 
1615
 
 
1616
 
 
1617
###############################################################################
 
1618
###############################################################################
 
1619
# (Internal) helper for manually added cuda source files with specific targets
 
1620
###############################################################################
 
1621
###############################################################################
 
1622
macro(cuda_compile_base cuda_target format generated_files)
 
1623
 
 
1624
  # Separate the sources from the options
 
1625
  CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
 
1626
  # Create custom commands and targets for each file.
 
1627
  CUDA_WRAP_SRCS( ${cuda_target} ${format} _generated_files ${_sources} ${_cmake_options}
 
1628
    OPTIONS ${_options} )
 
1629
 
 
1630
  set( ${generated_files} ${_generated_files})
 
1631
 
 
1632
endmacro()
 
1633
 
 
1634
###############################################################################
 
1635
###############################################################################
 
1636
# CUDA COMPILE
 
1637
###############################################################################
 
1638
###############################################################################
 
1639
macro(CUDA_COMPILE generated_files)
 
1640
  cuda_compile_base(cuda_compile OBJ ${generated_files} ${ARGN})
 
1641
endmacro()
 
1642
 
 
1643
###############################################################################
 
1644
###############################################################################
 
1645
# CUDA COMPILE PTX
 
1646
###############################################################################
 
1647
###############################################################################
 
1648
macro(CUDA_COMPILE_PTX generated_files)
 
1649
  cuda_compile_base(cuda_compile_ptx PTX ${generated_files} ${ARGN})
 
1650
endmacro()
 
1651
 
 
1652
###############################################################################
 
1653
###############################################################################
 
1654
# CUDA COMPILE FATBIN
 
1655
###############################################################################
 
1656
###############################################################################
 
1657
macro(CUDA_COMPILE_FATBIN generated_files)
 
1658
  cuda_compile_base(cuda_compile_fatbin FATBIN ${generated_files} ${ARGN})
 
1659
endmacro()
 
1660
 
 
1661
###############################################################################
 
1662
###############################################################################
 
1663
# CUDA COMPILE CUBIN
 
1664
###############################################################################
 
1665
###############################################################################
 
1666
macro(CUDA_COMPILE_CUBIN generated_files)
 
1667
  cuda_compile_base(cuda_compile_cubin CUBIN ${generated_files} ${ARGN})
 
1668
endmacro()
 
1669
 
 
1670
 
 
1671
###############################################################################
 
1672
###############################################################################
 
1673
# CUDA ADD CUFFT TO TARGET
 
1674
###############################################################################
 
1675
###############################################################################
 
1676
macro(CUDA_ADD_CUFFT_TO_TARGET target)
 
1677
  if (CUDA_BUILD_EMULATION)
 
1678
    target_link_libraries(${target} ${CUDA_cufftemu_LIBRARY})
 
1679
  else()
 
1680
    target_link_libraries(${target} ${CUDA_cufft_LIBRARY})
 
1681
  endif()
 
1682
endmacro()
 
1683
 
 
1684
###############################################################################
 
1685
###############################################################################
 
1686
# CUDA ADD CUBLAS TO TARGET
 
1687
###############################################################################
 
1688
###############################################################################
 
1689
macro(CUDA_ADD_CUBLAS_TO_TARGET target)
 
1690
  if (CUDA_BUILD_EMULATION)
 
1691
    target_link_libraries(${target} ${CUDA_cublasemu_LIBRARY})
 
1692
  else()
 
1693
    target_link_libraries(${target} ${CUDA_cublas_LIBRARY})
 
1694
  endif()
 
1695
endmacro()
 
1696
 
 
1697
###############################################################################
 
1698
###############################################################################
 
1699
# CUDA BUILD CLEAN TARGET
 
1700
###############################################################################
 
1701
###############################################################################
 
1702
macro(CUDA_BUILD_CLEAN_TARGET)
 
1703
  # Call this after you add all your CUDA targets, and you will get a convience
 
1704
  # target.  You should also make clean after running this target to get the
 
1705
  # build system to generate all the code again.
 
1706
 
 
1707
  set(cuda_clean_target_name clean_cuda_depends)
 
1708
  if (CMAKE_GENERATOR MATCHES "Visual Studio")
 
1709
    string(TOUPPER ${cuda_clean_target_name} cuda_clean_target_name)
 
1710
  endif()
 
1711
  add_custom_target(${cuda_clean_target_name}
 
1712
    COMMAND ${CMAKE_COMMAND} -E remove ${CUDA_ADDITIONAL_CLEAN_FILES})
 
1713
 
 
1714
  # Clear out the variable, so the next time we configure it will be empty.
 
1715
  # This is useful so that the files won't persist in the list after targets
 
1716
  # have been removed.
 
1717
  set(CUDA_ADDITIONAL_CLEAN_FILES "" CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.")
 
1718
endmacro()