FindCUDA.cmake 75 KB

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