~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to cmake/modules/FindCuda.cmake

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###############################################################################
 
2
#  For more information, please see: http://software.sci.utah.edu
 
3
#
 
4
#  The MIT License
 
5
#
 
6
#  Copyright (c) 2007-2008
 
7
#  Scientific Computing and Imaging Institute, University of Utah
 
8
#
 
9
#  License for the specific language governing rights and limitations under
 
10
#  Permission is hereby granted, free of charge, to any person obtaining a
 
11
#  copy of this software and associated documentation files (the "Software"),
 
12
#  to deal in the Software without restriction, including without limitation
 
13
#  the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
14
#  and/or sell copies of the Software, and to permit persons to whom the
 
15
#  Software is furnished to do so, subject to the following conditions:
 
16
#
 
17
#  The above copyright notice and this permission notice shall be included
 
18
#  in all copies or substantial portions of the Software.
 
19
#
 
20
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
21
#  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
22
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
23
#  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
24
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
25
#  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
26
#  DEALINGS IN THE SOFTWARE.
 
27
#
 
28
# This script locates the Nvidia Compute Unified Driver Architecture (CUDA) 
 
29
# tools. It should work on linux, windows, and mac and should be reasonably 
 
30
# up to date with cuda releases.
 
31
#
 
32
# The script will prompt the user to specify CUDA_INSTALL_PREFIX if the 
 
33
# prefix cannot be determined by the location of nvcc in the system path. To
 
34
# use a different installed version of the toolkit set the environment variable
 
35
# CUDA_BIN_PATH before running cmake (e.g. CUDA_BIN_PATH=/usr/local/cuda1.0 
 
36
# instead of the default /usr/local/cuda).
 
37
#
 
38
# Set MT_CUDA_BUILD_TYPE to "Device" or "Emulation" mode.
 
39
# _DEVICEEMU is defined in "Emulation" mode.
 
40
#
 
41
# Set CUDA_BUILD_CUBIN to "ON" or "OFF" to enable and extra compilation pass
 
42
# with the -cubin option in Device mode. The output is parsed and register, 
 
43
# shared memory usage is printed during build. Default ON.
 
44
 
45
# The script creates the following macros:
 
46
# CUDA_INCLUDE_DIRECTORIES( path0 path1 ... )
 
47
# -- Sets the directories that should be passed to nvcc 
 
48
#    (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu 
 
49
#    files.
 
50
 
51
# CUDA_ADD_LIBRARY( cuda_target file0 file1 ... )
 
52
# -- Creates a shared library "cuda_target" which contains all of the source 
 
53
#    (*.c, *.cc, etc.) specified and all of the nvcc'ed .cu files specified.
 
54
#    All of the specified source files and generated .cpp files are compiled 
 
55
#    using the standard CMake compiler, so the normal INCLUDE_DIRECTORIES, 
 
56
#    LINK_DIRECTORIES, and TARGET_LINK_LIBRARIES can be used to affect their
 
57
#    build and link.
 
58
#
 
59
# CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ... )
 
60
# -- Same as CUDA_ADD_LIBRARY except that an exectuable is created.
 
61
#
 
62
# CUDA_COMPILE( cuda_files file0 file1 ... )
 
63
# -- Returns a list of build commands in the first argument to be used with 
 
64
#    ADD_LIBRARY or ADD_EXECUTABLE.
 
65
 
66
# The script defines the following variables:
 
67
#
 
68
# ( Note CUDA_ADD_* macros setup cuda/cut library dependencies automatically. 
 
69
# These variables are only needed if a cuda API call must be made from code in 
 
70
# a outside library or executable. )
 
71
#
 
72
# CUDA_INCLUDE         -- Include directory for cuda headers.
 
73
# CUDA_TARGET_LINK     -- Cuda RT library. 
 
74
# CUDA_CUT_INCLUDE     -- Include directory for cuda SDK headers (cutil.h).   
 
75
# CUDA_CUT_TARGET_LINK -- SDK libraries.
 
76
# CUDA_NVCC_FLAGS      -- Additional NVCC command line arguments. NOTE: 
 
77
#                         multiple arguments must be semi-colon delimited 
 
78
#                         e.g. --compiler-options;-Wall
 
79
# CUBLAS_TARGET_LINK-- cublas library name.
 
80
# CUFFT_TARGET_LINK -- cubfft library name.
 
81
 
82
# The nvcc flag "--host-compilation;c++" should be used if functions declared
 
