FindCUDA.cmake 74 KB

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