83
# as __host__ contain C++ code.
 
84
#
 
85
# It might be necessary to set CUDA_INSTALL_PATH manually on certain platforms,
 
86
# or to use a cuda runtime not installed in the default location. In newer 
 
87
# versions of the toolkit the cuda library is included with the graphics 
 
88
# driver- be sure that the driver version matches what is needed by the cuda 
 
89
# runtime version.
 
90
 
91
# -- Abe Stephens SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
 
92
###############################################################################
 
93
 
 
94
# FindCuda.cmake
 
95
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
 
96
 
 
97
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/CudaDependency.cmake)
 
98
 
 
99
###############################################################################
 
100
###############################################################################
 
101
# Locate CUDA, Set Build Type, etc.
 
102
###############################################################################
 
103
###############################################################################
 
104
 
 
105
# Parse CUDA build type.
 
106
IF (NOT MT_CUDA_BUILD_TYPE)
 
107
  SET(MT_CUDA_BUILD_TYPE "Device" CACHE STRING "Cuda build type: Emulation or Device")
 
108
ENDIF(NOT MT_CUDA_BUILD_TYPE)
 
109
 
 
110
# Emulation if the card isn't present.
 
111
IF (MT_CUDA_BUILD_TYPE MATCHES "Emulation")
 
112
  # Emulation.
 
113
  SET(nvcc_flags --device-emulation -D_DEVICEEMU -g)
 
114
ELSE(MT_CUDA_BUILD_TYPE MATCHES "Emulation")
 
115
  # Device present.
 
116
  SET(nvcc_flags "")
 
117
ENDIF(MT_CUDA_BUILD_TYPE MATCHES "Emulation")
 
118
 
 
119
SET(CUDA_BUILD_CUBIN TRUE CACHE BOOL "Generate and parse .cubin files in Device mode.")
 
120
SET(CUDA_NVCC_FLAGS "" CACHE STRING "Semi-colon delimit multiple arguments.")
 
121
 
 
122
# Search for the cuda distribution.
 
123
IF(NOT CUDA_INSTALL_PREFIX)
 
124
  FIND_PATH(CUDA_INSTALL_PREFIX
 
125
    NAMES nvcc
 
126
    PATHS /usr/local/cuda
 
127
    PATH_SUFFIXES bin
 
128
    ENV CUDA_BIN_PATH
 
129
    DOC "Toolkit location."
 
130
    )
 
131
  IF (CUDA_INSTALL_PREFIX) 
 
132
    STRING(REGEX REPLACE "[/\\\\]?bin[/\\\\]?$" "" CUDA_INSTALL_PREFIX ${CUDA_INSTALL_PREFIX})
 
133
  ENDIF(CUDA_INSTALL_PREFIX)
 
134
  IF (NOT EXISTS ${CUDA_INSTALL_PREFIX})
 
135
    MESSAGE(FATAL_ERROR "Specify CUDA_INSTALL_PREFIX")
 
136
  ENDIF (NOT EXISTS ${CUDA_INSTALL_PREFIX})
 
137
ENDIF (NOT CUDA_INSTALL_PREFIX)
 
138
 
 
139
# CUDA_NVCC
 
140
IF (NOT CUDA_NVCC)
 
141
  FIND_PROGRAM(CUDA_NVCC 
 
142
    nvcc
 
143
    PATHS ${CUDA_INSTALL_PREFIX}/bin $ENV{CUDA_BIN_PATH}
 
144
    )
 
145
  IF(NOT CUDA_NVCC)
 
146
    MESSAGE(FATAL_ERROR "Could not find nvcc")
 
147
  ELSE(NOT CUDA_NVCC)
 
148
    MARK_AS_ADVANCED(CUDA_NVCC)
 
149
  ENDIF(NOT CUDA_NVCC)
 
150
ENDIF(NOT CUDA_NVCC)
 
151
 
 
152
# CUDA_NVCC_INCLUDE_ARGS
 
153
# IF (NOT FOUND_CUDA_NVCC_INCLUDE)
 
154
  FIND_PATH(FOUND_CUDA_NVCC_INCLUDE
 
155
    device_functions.h # Header included in toolkit
 
156
    PATHS ${CUDA_INSTALL_PREFIX}/include 
 
157
          $ENV{CUDA_INC_PATH}
 
158
    )
 
159
  
 
160
  IF(NOT FOUND_CUDA_NVCC_INCLUDE)
 
161
    MESSAGE(FATAL_ERROR "Could not find Cuda headers")
 
162
  ELSE(NOT FOUND_CUDA_NVCC_INCLUDE)
 
163
    # Set the initial include dir.
 
164
    SET (CUDA_NVCC_INCLUDE_ARGS "-I"${FOUND_CUDA_NVCC_INCLUDE})
 
165
        SET (CUDA_INCLUDE ${FOUND_CUDA_NVCC_INCLUDE})
 
166
 
 
167
    MARK_AS_ADVANCED(
 
168
      FOUND_CUDA_NVCC_INCLUDE
 
169
      CUDA_NVCC_INCLUDE_ARGS
 
170
      )
 
171
  ENDIF(NOT FOUND_CUDA_NVCC_INCLUDE)
 
172
  
 
173
# ENDIF(NOT FOUND_CUDA_NVCC_INCLUDE)
 
174
 
 
175
  
 
176
# CUDA_TARGET_LINK
 
177
IF (NOT CUDA_TARGET_LINK)
 
178
 
 
179
  FIND_LIBRARY(FOUND_CUDART
 
180
    cudart
 
181
    PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
 
182
    DOC "\"cudart\" library"
 
183
    )
 
184
  
 
185
  # Check to see if cudart library was found.
 
186
  IF(NOT FOUND_CUDART)
 
187
    MESSAGE(FATAL_ERROR "Could not find cudart library (cudart)")
 
188
  ENDIF(NOT FOUND_CUDART)  
 
189
 
 
190
  # 1.1 toolkit on linux doesn't appear to have a separate library on 
 
191
  # some platforms.
 
192
  FIND_LIBRARY(FOUND_CUDA
 
193
    cuda
 
194
    PATHS ${CUDA_INSTALL_PREFIX}/lib
 
195
    DOC "\"cuda\" library (older versions only)."
 
196
    NO_DEFAULT_PATH
 
197
    NO_CMAKE_ENVIRONMENT_PATH
 
198
    NO_CMAKE_PATH
 
199
    NO_SYSTEM_ENVIRONMENT_PATH
 
200
    NO_CMAKE_SYSTEM_PATH
 
201
    )
 
202
 
 
203
  # Add cuda library to the link line only if it is found.
 
204
  IF (FOUND_CUDA)
 
205
    SET(CUDA_TARGET_LINK ${FOUND_CUDA})
 
206
  ENDIF(FOUND_CUDA)
 
207
 
 
208
  # Always add cudart to the link line.
 
209
  IF(FOUND_CUDART)
 
210
    SET(CUDA_TARGET_LINK
 
211
      ${CUDA_TARGET_LINK} ${FOUND_CUDART}
 
212
      )
 
213
    MARK_AS_ADVANCED(
 
214
      CUDA_TARGET_LINK 
 
215
      CUDA_LIB
 
216
      FOUND_CUDA
 
217
      FOUND_CUDART
 
218
      )
 
219
  ELSE(FOUND_CUDART)
 
220
    MESSAGE(FATAL_ERROR "Could not find cuda libraries.")
 
221
  ENDIF(FOUND_CUDART)
 
222
  
 
223
ENDIF(NOT CUDA_TARGET_LINK)
 
224
 
 
225
# CUDA_CUT_INCLUDE
 
226
IF(NOT CUDA_CUT_INCLUDE)
 
227
  FIND_PATH(FOUND_CUT_INCLUDE
 
228
    cutil.h
 
229
    PATHS ${CUDA_INSTALL_PREFIX}/local/NVSDK0.2/common/inc
 
230
          ${CUDA_INSTALL_PREFIX}/NVSDK0.2/common/inc
 
231
          ${CUDA_INSTALL_PREFIX}/NV_CUDA_SDK/common/inc
 
232
          $ENV{HOME}/NVIDIA_CUDA_SDK/common/inc
 
233
          $ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX/common/inc
 
234
          $ENV{NVSDKCUDA_ROOT}/common/inc
 
235
    DOC "Location of cutil.h"
 
236
    )
 
237
  IF(FOUND_CUT_INCLUDE)
 
238
    SET(CUDA_CUT_INCLUDE ${FOUND_CUT_INCLUDE})
 
239
    MARK_AS_ADVANCED(
 
240
      FOUND_CUT_INCLUDE
 
241
      )
 
242
  ENDIF(FOUND_CUT_INCLUDE)
 
243
ENDIF(NOT CUDA_CUT_INCLUDE)
 
244
 
 
245
 
 
246
# CUDA_CUT_TARGET_LINK
 
247
IF(NOT CUDA_CUT_TARGET_LINK)
 
248
  FIND_LIBRARY(FOUND_CUT
 
249
    cutil
 
250
    cutil32
 
251
    PATHS ${CUDA_INSTALL_PREFIX}/local/NVSDK0.2/lib
 
252
          ${CUDA_INSTALL_PREFIX}/NVSDK0.2/lib
 
253
          ${CUDA_INSTALL_PREFIX}/NV_CUDA_SDK/lib
 
254
          $ENV{HOME}/NVIDIA_CUDA_SDK/lib
 
255
          $ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX/lib
 
256
          $ENV{NVSDKCUDA_ROOT}/common/lib
 
257
    NO_DEFAULT_PATH
 
258
    NO_CMAKE_ENVIRONMENT_PATH
 
259
    NO_CMAKE_PATH
 
260
    NO_SYSTEM_ENVIRONMENT_PATH
 
261
    NO_CMAKE_SYSTEM_PATH
 
262
    DOC "Location of cutil library"
 
263
    )
 
264
  IF(FOUND_CUT)
 
265
    SET(CUDA_CUT_TARGET_LINK ${FOUND_CUT})
 
266
    MARK_AS_ADVANCED(
 
267
      FOUND_CUT
 
268
      )
 
269
  ENDIF(FOUND_CUT)
 
270
 
 
271
# Add variables for cufft and cublas target link
 
272
FIND_LIBRARY(FOUND_CUFFTEMU
 
273
  cufftemu
 
274
  PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
 
275
  DOC "\"cufftemu\" library"
 
276
  )
 
277
FIND_LIBRARY(FOUND_CUBLASEMU
 
278
  cublasemu
 
279
  PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
 
280
  DOC "\"cublasemu\" library"
 
281
  )
 
282
FIND_LIBRARY(FOUND_CUFFT
 
283
  cufft
 
284
  PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
 
285
  DOC "\"cufft\" library"
 
286
  )
 
287
FIND_LIBRARY(FOUND_CUBLAS
 
288
  cublas
 
289
  PATHS ${CUDA_INSTALL_PREFIX}/lib $ENV{CUDA_LIB_PATH}
 
290
  DOC "\"cublas\" library"
 
291
  )
 
292
 
 
293
IF (MT_CUDA_BUILD_TYPE MATCHES "Emulation")
 
294
  SET(CUFFT_TARGET_LINK  ${FOUND_CUFFTEMU})
 
295
  SET(CUBLAS_TARGET_LINK ${FOUND_CUBLASEMU})
 
296
ELSE(MT_CUDA_BUILD_TYPE MATCHES "Emulation")
 
297
  SET(CUFFT_TARGET_LINK  ${FOUND_CUFFT})
 
298
  SET(CUBLAS_TARGET_LINK ${FOUND_CUBLAS})
 
299
ENDIF(MT_CUDA_BUILD_TYPE MATCHES "Emulation")
 
300
 
 
301
 
 
302
 
 
303
 
 
304
ENDIF(NOT CUDA_CUT_TARGET_LINK)
 
305
 
 
306
 
 
307
###############################################################################
 
308
# Add include directories to pass to the nvcc command.
 
309
MACRO(CUDA_INCLUDE_DIRECTORIES)
 
310
  FOREACH(dir ${ARGN})
 
311
    SET(CUDA_NVCC_INCLUDE_ARGS ${CUDA_NVCC_INCLUDE_ARGS} -I${dir})
 
312
  ENDFOREACH(dir ${ARGN})
 
313
ENDMACRO(CUDA_INCLUDE_DIRECTORIES)
 
314
 
 
315
 
 
316
##############################################################################
 
317
##############################################################################
 
318
# This helper macro populates the following variables and setups up custom commands and targets to
 
319
# invoke the nvcc compiler. The compiler is invoked once with -M to generate a dependency file and
 
320
# a second time with -cuda to generate a .cpp file
 
321
# ${target_srcs}
 
322
# ${cuda_cu_sources}
 
323
##############################################################################
 
324
##############################################################################
 
325
 
 
326
MACRO(CUDA_add_custom_commands cuda_target)
 
327
 
 
328
  SET(target_srcs "")
 
329
  SET(cuda_cu_sources "")
 
330
 
 
331
  # Iterate over the macro arguments and create custom
 
332
  # commands for all the .cu files.
 
333
  FOREACH(file ${ARGN})
 
334
    IF(${file} MATCHES ".*\\.cu$")
 
335
    
 
336
    # Add a custom target to generate a c file.
 
337
    SET(generated_file  "${CMAKE_BINARY_DIR}/${file}_${cuda_target}_generated.cpp")
 
338
    SET(generated_target "${file}_target")
 
339
    
 
340
    FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR})
 
341
 
 
342
    SET(source_file ${CMAKE_CURRENT_SOURCE_DIR}/${file})
 
343
 
 
344
    # MESSAGE("${CUDA_NVCC} ${source_file} ${CUDA_NVCC_FLAGS} ${nvcc_flags} -cuda -o ${generated_file} ${CUDA_NVCC_INCLUDE_ARGS}")
 
345
    
 
346
    # Bring in the dependencies.  Creates a variable CUDA_NVCC_DEPEND
 
347
        SET(cmake_dependency_file "${generated_file}.depend")
 
348
        CUDA_INCLUDE_NVCC_DEPENDENCIES(${cmake_dependency_file})
 
349
        SET(NVCC_generated_dependency_file "${generated_file}.NVCC-depend")
 
350
 
 
351
 
 
352
        # Build the NVCC made dependency file
 
353
  IF (MT_CUDA_BUILD_TYPE MATCHES "Device" AND CUDA_BUILD_CUBIN)
 
354
    SET(NVCC_generated_cubin_file "${generated_file}.NVCC-cubin.txt")
 
355
          ADD_CUSTOM_COMMAND(
 
356
 
 
357
      # Generate the .cubin output.
 
358
      OUTPUT ${NVCC_generated_cubin_file}
 
359
      COMMAND ${CUDA_NVCC}
 
360
      ARGS ${source_file} 
 
361
      ${CUDA_NVCC_FLAGS}
 
362
      ${nvcc_flags}
 
363
      -DNVCC
 
364
      -cubin
 
365
      -o ${NVCC_generated_cubin_file} 
 
366
      ${CUDA_NVCC_INCLUDE_ARGS}
 
367
 
 
368
      # Execute the parser script.
 
369
      COMMAND  ${CMAKE_COMMAND}
 
370
      ARGS 
 
371
      -D input_file="${NVCC_generated_cubin_file}"
 
372
      -P "${CMAKE_SOURCE_DIR}/cmake/parse_cubin.cmake"
 
373
 
 
374
 
 
375
      # MAIN_DEPENDENCY ${source_file}
 
376
      DEPENDS ${source_file}
 
377
      DEPENDS ${CUDA_NVCC_DEPEND}
 
378
 
 
379
 
 
380
 
 
381
            COMMENT "Building (${MT_CUDA_BUILD_TYPE}) NVCC -cubin File: ${NVCC_generated_cubin_file}\n"
 
382
      )
 
383
  ELSE (MT_CUDA_BUILD_TYPE MATCHES "Device" AND CUDA_BUILD_CUBIN)
 
384
    # Depend on something that will exist.
 
385
    SET(NVCC_generated_cubin_file "${source_file}")
 
386
  ENDIF (MT_CUDA_BUILD_TYPE MATCHES "Device"AND CUDA_BUILD_CUBIN)
 
387
 
 
388
        # Build the NVCC made dependency file
 
389
        ADD_CUSTOM_COMMAND(
 
390
      OUTPUT ${NVCC_generated_dependency_file}
 
391
      COMMAND ${CUDA_NVCC}
 
392
      ARGS ${source_file} 
 
393
           ${CUDA_NVCC_FLAGS}
 
394
           ${nvcc_flags}
 
395
           -DNVCC
 
396
           -M
 
397
           -o ${NVCC_generated_dependency_file} 
 
398
           ${CUDA_NVCC_INCLUDE_ARGS}
 
399
      # MAIN_DEPENDENCY ${source_file}
 
400
      DEPENDS ${source_file}
 
401
      DEPENDS ${CUDA_NVCC_DEPEND}
 
402
          COMMENT "Building (${MT_CUDA_BUILD_TYPE}) NVCC Dependency File: ${NVCC_generated_dependency_file}\n"
 
403
    )
 
404
    
 
405
    # Build the CMake readible dependency file
 
406
        ADD_CUSTOM_COMMAND(
 
407
          OUTPUT ${cmake_dependency_file}
 
408
      COMMAND ${CMAKE_COMMAND}
 
409
      ARGS 
 
410
      -D input_file="${NVCC_generated_dependency_file}"
 
411
      -D output_file="${cmake_dependency_file}"
 
412
      -P "${CMAKE_SOURCE_DIR}/cmake/make2cmake.cmake"
 
413
      MAIN_DEPENDENCY ${NVCC_generated_dependency_file}
 
414
      COMMENT "Converting NVCC dependency to CMake (${cmake_dependency_file})"
 
415
    )
 
416
 
 
417
    ADD_CUSTOM_COMMAND(
 
418
      OUTPUT ${generated_file}
 
419
      MAIN_DEPENDENCY ${source_file} 
 
420
      DEPENDS ${CUDA_NVCC_DEPEND}
 
421
      DEPENDS ${cmake_dependency_file}
 
422
      DEPENDS ${NVCC_generated_cubin_file}
 
423
      COMMAND ${CUDA_NVCC} 
 
424
      ARGS ${source_file} 
 
425
           ${CUDA_NVCC_FLAGS}
 
426
           ${nvcc_flags}
 
427
           -DNVCC
 
428
           --keep
 
429
           -cuda -o ${generated_file} 
 
430
           ${CUDA_NVCC_INCLUDE_ARGS}
 
431
       COMMENT "Building (${MT_CUDA_BUILD_TYPE}) NVCC ${source_file}: ${generated_file}\n"
 
432
      )
 
433
        
 
434
    SET(cuda_cu_sources ${cuda_cu_sources} ${source_file})
 
435
 
 
436
    # Add the generated file name to the source list.
 
437
    SET(target_srcs ${target_srcs} ${generated_file})
 
438
    
 
439
    ELSE(${file} MATCHES ".*\\.cu$")
 
440
  
 
441
    # Otherwise add the file name to the source list.
 
442
    SET(target_srcs ${target_srcs} ${file})
 
443
  
 
444
    ENDIF(${file} MATCHES ".*\\.cu$")
 
445
  ENDFOREACH(file)
 
446
 
 
447
ENDMACRO(CUDA_add_custom_commands)
 
448
 
 
449
###############################################################################
 
450
###############################################################################
 
451
# ADD LIBRARY
 
452
###############################################################################
 
453
###############################################################################
 
454
MACRO(CUDA_ADD_LIBRARY cuda_target)
 
455
 
 
456
  # Create custom commands and targets for each file.
 
457
  CUDA_add_custom_commands( ${cuda_target} ${ARGN} )  
 
458
 
 
459
  # Add the library.
 
460
        ADD_LIBRARY(${cuda_target}
 
461
                  ${target_srcs}
 
462
                ${cuda_cu_sources}
 
463
          )
 
464
 
 
465
  TARGET_LINK_LIBRARIES(${cuda_target}
 
466
    ${CUDA_TARGET_LINK}
 
467
    )
 
468
 
 
469
ENDMACRO(CUDA_ADD_LIBRARY cuda_target)
 
470
 
 
471
 
 
472
###############################################################################
 
473
###############################################################################
 
474
# ADD EXECUTABLE
 
475
###############################################################################
 
476
###############################################################################
 
477
MACRO(CUDA_ADD_EXECUTABLE cuda_target)
 
478
  
 
479
  # Create custom commands and targets for each file.
 
480
  CUDA_add_custom_commands( ${cuda_target} ${ARGN} )
 
481
  
 
482
  # Add the library.
 
483
  ADD_EXECUTABLE(${cuda_target}
 
484
    ${target_srcs}
 
485
    ${cuda_cu_sources}
 
486
    )
 
487
 
 
488
  TARGET_LINK_LIBRARIES(${cuda_target}
 
489
    ${CUDA_TARGET_LINK}
 
490
    )
 
491
 
 
492
 
 
493
ENDMACRO(CUDA_ADD_EXECUTABLE cuda_target)
 
494
 
 
495
###############################################################################
 
496
###############################################################################
 
497
# ADD EXECUTABLE
 
498
###############################################################################
 
499
###############################################################################
 
500
MACRO(CUDA_COMPILE file_variable)
 
501
  
 
502
  # Create custom commands and targets for each file.
 
503
  CUDA_add_custom_commands( cuda_compile ${ARGN} )
 
504
  
 
505
  SET(file_variable ${target_srcs} ${cuda_cu_sources})
 
506
 
 
507
ENDMACRO(CUDA_COMPILE)