2013-10-15 19:17:36 +04:00
#.rst:
# FindCUDA
# --------
#
# Tools for building CUDA C files: libraries and build dependencies.
#
# This script locates the NVIDIA CUDA C tools. It should work on linux,
# windows, and mac and should be reasonably up to date with CUDA C
# releases.
#
# This script makes use of the standard find_package arguments of
# <VERSION>, REQUIRED and QUIET. CUDA_FOUND will report if an
# acceptable version of CUDA was found.
#
# The script will prompt the user to specify CUDA_TOOLKIT_ROOT_DIR if
# the prefix cannot be determined by the location of nvcc in the system
# path and REQUIRED is specified to find_package(). To use a different
# installed version of the toolkit set the environment variable
# CUDA_BIN_PATH before running cmake (e.g.
# CUDA_BIN_PATH=/usr/local/cuda1.0 instead of the default
# /usr/local/cuda) or set CUDA_TOOLKIT_ROOT_DIR after configuring. If
# you change the value of CUDA_TOOLKIT_ROOT_DIR, various components that
# depend on the path will be relocated.
2009-09-25 23:42:53 +04:00
#
# It might be necessary to set CUDA_TOOLKIT_ROOT_DIR manually on certain
2013-10-15 19:17:36 +04:00
# platforms, or to use a cuda runtime not installed in the default
# location. In newer versions of the toolkit the cuda library is
# included with the graphics driver- be sure that the driver version
# matches what is needed by the cuda runtime version.
#
# The following variables affect the behavior of the macros in the
# script (in alphebetical order). Note that any of these flags can be
# changed multiple times in the same directory before calling
2014-04-30 02:01:57 +04:00
# CUDA_ADD_EXECUTABLE, CUDA_ADD_LIBRARY, CUDA_COMPILE, CUDA_COMPILE_PTX,
# CUDA_COMPILE_FATBIN, CUDA_COMPILE_CUBIN or CUDA_WRAP_SRCS::
2013-10-15 19:17:36 +04:00
#
# CUDA_64_BIT_DEVICE_CODE (Default matches host bit size)
# -- Set to ON to compile for 64 bit device code, OFF for 32 bit device code.
# Note that making this different from the host code when generating object
# or C files from CUDA code just won't work, because size_t gets defined by
# nvcc in the generated source. If you compile to PTX and then load the
# file yourself, you can mix bit sizes between device and host.
#
# CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE (Default ON)
# -- Set to ON if you want the custom build rule to be attached to the source
# file in Visual Studio. Turn OFF if you add the same cuda file to multiple
# targets.
#
# This allows the user to build the target from the CUDA file; however, bad
# things can happen if the CUDA source file is added to multiple targets.
# When performing parallel builds it is possible for the custom build
# command to be run more than once and in parallel causing cryptic build
# errors. VS runs the rules for every source file in the target, and a
# source can have only one rule no matter how many projects it is added to.
# When the rule is run from multiple targets race conditions can occur on
# the generated file. Eventually everything will get built, but if the user
# is unaware of this behavior, there may be confusion. It would be nice if
# this script could detect the reuse of source files across multiple targets
# and turn the option off for the user, but no good solution could be found.
#
# CUDA_BUILD_CUBIN (Default OFF)
# -- Set to ON to enable and extra compilation pass with the -cubin option in
# Device mode. The output is parsed and register, shared memory usage is
# printed during build.
#
# CUDA_BUILD_EMULATION (Default OFF for device mode)
# -- Set to ON for Emulation mode. -D_DEVICEEMU is defined for CUDA C files
# when CUDA_BUILD_EMULATION is TRUE.
#
# CUDA_GENERATED_OUTPUT_DIR (Default CMAKE_CURRENT_BINARY_DIR)
# -- Set to the path you wish to have the generated files placed. If it is
# blank output files will be placed in CMAKE_CURRENT_BINARY_DIR.
# Intermediate files will always be placed in
# CMAKE_CURRENT_BINARY_DIR/CMakeFiles.
#
# CUDA_HOST_COMPILATION_CPP (Default ON)
# -- Set to OFF for C compilation of host code.
#
# CUDA_HOST_COMPILER (Default CMAKE_C_COMPILER, $(VCInstallDir)/bin for VS)
# -- Set the host compiler to be used by nvcc. Ignored if -ccbin or
# --compiler-bindir is already present in the CUDA_NVCC_FLAGS or
# CUDA_NVCC_FLAGS_<CONFIG> variables. For Visual Studio targets
# $(VCInstallDir)/bin is a special value that expands out to the path when
# the command is run from withing VS.
#
# CUDA_NVCC_FLAGS
# CUDA_NVCC_FLAGS_<CONFIG>
# -- Additional NVCC command line arguments. NOTE: multiple arguments must be
# semi-colon delimited (e.g. --compiler-options;-Wall)
#
# CUDA_PROPAGATE_HOST_FLAGS (Default ON)
# -- Set to ON to propagate CMAKE_{C,CXX}_FLAGS and their configuration
# dependent counterparts (e.g. CMAKE_C_FLAGS_DEBUG) automatically to the
# host compiler through nvcc's -Xcompiler flag. This helps make the
# generated host code match the rest of the system better. Sometimes
# certain flags give nvcc problems, and this will help you turn the flag
# propagation off. This does not affect the flags supplied directly to nvcc
# via CUDA_NVCC_FLAGS or through the OPTION flags specified through
# CUDA_ADD_LIBRARY, CUDA_ADD_EXECUTABLE, or CUDA_WRAP_SRCS. Flags used for
# shared library compilation are not affected by this flag.
#
# CUDA_SEPARABLE_COMPILATION (Default OFF)
# -- If set this will enable separable compilation for all CUDA runtime object
# files. If used outside of CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY
# (e.g. calling CUDA_WRAP_SRCS directly),
# CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME and
# CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS should be called.
#
2015-03-27 08:46:35 +03:00
# CUDA_SOURCE_PROPERTY_FORMAT
# -- If this source file property is set, it can override the format specified
# to CUDA_WRAP_SRCS (OBJ, PTX, CUBIN, or FATBIN). If an input source file
# is not a .cu file, setting this file will cause it to be treated as a .cu
# file. See documentation for set_source_files_properties on how to set
# this property.
#
2015-03-31 23:13:04 +03:00
# CUDA_USE_STATIC_CUDA_RUNTIME (Default ON)
# -- When enabled the static version of the CUDA runtime library will be used
# in CUDA_LIBRARIES. If the version of CUDA configured doesn't support
# this option, then it will be silently disabled.
#
2013-10-15 19:17:36 +04:00
# CUDA_VERBOSE_BUILD (Default OFF)
# -- Set to ON to see all the commands used when building the CUDA file. When
# using a Makefile generator the value defaults to VERBOSE (run make
# VERBOSE=1 to see output), although setting CUDA_VERBOSE_BUILD to ON will
# always print the output.
#
2014-01-29 23:25:29 +04:00
# The script creates the following macros (in alphebetical order)::
2013-10-15 19:17:36 +04:00
#
# CUDA_ADD_CUFFT_TO_TARGET( cuda_target )
# -- Adds the cufft library to the target (can be any target). Handles whether
# you are in emulation mode or not.
#
# CUDA_ADD_CUBLAS_TO_TARGET( cuda_target )
# -- Adds the cublas library to the target (can be any target). Handles
# whether you are in emulation mode or not.
#
# CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ...
# [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] [OPTIONS ...] )
# -- Creates an executable "cuda_target" which is made up of the files
# specified. All of the non CUDA C files are compiled using the standard
# build rules specified by CMAKE and the cuda files are compiled to object
# files using nvcc and the host compiler. In addition CUDA_INCLUDE_DIRS is
# added automatically to include_directories(). Some standard CMake target
# calls can be used on the target after calling this macro
# (e.g. set_target_properties and target_link_libraries), but setting
# properties that adjust compilation flags will not affect code compiled by
# nvcc. Such flags should be modified before calling CUDA_ADD_EXECUTABLE,
# CUDA_ADD_LIBRARY or CUDA_WRAP_SRCS.
#
# CUDA_ADD_LIBRARY( cuda_target file0 file1 ...
# [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] [OPTIONS ...] )
# -- Same as CUDA_ADD_EXECUTABLE except that a library is created.
#
# CUDA_BUILD_CLEAN_TARGET()
# -- Creates a convience target that deletes all the dependency files
# generated. You should make clean after running this target to ensure the
# dependency files get regenerated.
#
# CUDA_COMPILE( generated_files file0 file1 ... [STATIC | SHARED | MODULE]
# [OPTIONS ...] )
# -- Returns a list of generated files from the input source files to be used
# with ADD_LIBRARY or ADD_EXECUTABLE.
#
# CUDA_COMPILE_PTX( generated_files file0 file1 ... [OPTIONS ...] )
# -- Returns a list of PTX files generated from the input source files.
#
2014-04-30 02:01:57 +04:00
# CUDA_COMPILE_FATBIN( generated_files file0 file1 ... [OPTIONS ...] )
# -- Returns a list of FATBIN files generated from the input source files.
#
# CUDA_COMPILE_CUBIN( generated_files file0 file1 ... [OPTIONS ...] )
# -- Returns a list of CUBIN files generated from the input source files.
#
2013-10-15 19:17:36 +04:00
# CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME( output_file_var
# cuda_target
# object_files )
# -- Compute the name of the intermediate link file used for separable
# compilation. This file name is typically passed into
# CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS. output_file_var is produced
# based on cuda_target the list of objects files that need separable
# compilation as specified by object_files. If the object_files list is
# empty, then output_file_var will be empty. This function is called
# automatically for CUDA_ADD_LIBRARY and CUDA_ADD_EXECUTABLE. Note that
# this is a function and not a macro.
#
# CUDA_INCLUDE_DIRECTORIES( path0 path1 ... )
# -- Sets the directories that should be passed to nvcc
# (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu
# files.
#
#
#
# CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS( output_file_var cuda_target
# nvcc_flags object_files)
#
# -- Generates the link object required by separable compilation from the given
# object files. This is called automatically for CUDA_ADD_EXECUTABLE and
# CUDA_ADD_LIBRARY, but can be called manually when using CUDA_WRAP_SRCS
# directly. When called from CUDA_ADD_LIBRARY or CUDA_ADD_EXECUTABLE the
# nvcc_flags passed in are the same as the flags passed in via the OPTIONS
# argument. The only nvcc flag added automatically is the bitness flag as
# specified by CUDA_64_BIT_DEVICE_CODE. Note that this is a function
# instead of a macro.
#
# CUDA_WRAP_SRCS ( cuda_target format generated_files file0 file1 ...
# [STATIC | SHARED | MODULE] [OPTIONS ...] )
# -- This is where all the magic happens. CUDA_ADD_EXECUTABLE,
# CUDA_ADD_LIBRARY, CUDA_COMPILE, and CUDA_COMPILE_PTX all call this
# function under the hood.
#
# Given the list of files (file0 file1 ... fileN) this macro generates
# custom commands that generate either PTX or linkable objects (use "PTX" or
# "OBJ" for the format argument to switch). Files that don't end with .cu
# or have the HEADER_FILE_ONLY property are ignored.
#
# The arguments passed in after OPTIONS are extra command line options to
# give to nvcc. You can also specify per configuration options by
# specifying the name of the configuration followed by the options. General
# options must preceed configuration specific options. Not all
# configurations need to be specified, only the ones provided will be used.
#
# OPTIONS -DFLAG=2 "-DFLAG_OTHER=space in flag"
# DEBUG -g
# RELEASE --use_fast_math
# RELWITHDEBINFO --use_fast_math;-g
# MINSIZEREL --use_fast_math
#
# For certain configurations (namely VS generating object files with
# CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE set to ON), no generated file will
# be produced for the given cuda file. This is because when you add the
# cuda file to Visual Studio it knows that this file produces an object file
# and will link in the resulting object file automatically.
#
# This script will also generate a separate cmake script that is used at
# build time to invoke nvcc. This is for several reasons.
#
# 1. nvcc can return negative numbers as return values which confuses
# Visual Studio into thinking that the command succeeded. The script now
# checks the error codes and produces errors when there was a problem.
#
# 2. nvcc has been known to not delete incomplete results when it
# encounters problems. This confuses build systems into thinking the
# target was generated when in fact an unusable file exists. The script
# now deletes the output files if there was an error.
#
# 3. By putting all the options that affect the build into a file and then
# make the build rule dependent on the file, the output files will be
# regenerated when the options change.
#
# This script also looks at optional arguments STATIC, SHARED, or MODULE to
# determine when to target the object compilation for a shared library.
# BUILD_SHARED_LIBS is ignored in CUDA_WRAP_SRCS, but it is respected in
# CUDA_ADD_LIBRARY. On some systems special flags are added for building
# objects intended for shared libraries. A preprocessor macro,
# <target_name>_EXPORTS is defined when a shared library compilation is
# detected.
#
# Flags passed into add_definitions with -D or /D are passed along to nvcc.
#
#
2009-09-25 23:42:53 +04:00
#
2014-01-29 23:25:29 +04:00
# The script defines the following variables::
2013-10-15 19:17:36 +04:00
#
# CUDA_VERSION_MAJOR -- The major version of cuda as reported by nvcc.
# CUDA_VERSION_MINOR -- The minor version.
# CUDA_VERSION
# CUDA_VERSION_STRING -- CUDA_VERSION_MAJOR.CUDA_VERSION_MINOR
#
# CUDA_TOOLKIT_ROOT_DIR -- Path to the CUDA Toolkit (defined if not set).
# CUDA_SDK_ROOT_DIR -- Path to the CUDA SDK. Use this to find files in the
# SDK. This script will not directly support finding
# specific libraries or headers, as that isn't
# supported by NVIDIA. If you want to change
# libraries when the path changes see the
# FindCUDA.cmake script for an example of how to clear
# these variables. There are also examples of how to
# use the CUDA_SDK_ROOT_DIR to locate headers or
# libraries, if you so choose (at your own risk).
# CUDA_INCLUDE_DIRS -- Include directory for cuda headers. Added automatically
# for CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY.
# CUDA_LIBRARIES -- Cuda RT library.
# CUDA_CUFFT_LIBRARIES -- Device or emulation library for the Cuda FFT
# implementation (alternative to:
# CUDA_ADD_CUFFT_TO_TARGET macro)
# CUDA_CUBLAS_LIBRARIES -- Device or emulation library for the Cuda BLAS
# implementation (alterative to:
# CUDA_ADD_CUBLAS_TO_TARGET macro).
2015-03-31 23:13:04 +03:00
# CUDA_cudart_static_LIBRARY -- Statically linkable cuda runtime library.
# Only available for CUDA version 5.5+
2013-10-15 19:17:36 +04:00
# CUDA_cupti_LIBRARY -- CUDA Profiling Tools Interface library.
# Only available for CUDA version 4.0+.
# CUDA_curand_LIBRARY -- CUDA Random Number Generation library.
# Only available for CUDA version 3.2+.
2015-01-21 03:06:11 +03:00
# CUDA_cusolver_LIBRARY -- CUDA Direct Solver library.
# Only available for CUDA version 7.0+.
2013-10-15 19:17:36 +04:00
# CUDA_cusparse_LIBRARY -- CUDA Sparse Matrix library.
# Only available for CUDA version 3.2+.
2014-11-06 21:50:40 +03:00
# CUDA_npp_LIBRARY -- NVIDIA Performance Primitives lib.
2013-10-15 19:17:36 +04:00
# Only available for CUDA version 4.0+.
2014-11-06 21:50:40 +03:00
# CUDA_nppc_LIBRARY -- NVIDIA Performance Primitives lib (core).
2013-10-15 19:17:36 +04:00
# Only available for CUDA version 5.5+.
2014-11-06 21:50:40 +03:00
# CUDA_nppi_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
2013-10-15 19:17:36 +04:00
# Only available for CUDA version 5.5+.
2014-11-06 21:50:40 +03:00
# CUDA_npps_LIBRARY -- NVIDIA Performance Primitives lib (signal processing).
2013-10-15 19:17:36 +04:00
# Only available for CUDA version 5.5+.
# CUDA_nvcuvenc_LIBRARY -- CUDA Video Encoder library.
# Only available for CUDA version 3.2+.
# Windows only.
# CUDA_nvcuvid_LIBRARY -- CUDA Video Decoder library.
# Only available for CUDA version 3.2+.
# Windows only.
#
2014-01-29 23:25:29 +04:00
2013-10-15 19:17:36 +04:00
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
#
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
#
# Copyright (c) 2007-2009
# Scientific Computing and Imaging Institute, University of Utah
#
# This code is licensed under the MIT License. See the FindCUDA.cmake script
# for the text of the license.
2009-09-25 23:42:53 +04:00
# The MIT License
#
# License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
###############################################################################
# FindCUDA.cmake
# This macro helps us find the location of helper files we will need the full path to
macro ( CUDA_FIND_HELPER_FILE _name _extension )
set ( _full_name "${_name}.${_extension}" )
# CMAKE_CURRENT_LIST_FILE contains the full path to the file currently being
# processed. Using this variable, we can pull out the current path, and
# provide a way to get access to the other files we need local to here.
get_filename_component ( CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH )
2011-12-06 06:04:48 +04:00
set ( CUDA_ ${ _name } "${CMAKE_CURRENT_LIST_DIR}/FindCUDA/${_full_name}" )
if ( NOT EXISTS "${CUDA_${_name}}" )
set ( error_message "${_full_name} not found in ${CMAKE_CURRENT_LIST_DIR}/FindCUDA" )
2009-09-25 23:42:53 +04:00
if ( CUDA_FIND_REQUIRED )
message ( FATAL_ERROR "${error_message}" )
2011-12-06 06:04:48 +04:00
else ( )
2009-09-25 23:42:53 +04:00
if ( NOT CUDA_FIND_QUIETLY )
message ( STATUS "${error_message}" )
2011-12-06 06:04:48 +04:00
endif ( )
endif ( )
endif ( )
2009-09-25 23:42:53 +04:00
# Set this variable as internal, so the user isn't bugged with it.
set ( CUDA_ ${ _name } ${ CUDA_${_name } } CACHE INTERNAL "Location of ${_full_name}" FORCE )
2012-08-13 21:50:14 +04:00
endmacro ( )
2009-09-25 23:42:53 +04:00
#####################################################################
## CUDA_INCLUDE_NVCC_DEPENDENCIES
##
# So we want to try and include the dependency file if it exists. If
# it doesn't exist then we need to create an empty one, so we can
# include it.
# If it does exist, then we need to check to see if all the files it
# depends on exist. If they don't then we should clear the dependency
# file and regenerate it later. This covers the case where a header
# file has disappeared or moved.
macro ( CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file )
set ( CUDA_NVCC_DEPEND )
set ( CUDA_NVCC_DEPEND_REGENERATE FALSE )
# Include the dependency file. Create it first if it doesn't exist . The
# INCLUDE puts a dependency that will force CMake to rerun and bring in the
# new info when it changes. DO NOT REMOVE THIS (as I did and spent a few
# hours figuring out why it didn't work.
if ( NOT EXISTS ${ dependency_file } )
file ( WRITE ${ dependency_file } "#FindCUDA.cmake generated file. Do not edit.\n" )
endif ( )
# Always include this file to force CMake to run again next
# invocation and rebuild the dependencies.
#message("including dependency_file = ${dependency_file}")
include ( ${ dependency_file } )
# Now we need to verify the existence of all the included files
# here. If they aren't there we need to just blank this variable and
# make the file regenerate again.
# if(DEFINED CUDA_NVCC_DEPEND)
# message("CUDA_NVCC_DEPEND set")
# else()
# message("CUDA_NVCC_DEPEND NOT set")
# endif()
if ( CUDA_NVCC_DEPEND )
2011-12-06 06:04:48 +04:00
#message("CUDA_NVCC_DEPEND found")
2009-09-25 23:42:53 +04:00
foreach ( f ${ CUDA_NVCC_DEPEND } )
2011-12-06 06:04:48 +04:00
# message("searching for ${f}")
2009-09-25 23:42:53 +04:00
if ( NOT EXISTS ${ f } )
#message("file ${f} not found")
set ( CUDA_NVCC_DEPEND_REGENERATE TRUE )
endif ( )
2012-08-13 21:50:14 +04:00
endforeach ( )
else ( )
2009-09-25 23:42:53 +04:00
#message("CUDA_NVCC_DEPEND false")
# No dependencies, so regenerate the file.
set ( CUDA_NVCC_DEPEND_REGENERATE TRUE )
2012-08-13 21:50:14 +04:00
endif ( )
2009-09-25 23:42:53 +04:00
#message("CUDA_NVCC_DEPEND_REGENERATE = ${CUDA_NVCC_DEPEND_REGENERATE}")
# No incoming dependencies, so we need to generate them. Make the
# output depend on the dependency file itself, which should cause the
# rule to re-run.
if ( CUDA_NVCC_DEPEND_REGENERATE )
2011-12-06 03:29:28 +04:00
set ( CUDA_NVCC_DEPEND ${ dependency_file } )
#message("Generating an empty dependency_file: ${dependency_file}")
2009-09-25 23:42:53 +04:00
file ( WRITE ${ dependency_file } "#FindCUDA.cmake generated file. Do not edit.\n" )
2012-08-13 21:50:14 +04:00
endif ( )
2009-09-25 23:42:53 +04:00
2012-08-13 21:50:14 +04:00
endmacro ( )
2009-09-25 23:42:53 +04:00
###############################################################################
###############################################################################
# Setup variables' defaults
###############################################################################
###############################################################################
# Allow the user to specify if the device code is supposed to be 32 or 64 bit.
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( CUDA_64_BIT_DEVICE_CODE_DEFAULT ON )
else ( )
set ( CUDA_64_BIT_DEVICE_CODE_DEFAULT OFF )
endif ( )
option ( CUDA_64_BIT_DEVICE_CODE "Compile device code in 64 bit mode" ${ CUDA_64_BIT_DEVICE_CODE_DEFAULT } )
# Attach the build rule to the source file in VS. This option
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 )
# Prints out extra information about the cuda file during compilation
option ( CUDA_BUILD_CUBIN "Generate and parse .cubin files in Device mode." OFF )
# Set whether we are using emulation or device mode.
option ( CUDA_BUILD_EMULATION "Build in Emulation mode" OFF )
# Where to put the generated output.
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" )
# Parse HOST_COMPILATION mode.
option ( CUDA_HOST_COMPILATION_CPP "Generated file extension" ON )
# Extra user settable flags
set ( CUDA_NVCC_FLAGS "" CACHE STRING "Semi-colon delimit multiple arguments." )
2012-08-21 01:14:37 +04:00
if ( CMAKE_GENERATOR MATCHES "Visual Studio" )
set ( CUDA_HOST_COMPILER "$(VCInstallDir)bin" CACHE FILEPATH "Host side compiler used by NVCC" )
else ( )
2015-06-12 21:16:09 +03:00
if ( APPLE
A N D " $ { C M A K E _ C _ C O M P I L E R _ I D } " M A T C H E S " C l a n g "
A N D " $ { C M A K E _ C _ C O M P I L E R } " M A T C H E S " / c c $ " )
# Using cc which is symlink to clang may let NVCC think it is GCC and issue
# unhandled -dumpspecs option to clang. Also in case neither
# CMAKE_C_COMPILER is defined (project does not use C language) nor
# CUDA_HOST_COMPILER is specified manually we should skip -ccbin and let
# nvcc use its own default C compiler.
# Only care about this on APPLE with clang to avoid
# following symlinks to things like ccache
if ( DEFINED CMAKE_C_COMPILER AND NOT DEFINED CUDA_HOST_COMPILER )
get_filename_component ( c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH )
# if the real path does not end up being clang then
# go back to using CMAKE_C_COMPILER
if ( NOT "${c_compiler_realpath}" MATCHES "/clang$" )
set ( c_compiler_realpath "${CMAKE_C_COMPILER}" )
endif ( )
else ( )
set ( c_compiler_realpath "" )
endif ( )
set ( CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC" )
2014-06-12 21:46:50 +04:00
else ( )
2015-06-12 21:16:09 +03:00
set ( CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}"
C A C H E F I L E P A T H " H o s t s i d e c o m p i l e r u s e d b y N V C C " )
2014-06-12 21:46:50 +04:00
endif ( )
2012-08-21 01:14:37 +04:00
endif ( )
2009-09-25 23:42:53 +04:00
# Propagate the host flags to the host compiler via -Xcompiler
option ( CUDA_PROPAGATE_HOST_FLAGS "Propage C/CXX_FLAGS and friends to the host compiler via -Xcompile" ON )
2013-03-05 00:08:20 +04:00
# Enable CUDA_SEPARABLE_COMPILATION
option ( CUDA_SEPARABLE_COMPILATION "Compile CUDA objects with separable compilation enabled. Requires CUDA 5.0+" OFF )
2009-09-25 23:42:53 +04:00
# Specifies whether the commands used when compiling the .cu file will be printed out.
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 )
mark_as_advanced (
C U D A _ 6 4 _ B I T _ D E V I C E _ C O D E
C U D A _ A T T A C H _ V S _ B U I L D _ R U L E _ T O _ C U D A _ F I L E
C U D A _ G E N E R A T E D _ O U T P U T _ D I R
C U D A _ H O S T _ C O M P I L A T I O N _ C P P
C U D A _ N V C C _ F L A G S
C U D A _ P R O P A G A T E _ H O S T _ F L A G S
2015-01-22 18:29:22 +03:00
C U D A _ B U I L D _ C U B I N
C U D A _ B U I L D _ E M U L A T I O N
C U D A _ V E R B O S E _ B U I L D
C U D A _ S E P A R A B L E _ C O M P I L A T I O N
2009-09-25 23:42:53 +04:00
)
# Makefile and similar generators don't define CMAKE_CONFIGURATION_TYPES, so we
# need to add another entry for the CMAKE_BUILD_TYPE. We also need to add the
# standerd set of 4 build types (Debug, MinSizeRel, Release, and RelWithDebInfo)
# for completeness. We need run this loop in order to accomodate the addition
# of extra configuration types. Duplicate entries will be removed by
# REMOVE_DUPLICATES.
set ( CUDA_configuration_types ${ CMAKE_CONFIGURATION_TYPES } ${ CMAKE_BUILD_TYPE } Debug MinSizeRel Release RelWithDebInfo )
list ( REMOVE_DUPLICATES CUDA_configuration_types )
foreach ( config ${ CUDA_configuration_types } )
string ( TOUPPER ${ config } config_upper )
set ( CUDA_NVCC_FLAGS_ ${ config_upper } "" CACHE STRING "Semi-colon delimit multiple arguments." )
mark_as_advanced ( CUDA_NVCC_FLAGS_ ${ config_upper } )
endforeach ( )
###############################################################################
###############################################################################
# Locate CUDA, Set Build Type, etc.
###############################################################################
###############################################################################
2013-10-24 10:04:09 +04:00
macro ( cuda_unset_include_and_libraries )
2009-09-25 23:42:53 +04:00
unset ( CUDA_TOOLKIT_INCLUDE CACHE )
unset ( CUDA_CUDART_LIBRARY CACHE )
2013-10-24 10:04:09 +04:00
unset ( CUDA_CUDA_LIBRARY CACHE )
2011-12-06 06:04:48 +04:00
# Make sure you run this before you unset CUDA_VERSION.
2010-06-22 03:11:57 +04:00
if ( CUDA_VERSION VERSION_EQUAL "3.0" )
# This only existed in the 3.0 version of the CUDA toolkit
unset ( CUDA_CUDARTEMU_LIBRARY CACHE )
endif ( )
2015-03-31 23:13:04 +03:00
unset ( CUDA_cudart_static_LIBRARY CACHE )
2009-09-25 23:42:53 +04:00
unset ( CUDA_cublas_LIBRARY CACHE )
unset ( CUDA_cublasemu_LIBRARY CACHE )
unset ( CUDA_cufft_LIBRARY CACHE )
unset ( CUDA_cufftemu_LIBRARY CACHE )
2015-03-31 23:13:04 +03:00
unset ( CUDA_cupti_LIBRARY CACHE )
2011-12-21 01:20:04 +04:00
unset ( CUDA_curand_LIBRARY CACHE )
2015-01-21 03:06:11 +03:00
unset ( CUDA_cusolver_LIBRARY CACHE )
2011-12-21 01:20:04 +04:00
unset ( CUDA_cusparse_LIBRARY CACHE )
unset ( CUDA_npp_LIBRARY CACHE )
2013-10-08 11:22:45 +04:00
unset ( CUDA_nppc_LIBRARY CACHE )
unset ( CUDA_nppi_LIBRARY CACHE )
unset ( CUDA_npps_LIBRARY CACHE )
2011-12-21 01:20:04 +04:00
unset ( CUDA_nvcuvenc_LIBRARY CACHE )
unset ( CUDA_nvcuvid_LIBRARY CACHE )
2015-03-31 23:13:04 +03:00
unset ( CUDA_USE_STATIC_CUDA_RUNTIME CACHE )
2013-10-24 10:04:09 +04:00
endmacro ( )
# Check to see if the CUDA_TOOLKIT_ROOT_DIR and CUDA_SDK_ROOT_DIR have changed,
# if they have then clear the cache variables, so that will be detected again.
if ( NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}" )
unset ( CUDA_TOOLKIT_TARGET_DIR CACHE )
unset ( CUDA_NVCC_EXECUTABLE CACHE )
cuda_unset_include_and_libraries ( )
2015-03-31 23:13:04 +03:00
unset ( CUDA_VERSION CACHE )
2013-10-24 10:04:09 +04:00
endif ( )
if ( NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL}" )
cuda_unset_include_and_libraries ( )
2009-09-25 23:42:53 +04:00
endif ( )
if ( NOT "${CUDA_SDK_ROOT_DIR}" STREQUAL "${CUDA_SDK_ROOT_DIR_INTERNAL}" )
2009-09-29 07:41:40 +04:00
# No specific variables to catch. Use this kind of code before calling
# find_package(CUDA) to clean up any variables that may depend on this path.
# unset(MY_SPECIAL_CUDA_SDK_INCLUDE_DIR CACHE)
# unset(MY_SPECIAL_CUDA_SDK_LIBRARY CACHE)
2009-09-25 23:42:53 +04:00
endif ( )
# Search for the cuda distribution.
if ( NOT CUDA_TOOLKIT_ROOT_DIR )
# Search in the CUDA_BIN_PATH first.
find_path ( CUDA_TOOLKIT_ROOT_DIR
N A M E S n v c c n v c c . e x e
2011-12-06 03:04:00 +04:00
P A T H S
E N V C U D A _ P A T H
E N V C U D A _ B I N _ P A T H
P A T H _ S U F F I X E S b i n b i n 6 4
2009-09-25 23:42:53 +04:00
D O C " T o o l k i t l o c a t i o n . "
N O _ D E F A U L T _ P A T H
)
# Now search default paths
find_path ( CUDA_TOOLKIT_ROOT_DIR
N A M E S n v c c n v c c . e x e
P A T H S / u s r / l o c a l / b i n
/ u s r / l o c a l / c u d a / b i n
D O C " T o o l k i t l o c a t i o n . "
)
if ( CUDA_TOOLKIT_ROOT_DIR )
string ( REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${ CUDA_TOOLKIT_ROOT_DIR } )
# We need to force this back into the cache.
set ( CUDA_TOOLKIT_ROOT_DIR ${ CUDA_TOOLKIT_ROOT_DIR } CACHE PATH "Toolkit location." FORCE )
2012-08-13 21:50:14 +04:00
endif ( )
2009-09-25 23:42:53 +04:00
if ( NOT EXISTS ${ CUDA_TOOLKIT_ROOT_DIR } )
if ( CUDA_FIND_REQUIRED )
message ( FATAL_ERROR "Specify CUDA_TOOLKIT_ROOT_DIR" )
elseif ( NOT CUDA_FIND_QUIETLY )
message ( "CUDA_TOOLKIT_ROOT_DIR not found or specified" )
endif ( )
2012-08-13 21:50:14 +04:00
endif ( )
endif ( )
2009-09-25 23:42:53 +04:00
# CUDA_NVCC_EXECUTABLE
find_program ( CUDA_NVCC_EXECUTABLE
N A M E S n v c c
2011-12-06 03:04:00 +04:00
P A T H S " $ { C U D A _ T O O L K I T _ R O O T _ D I R } "
E N V C U D A _ P A T H
2009-09-25 23:42:53 +04:00
E N V C U D A _ B I N _ P A T H
2011-12-06 03:04:00 +04:00
P A T H _ S U F F I X E S b i n b i n 6 4
2009-09-25 23:42:53 +04:00
N O _ D E F A U L T _ P A T H
)
# Search default search paths, after we search our own set of paths.
find_program ( CUDA_NVCC_EXECUTABLE nvcc )
mark_as_advanced ( CUDA_NVCC_EXECUTABLE )
if ( CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION )
# Compute the version.
2009-12-02 00:28:26 +03:00
execute_process ( COMMAND ${ CUDA_NVCC_EXECUTABLE } "--version" OUTPUT_VARIABLE NVCC_OUT )
2009-09-25 23:42:53 +04:00
string ( REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${ NVCC_OUT } )
string ( REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${ NVCC_OUT } )
set ( CUDA_VERSION "${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" CACHE STRING "Version of CUDA as computed from nvcc." )
mark_as_advanced ( CUDA_VERSION )
2010-05-13 02:38:51 +04:00
else ( )
# Need to set these based off of the cached value
2010-06-15 20:03:40 +04:00
string ( REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR "${CUDA_VERSION}" )
string ( REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR "${CUDA_VERSION}" )
2009-09-25 23:42:53 +04:00
endif ( )
# Always set this convenience variable
set ( CUDA_VERSION_STRING "${CUDA_VERSION}" )
2013-10-24 10:04:09 +04:00
# Support for arm cross compilation with CUDA 5.5
2015-01-04 16:37:51 +03:00
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" )
2013-10-24 10:04:09 +04:00
set ( CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}/targets/armv7-linux-gnueabihf" CACHE PATH "Toolkit target location." )
2015-11-23 17:17:52 +03:00
# Support for aarch64 cross compilation with CUDA 7.0
elseif ( CUDA_VERSION VERSION_GREATER "6.5" AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" AND EXISTS "${CUDA_TOOLKIT_ROOT_DIR}/targets/aarch64-linux" )
set ( CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}/targets/aarch64-linux" CACHE PATH "Toolkit target location." )
2013-10-24 10:04:09 +04:00
else ( )
set ( CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT_DIR}" CACHE PATH "Toolkit target location." )
endif ( )
mark_as_advanced ( CUDA_TOOLKIT_TARGET_DIR )
# Target CPU architecture
2015-01-04 16:37:51 +03:00
if ( CUDA_VERSION VERSION_GREATER "5.0" AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm" )
2013-10-24 10:04:09 +04:00
set ( _cuda_target_cpu_arch_initial "ARM" )
else ( )
set ( _cuda_target_cpu_arch_initial "" )
endif ( )
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." )
mark_as_advanced ( CUDA_TARGET_CPU_ARCH )
2009-09-25 23:42:53 +04:00
# CUDA_TOOLKIT_INCLUDE
find_path ( CUDA_TOOLKIT_INCLUDE
d e v i c e _ f u n c t i o n s . h # Header included in toolkit
2013-10-24 10:04:09 +04:00
P A T H S " $ { C U D A _ T O O L K I T _ T A R G E T _ D I R } " " $ { C U D A _ T O O L K I T _ R O O T _ D I R } "
2011-12-06 03:04:00 +04:00
E N V C U D A _ P A T H
2009-09-25 23:42:53 +04:00
E N V C U D A _ I N C _ P A T H
2011-12-06 03:04:00 +04:00
P A T H _ S U F F I X E S i n c l u d e
2009-09-25 23:42:53 +04:00
N O _ D E F A U L T _ P A T H
)
# Search default search paths, after we search our own set of paths.
find_path ( CUDA_TOOLKIT_INCLUDE device_functions.h )
mark_as_advanced ( CUDA_TOOLKIT_INCLUDE )
# Set the user list of include dir to nothing to initialize it.
set ( CUDA_NVCC_INCLUDE_ARGS_USER "" )
set ( CUDA_INCLUDE_DIRS ${ CUDA_TOOLKIT_INCLUDE } )
2013-03-05 01:06:15 +04:00
macro ( cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext )
2009-09-25 23:42:53 +04:00
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
2012-03-26 18:21:23 +04:00
# CUDA 3.2+ on Windows moved the library directories, so we need the new
2010-09-10 21:48:38 +04:00
# and old paths.
2013-03-05 01:06:15 +04:00
set ( _cuda_64bit_lib_dir "${_path_ext}lib/x64" "${_path_ext}lib64" "${_path_ext}libx64" )
2009-09-25 23:42:53 +04:00
endif ( )
2010-09-10 21:48:38 +04:00
# CUDA 3.2+ on Windows moved the library directories, so we need to new
# (lib/Win32) and the old path (lib).
2009-09-25 23:42:53 +04:00
find_library ( ${ _var }
N A M E S $ { _ n a m e s }
2013-10-24 10:04:09 +04:00
P A T H S " $ { C U D A _ T O O L K I T _ T A R G E T _ D I R } " " $ { C U D A _ T O O L K I T _ R O O T _ D I R } "
2011-12-06 03:04:00 +04:00
E N V C U D A _ P A T H
2009-09-25 23:42:53 +04:00
E N V C U D A _ L I B _ P A T H
2013-03-05 01:06:15 +04:00
P A T H _ S U F F I X E S $ { _ c u d a _ 6 4 b i t _ l i b _ d i r } " $ { _ p a t h _ e x t } l i b / W i n 3 2 " " $ { _ p a t h _ e x t } l i b " " $ { _ p a t h _ e x t } l i b W i n 3 2 "
2009-09-25 23:42:53 +04:00
D O C $ { _ d o c }
N O _ D E F A U L T _ P A T H
)
# Search default search paths, after we search our own set of paths.
2013-05-24 18:03:57 +04:00
find_library ( ${ _var }
N A M E S $ { _ n a m e s }
P A T H S " / u s r / l i b / n v i d i a - c u r r e n t "
D O C $ { _ d o c }
)
2009-09-25 23:42:53 +04:00
endmacro ( )
2013-03-05 01:06:15 +04:00
macro ( cuda_find_library_local_first _var _names _doc )
cuda_find_library_local_first_with_path_ext ( "${_var}" "${_names}" "${_doc}" "" )
endmacro ( )
macro ( find_library_local_first _var _names _doc )
cuda_find_library_local_first ( "${_var}" "${_names}" "${_doc}" "" )
endmacro ( )
2009-09-25 23:42:53 +04:00
# CUDA_LIBRARIES
2013-03-05 01:06:15 +04:00
cuda_find_library_local_first ( CUDA_CUDART_LIBRARY cudart "\" cudart\ " library" )
2010-06-22 03:11:57 +04:00
if ( CUDA_VERSION VERSION_EQUAL "3.0" )
# The cudartemu library only existed for the 3.0 version of CUDA.
2013-03-05 01:06:15 +04:00
cuda_find_library_local_first ( CUDA_CUDARTEMU_LIBRARY cudartemu "\" cudartemu\ " library" )
2010-06-22 03:11:57 +04:00
mark_as_advanced (
C U D A _ C U D A R T E M U _ L I B R A R Y
)
endif ( )
2015-03-31 23:13:04 +03:00
if ( NOT CUDA_VERSION VERSION_LESS "5.5" )
cuda_find_library_local_first ( CUDA_cudart_static_LIBRARY cudart_static "static CUDA runtime library" )
mark_as_advanced ( CUDA_cudart_static_LIBRARY )
endif ( )
if ( CUDA_cudart_static_LIBRARY )
# Set whether to use the static cuda runtime.
option ( CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" ON )
else ( )
option ( CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" OFF )
endif ( )
if ( CUDA_USE_STATIC_CUDA_RUNTIME )
if ( UNIX )
# Check for the dependent libraries. Here we look for pthreads.
if ( DEFINED CMAKE_THREAD_PREFER_PTHREAD )
set ( _cuda_cmake_thread_prefer_pthread ${ CMAKE_THREAD_PREFER_PTHREAD } )
endif ( )
set ( CMAKE_THREAD_PREFER_PTHREAD 1 )
# Many of the FindXYZ CMake comes with makes use of try_compile with int main(){return 0;}
# as the source file. Unfortunately this causes a warning with -Wstrict-prototypes and
# -Werror causes the try_compile to fail. We will just temporarily disable other flags
# when doing the find_package command here.
set ( _cuda_cmake_c_flags ${ CMAKE_C_FLAGS } )
set ( CMAKE_C_FLAGS "-fPIC" )
find_package ( Threads REQUIRED )
set ( CMAKE_C_FLAGS ${ _cuda_cmake_c_flags } )
if ( DEFINED _cuda_cmake_thread_prefer_pthread )
set ( CMAKE_THREAD_PREFER_PTHREAD ${ _cuda_cmake_thread_prefer_pthread } )
unset ( _cuda_cmake_thread_prefer_pthread )
else ( )
unset ( CMAKE_THREAD_PREFER_PTHREAD )
endif ( )
if ( NOT APPLE )
# Here is librt that has things such as, clock_gettime, shm_open, and shm_unlink.
find_library ( CUDA_rt_LIBRARY rt )
if ( NOT CUDA_rt_LIBRARY )
message ( WARNING "Expecting to find librt for libcudart_static, but didn't find it." )
endif ( )
endif ( )
endif ( )
endif ( )
2013-03-05 01:06:15 +04:00
# CUPTI library showed up in cuda toolkit 4.0
if ( NOT CUDA_VERSION VERSION_LESS "4.0" )
cuda_find_library_local_first_with_path_ext ( CUDA_cupti_LIBRARY cupti "\" cupti\ " library" "extras/CUPTI/" )
mark_as_advanced ( CUDA_cupti_LIBRARY )
endif ( )
2015-03-31 23:13:04 +03:00
# Set the CUDA_LIBRARIES variable. This is the set of stuff to link against if you are
# using the CUDA runtime. For the dynamic version of the runtime, most of the
# dependencies are brough in, but for the static version there are additional libraries
# and linker commands needed.
# Initialize to empty
set ( CUDA_LIBRARIES )
2010-06-22 03:11:57 +04:00
# If we are using emulation mode and we found the cudartemu library then use
# that one instead of cudart.
if ( CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY )
2015-03-31 23:13:04 +03:00
list ( APPEND CUDA_LIBRARIES ${ CUDA_CUDARTEMU_LIBRARY } )
elseif ( CUDA_USE_STATIC_CUDA_RUNTIME AND CUDA_cudart_static_LIBRARY )
2015-11-04 01:00:09 +03:00
list ( APPEND CUDA_LIBRARIES ${ CUDA_cudart_static_LIBRARY } ${ CMAKE_THREAD_LIBS_INIT } ${ CMAKE_DL_LIBS } )
2015-03-31 23:13:04 +03:00
if ( CUDA_rt_LIBRARY )
list ( APPEND CUDA_LIBRARIES ${ CUDA_rt_LIBRARY } )
endif ( )
if ( APPLE )
# We need to add the default path to the driver (libcuda.dylib) as an rpath, so that
# the static cuda runtime can find it at runtime.
list ( APPEND CUDA_LIBRARIES -Wl,-rpath,/usr/local/cuda/lib )
endif ( )
2010-06-22 03:11:57 +04:00
else ( )
2015-03-31 23:13:04 +03:00
list ( APPEND CUDA_LIBRARIES ${ CUDA_CUDART_LIBRARY } )
2010-06-22 03:11:57 +04:00
endif ( )
2009-09-25 23:42:53 +04:00
# 1.1 toolkit on linux doesn't appear to have a separate library on
# some platforms.
2013-03-05 01:06:15 +04:00
cuda_find_library_local_first ( CUDA_CUDA_LIBRARY cuda "\" cuda\ " library (older versions only)." )
2009-09-25 23:42:53 +04:00
mark_as_advanced (
C U D A _ C U D A _ L I B R A R Y
C U D A _ C U D A R T _ L I B R A R Y
)
#######################
# Look for some of the toolkit helper libraries
macro ( FIND_CUDA_HELPER_LIBS _name )
2013-03-05 01:06:15 +04:00
cuda_find_library_local_first ( CUDA_ ${ _name } _LIBRARY ${ _name } "\" ${ _name } \" library " )
2009-09-25 23:42:53 +04:00
mark_as_advanced ( CUDA_ ${ _name } _LIBRARY )
2012-08-13 21:50:14 +04:00
endmacro ( )
2009-09-25 23:42:53 +04:00
2010-09-10 21:48:38 +04:00
#######################
# Disable emulation for v3.1 onward
if ( CUDA_VERSION VERSION_GREATER "3.0" )
if ( CUDA_BUILD_EMULATION )
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}." )
endif ( )
endif ( )
2011-12-21 01:20:04 +04:00
# Search for additional CUDA toolkit libraries.
2010-09-10 21:48:38 +04:00
if ( CUDA_VERSION VERSION_LESS "3.1" )
# Emulation libraries aren't available in version 3.1 onward.
find_cuda_helper_libs ( cufftemu )
find_cuda_helper_libs ( cublasemu )
endif ( )
2009-09-25 23:42:53 +04:00
find_cuda_helper_libs ( cufft )
find_cuda_helper_libs ( cublas )
2011-12-21 01:20:04 +04:00
if ( NOT CUDA_VERSION VERSION_LESS "3.2" )
# cusparse showed up in version 3.2
find_cuda_helper_libs ( cusparse )
find_cuda_helper_libs ( curand )
if ( WIN32 )
find_cuda_helper_libs ( nvcuvenc )
find_cuda_helper_libs ( nvcuvid )
endif ( )
endif ( )
2013-10-08 11:22:45 +04:00
if ( CUDA_VERSION VERSION_GREATER "5.0" )
# In CUDA 5.5 NPP was splitted onto 3 separate libraries.
find_cuda_helper_libs ( nppc )
find_cuda_helper_libs ( nppi )
find_cuda_helper_libs ( npps )
set ( CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}" )
elseif ( NOT CUDA_VERSION VERSION_LESS "4.0" )
2011-12-21 01:20:04 +04:00
find_cuda_helper_libs ( npp )
endif ( )
2015-01-21 03:06:11 +03:00
if ( NOT CUDA_VERSION VERSION_LESS "7.0" )
# cusolver showed up in version 7.0
find_cuda_helper_libs ( cusolver )
endif ( )
2009-09-25 23:42:53 +04:00
if ( CUDA_BUILD_EMULATION )
set ( CUDA_CUFFT_LIBRARIES ${ CUDA_cufftemu_LIBRARY } )
set ( CUDA_CUBLAS_LIBRARIES ${ CUDA_cublasemu_LIBRARY } )
else ( )
set ( CUDA_CUFFT_LIBRARIES ${ CUDA_cufft_LIBRARY } )
set ( CUDA_CUBLAS_LIBRARIES ${ CUDA_cublas_LIBRARY } )
endif ( )
########################
2010-10-05 02:11:08 +04:00
# Look for the SDK stuff. As of CUDA 3.0 NVSDKCUDA_ROOT has been replaced with
# NVSDKCOMPUTE_ROOT with the old CUDA C contents moved into the C subdirectory
2009-09-25 23:42:53 +04:00
find_path ( CUDA_SDK_ROOT_DIR common/inc/cutil.h
2012-03-29 02:00:54 +04:00
H I N T S
2010-10-05 02:11:08 +04:00
" $ E N V { N V S D K C O M P U T E _ R O O T } / C "
2012-03-29 02:00:54 +04:00
E N V N V S D K C U D A _ R O O T
2009-09-25 23:42:53 +04:00
" [ H K E Y _ L O C A L _ M A C H I N E \ \ S O F T W A R E \ \ N V I D I A C o r p o r a t i o n \ \ I n s t a l l e d P r o d u c t s \ \ N V I D I A S D K 1 0 \ \ C o m p u t e ; I n s t a l l D i r ] "
2012-03-29 02:00:54 +04:00
P A T H S
2009-09-29 07:17:13 +04:00
" / D e v e l o p e r / G P U \ C o m p u t i n g / C "
2009-09-25 23:42:53 +04:00
)
# Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the
# environment variables.
set ( CUDA_SDK_SEARCH_PATH
" $ { C U D A _ S D K _ R O O T _ D I R } "
" $ { C U D A _ T O O L K I T _ R O O T _ D I R } / l o c a l / N V S D K 0 . 2 "
" $ { C U D A _ T O O L K I T _ R O O T _ D I R } / N V S D K 0 . 2 "
" $ { C U D A _ T O O L K I T _ R O O T _ D I R } / N V _ C U D A _ S D K "
" $ E N V { H O M E } / N V I D I A _ C U D A _ S D K "
" $ E N V { H O M E } / N V I D I A _ C U D A _ S D K _ M A C O S X "
" / D e v e l o p e r / C U D A "
)
2009-09-29 07:41:40 +04:00
# Example of how to find an include file from the CUDA_SDK_ROOT_DIR
# find_path(CUDA_CUT_INCLUDE_DIR
# cutil.h
# PATHS ${CUDA_SDK_SEARCH_PATH}
# PATH_SUFFIXES "common/inc"
# DOC "Location of cutil.h"
# NO_DEFAULT_PATH
# )
# # Now search system paths
# find_path(CUDA_CUT_INCLUDE_DIR cutil.h DOC "Location of cutil.h")
# mark_as_advanced(CUDA_CUT_INCLUDE_DIR)
# Example of how to find a library in the CUDA_SDK_ROOT_DIR
# # cutil library is called cutil64 for 64 bit builds on windows. We don't want
# # to get these confused, so we are setting the name based on the word size of
# # the build.
# if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# set(cuda_cutil_name cutil64)
2012-08-13 21:50:14 +04:00
# else()
2009-09-29 07:41:40 +04:00
# set(cuda_cutil_name cutil32)
2012-08-13 21:50:14 +04:00
# endif()
2009-09-29 07:41:40 +04:00
# find_library(CUDA_CUT_LIBRARY
# NAMES cutil ${cuda_cutil_name}
# PATHS ${CUDA_SDK_SEARCH_PATH}
# # The new version of the sdk shows up in common/lib, but the old one is in lib
# PATH_SUFFIXES "common/lib" "lib"
# DOC "Location of cutil library"
# NO_DEFAULT_PATH
# )
# # Now search system paths
# find_library(CUDA_CUT_LIBRARY NAMES cutil ${cuda_cutil_name} DOC "Location of cutil library")
# mark_as_advanced(CUDA_CUT_LIBRARY)
# set(CUDA_CUT_LIBRARIES ${CUDA_CUT_LIBRARY})
2009-09-25 23:42:53 +04:00
#############################
# Check for required components
set ( CUDA_FOUND TRUE )
set ( CUDA_TOOLKIT_ROOT_DIR_INTERNAL "${CUDA_TOOLKIT_ROOT_DIR}" CACHE INTERNAL
" T h i s i s t h e v a l u e o f t h e l a s t t i m e C U D A _ T O O L K I T _ R O O T _ D I R w a s s e t s u c c e s s f u l l y . " F O R C E )
2013-10-24 10:04:09 +04:00
set ( CUDA_TOOLKIT_TARGET_DIR_INTERNAL "${CUDA_TOOLKIT_TARGET_DIR}" CACHE INTERNAL
" T h i s i s t h e v a l u e o f t h e l a s t t i m e C U D A _ T O O L K I T _ T A R G E T _ D I R w a s s e t s u c c e s s f u l l y . " F O R C E )
2009-09-25 23:42:53 +04:00
set ( CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL
" T h i s i s t h e v a l u e o f t h e l a s t t i m e C U D A _ S D K _ R O O T _ D I R w a s s e t s u c c e s s f u l l y . " F O R C E )
Modules: Include builtin FindPackageHandleStandardArgs directly
The FindPackageHandleStandardArgs module was originally created outside
of CMake. It was added for CMake 2.6.0 by commit e118a627 (add a macro
FIND_PACKAGE_HANDLE_STANDARD_ARGS..., 2007-07-18). However, it also
proliferated into a number of other projects that at the time required
only CMake 2.4 and thus could not depend on CMake to provide the module.
CMake's own find modules started using the module in commit b5f656e0
(use the new FIND_PACKAGE_HANDLE_STANDARD_ARGS in some of the FindXXX
modules..., 2007-07-18).
Then commit d358cf5c (add 2nd, more powerful mode to
find_package_handle_standard_args, 2010-07-29) added a new feature to
the interface of the module that was fully optional and backward
compatible with all existing users of the module. Later commit 5f183caa
(FindZLIB: use the FPHSA version mode, 2010-08-04) and others shortly
thereafter started using the new interface in CMake's own find modules.
This change was also backward compatible because it was only an
implementation detail within each module.
Unforutnately these changes introduced a problem for projects that still
have an old copy of FindPackageHandleStandardArgs in CMAKE_MODULE_PATH.
When any such project uses one of CMake's builtin find modules the line
include(FindPackageHandleStandardArgs)
loads the copy from the project which does not have the new interface!
Then the including find module tries to use the new interface with the
old module and fails.
Whether this breakage can be considered a backward incompatible change
in CMake is debatable. The situation is analagous to copying a standard
library header from one version of a compiler into a project and then
observing problems when the next version of the compiler reports errors
in its other headers that depend on its new version of the original
header. Nevertheless it is a change to CMake that causes problems for
projects that worked with previous versions.
This problem was discovered during the 2.8.3 release candidate cycle.
It is an instance of a more general problem with projects that provide
their own versions of CMake modules when other CMake modules depend on
them. At the time we resolved this instance of the problem with commit
b0118402 (Use absolute path to FindPackageHandleStandardArgs.cmake
everywhere, 2010-09-28) for the 2.8.3 release.
In order to address the more general problem we introduced policy
CMP0017 in commit db44848f (Prefer files from CMAKE_ROOT when including
from CMAKE_ROOT, 2010-11-17). That change was followed by commit
ce28737c (Remove usage of CMAKE_CURRENT_LIST_DIR now that we have
CMP0017, 2010-12-20) which reverted the original workaround in favor of
using the policy. However, existing project releases do not set the
policy behavior to NEW and therefore still exhibit the problem.
We introduced in commit a364daf1 (Allow users to specify defaults for
unset policies, 2011-01-03) an option for users to build existing
projects by adding -DCMAKE_POLICY_DEFAULT_CMP0017=NEW to the command
line. Unfortunately this solution still does not allow such projects to
build out of the box, and there is no good way to suggest the use of the
new option.
The only remaining solution to keep existing projects that exhibit this
problem building is to restore the change originally made in commit
b0118402 (Use absolute path to FindPackageHandleStandardArgs.cmake
everywhere, 2010-09-28). This also avoids policy CMP0017 warnings for
this particular instance of the problem the policy addresses.
2011-01-20 18:56:49 +03:00
include ( ${ CMAKE_CURRENT_LIST_DIR } /FindPackageHandleStandardArgs.cmake )
2010-08-08 01:09:14 +04:00
find_package_handle_standard_args ( CUDA
R E Q U I R E D _ V A R S
C U D A _ T O O L K I T _ R O O T _ D I R
C U D A _ N V C C _ E X E C U T A B L E
C U D A _ I N C L U D E _ D I R S
C U D A _ C U D A R T _ L I B R A R Y
V E R S I O N _ V A R
C U D A _ V E R S I O N
2009-09-25 23:42:53 +04:00
)
###############################################################################
###############################################################################
# Macros
###############################################################################
###############################################################################
###############################################################################
# Add include directories to pass to the nvcc command.
macro ( CUDA_INCLUDE_DIRECTORIES )
foreach ( dir ${ ARGN } )
2011-12-06 04:16:05 +04:00
list ( APPEND CUDA_NVCC_INCLUDE_ARGS_USER -I ${ dir } )
2012-08-13 21:50:14 +04:00
endforeach ( )
endmacro ( )
2009-09-25 23:42:53 +04:00
##############################################################################
cuda_find_helper_file ( parse_cubin cmake )
cuda_find_helper_file ( make2cmake cmake )
cuda_find_helper_file ( run_nvcc cmake )
##############################################################################
# Separate the OPTIONS out from the sources
#
macro ( CUDA_GET_SOURCES_AND_OPTIONS _sources _cmake_options _options )
set ( ${ _sources } )
set ( ${ _cmake_options } )
set ( ${ _options } )
set ( _found_options FALSE )
foreach ( arg ${ ARGN } )
2014-09-17 15:54:29 +04:00
if ( "x${arg}" STREQUAL "xOPTIONS" )
2009-09-25 23:42:53 +04:00
set ( _found_options TRUE )
elseif (
2014-09-17 15:54:29 +04:00
" x $ { a r g } " S T R E Q U A L " x W I N 3 2 " O R
" x $ { a r g } " S T R E Q U A L " x M A C O S X _ B U N D L E " O R
" x $ { a r g } " S T R E Q U A L " x E X C L U D E _ F R O M _ A L L " O R
" x $ { a r g } " S T R E Q U A L " x S T A T I C " O R
" x $ { a r g } " S T R E Q U A L " x S H A R E D " O R
" x $ { a r g } " S T R E Q U A L " x M O D U L E "
2009-09-25 23:42:53 +04:00
)
2011-12-06 04:16:05 +04:00
list ( APPEND ${ _cmake_options } ${ arg } )
2009-09-25 23:42:53 +04:00
else ( )
if ( _found_options )
2011-12-06 04:16:05 +04:00
list ( APPEND ${ _options } ${ arg } )
2009-09-25 23:42:53 +04:00
else ( )
# Assume this is a file
2011-12-06 04:16:05 +04:00
list ( APPEND ${ _sources } ${ arg } )
2009-09-25 23:42:53 +04:00
endif ( )
endif ( )
endforeach ( )
endmacro ( )
##############################################################################
# Parse the OPTIONS from ARGN and set the variables prefixed by _option_prefix
#
macro ( CUDA_PARSE_NVCC_OPTIONS _option_prefix )
set ( _found_config )
foreach ( arg ${ ARGN } )
# Determine if we are dealing with a perconfiguration flag
foreach ( config ${ CUDA_configuration_types } )
string ( TOUPPER ${ config } config_upper )
if ( arg STREQUAL "${config_upper}" )
set ( _found_config _ ${ arg } )
# Set arg to nothing to keep it from being processed further
set ( arg )
endif ( )
endforeach ( )
if ( arg )
list ( APPEND ${ _option_prefix } ${ _found_config } "${arg}" )
endif ( )
endforeach ( )
endmacro ( )
##############################################################################
# Helper to add the include directory for CUDA only once
function ( CUDA_ADD_CUDA_INCLUDE_ONCE )
get_directory_property ( _include_directories INCLUDE_DIRECTORIES )
set ( _add TRUE )
if ( _include_directories )
foreach ( dir ${ _include_directories } )
if ( "${dir}" STREQUAL "${CUDA_INCLUDE_DIRS}" )
set ( _add FALSE )
endif ( )
endforeach ( )
endif ( )
if ( _add )
include_directories ( ${ CUDA_INCLUDE_DIRS } )
endif ( )
endfunction ( )
2009-11-04 09:15:31 +03:00
function ( CUDA_BUILD_SHARED_LIBRARY shared_flag )
set ( cmake_args ${ ARGN } )
# If SHARED, MODULE, or STATIC aren't already in the list of arguments, then
# add SHARED or STATIC based on the value of BUILD_SHARED_LIBS.
list ( FIND cmake_args SHARED _cuda_found_SHARED )
list ( FIND cmake_args MODULE _cuda_found_MODULE )
list ( FIND cmake_args STATIC _cuda_found_STATIC )
if ( _cuda_found_SHARED GREATER -1 OR
_ c u d a _ f o u n d _ M O D U L E G R E A T E R - 1 O R
_ c u d a _ f o u n d _ S T A T I C G R E A T E R - 1 )
set ( _cuda_build_shared_libs )
else ( )
if ( BUILD_SHARED_LIBS )
set ( _cuda_build_shared_libs SHARED )
else ( )
set ( _cuda_build_shared_libs STATIC )
endif ( )
endif ( )
set ( ${ shared_flag } ${ _cuda_build_shared_libs } PARENT_SCOPE )
endfunction ( )
2011-12-06 06:00:00 +04:00
##############################################################################
# Helper to avoid clashes of files with the same basename but different paths.
# This doesn't attempt to do exactly what CMake internals do, which is to only
# add this path when there is a conflict, since by the time a second collision
# in names is detected it's already too late to fix the first one. For
# consistency sake the relative path will be added to all files.
function ( CUDA_COMPUTE_BUILD_PATH path build_path )
#message("CUDA_COMPUTE_BUILD_PATH([${path}] ${build_path})")
# Only deal with CMake style paths from here on out
file ( TO_CMAKE_PATH "${path}" bpath )
if ( IS_ABSOLUTE "${bpath}" )
# Absolute paths are generally unnessary, especially if something like
2012-08-13 21:47:32 +04:00
# file(GLOB_RECURSE) is used to pick up the files.
2013-03-27 14:33:36 +04:00
string ( FIND "${bpath}" "${CMAKE_CURRENT_BINARY_DIR}" _binary_dir_pos )
if ( _binary_dir_pos EQUAL 0 )
file ( RELATIVE_PATH bpath "${CMAKE_CURRENT_BINARY_DIR}" "${bpath}" )
else ( )
file ( RELATIVE_PATH bpath "${CMAKE_CURRENT_SOURCE_DIR}" "${bpath}" )
endif ( )
2011-12-06 06:00:00 +04:00
endif ( )
2014-02-04 22:35:11 +04:00
# This recipe is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the
2011-12-06 06:00:00 +04:00
# CMake source.
# Remove leading /
string ( REGEX REPLACE "^[/]+" "" bpath "${bpath}" )
# Avoid absolute paths by removing ':'
string ( REPLACE ":" "_" bpath "${bpath}" )
# Avoid relative paths that go up the tree
string ( REPLACE "../" "__/" bpath "${bpath}" )
# Avoid spaces
string ( REPLACE " " "_" bpath "${bpath}" )
# Strip off the filename. I wait until here to do it, since removin the
# basename can make a path that looked like path/../basename turn into
# path/.. (notice the trailing slash).
get_filename_component ( bpath "${bpath}" PATH )
set ( ${ build_path } "${bpath}" PARENT_SCOPE )
#message("${build_path} = ${bpath}")
endfunction ( )
2009-09-25 23:42:53 +04:00
##############################################################################
# This helper macro populates the following variables and setups up custom
# commands and targets to invoke the nvcc compiler to generate C or PTX source
2010-07-02 18:58:00 +04:00
# dependent upon the format parameter. The compiler is invoked once with -M
2009-09-25 23:42:53 +04:00
# to generate a dependency file and a second time with -cuda or -ptx to generate
# a .cpp or .ptx file.
# INPUT:
# cuda_target - Target name
2014-04-30 02:01:57 +04:00
# format - PTX, CUBIN, FATBIN or OBJ
2009-09-25 23:42:53 +04:00
# FILE1 .. FILEN - The remaining arguments are the sources to be wrapped.
# OPTIONS - Extra options to NVCC
# OUTPUT:
# generated_files - List of generated files
##############################################################################
##############################################################################
macro ( CUDA_WRAP_SRCS cuda_target format generated_files )
2013-03-05 00:08:20 +04:00
# If CMake doesn't support separable compilation, complain
if ( CUDA_SEPARABLE_COMPILATION AND CMAKE_VERSION VERSION_LESS "2.8.10.1" )
message ( SEND_ERROR "CUDA_SEPARABLE_COMPILATION isn't supported for CMake versions less than 2.8.10.1" )
endif ( )
2012-02-18 19:13:34 +04:00
# Set up all the command line flags here, so that they can be overridden on a per target basis.
2009-09-25 23:42:53 +04:00
set ( nvcc_flags "" )
# Emulation if the card isn't present.
if ( CUDA_BUILD_EMULATION )
# Emulation.
set ( nvcc_flags ${ nvcc_flags } --device-emulation -D_DEVICEEMU -g )
2012-08-13 21:50:14 +04:00
else ( )
2009-09-25 23:42:53 +04:00
# Device mode. No flags necessary.
2012-08-13 21:50:14 +04:00
endif ( )
2009-09-25 23:42:53 +04:00
if ( CUDA_HOST_COMPILATION_CPP )
set ( CUDA_C_OR_CXX CXX )
2012-08-13 21:50:14 +04:00
else ( )
2010-01-08 20:12:54 +03:00
if ( CUDA_VERSION VERSION_LESS "3.0" )
set ( nvcc_flags ${ nvcc_flags } --host-compilation C )
else ( )
2010-01-08 20:57:43 +03:00
message ( WARNING "--host-compilation flag is deprecated in CUDA version >= 3.0. Removing --host-compilation C flag" )
2010-01-08 20:12:54 +03:00
endif ( )
2009-09-25 23:42:53 +04:00
set ( CUDA_C_OR_CXX C )
2012-08-13 21:50:14 +04:00
endif ( )
2009-09-25 23:42:53 +04:00
set ( generated_extension ${ CMAKE_${CUDA_C_OR_CXX } _OUTPUT_EXTENSION} )
if ( CUDA_64_BIT_DEVICE_CODE )
set ( nvcc_flags ${ nvcc_flags } -m64 )
else ( )
set ( nvcc_flags ${ nvcc_flags } -m32 )
endif ( )
2013-10-24 10:04:09 +04:00
if ( CUDA_TARGET_CPU_ARCH )
set ( nvcc_flags ${ nvcc_flags } "--target-cpu-architecture=${CUDA_TARGET_CPU_ARCH}" )
endif ( )
2009-09-25 23:42:53 +04:00
# This needs to be passed in at this stage, because VS needs to fill out the
2012-08-21 01:14:37 +04:00
# value of VCInstallDir from within VS. Note that CCBIN is only used if
# -ccbin or --compiler-bindir isn't used and CUDA_HOST_COMPILER matches
# $(VCInstallDir)/bin.
2009-09-25 23:42:53 +04:00
if ( CMAKE_GENERATOR MATCHES "Visual Studio" )
2012-08-21 01:14:37 +04:00
set ( ccbin_flags -D "\" CCBIN:PATH= $ ( VCInstallDir ) bin\ "" )
2013-03-05 00:08:20 +04:00
else ( )
set ( ccbin_flags )
2009-09-25 23:42:53 +04:00
endif ( )
# Figure out which configure we will use and pass that in as an argument to
# the script. We need to defer the decision until compilation time, because
# for VS projects we won't know if we are making a debug or release build
# until build time.
if ( CMAKE_GENERATOR MATCHES "Visual Studio" )
set ( CUDA_build_configuration "$(ConfigurationName)" )
else ( )
set ( CUDA_build_configuration "${CMAKE_BUILD_TYPE}" )
endif ( )
# Initialize our list of includes with the user ones followed by the CUDA system ones.
set ( CUDA_NVCC_INCLUDE_ARGS ${ CUDA_NVCC_INCLUDE_ARGS_USER } "-I${CUDA_INCLUDE_DIRS}" )
# Get the include directories for this directory and use them for our nvcc command.
2013-04-18 22:48:17 +04:00
# Remove duplicate entries which may be present since include_directories
# in CMake >= 2.8.8 does not remove them.
2009-09-25 23:42:53 +04:00
get_directory_property ( CUDA_NVCC_INCLUDE_DIRECTORIES INCLUDE_DIRECTORIES )
2013-04-18 22:48:17 +04:00
list ( REMOVE_DUPLICATES CUDA_NVCC_INCLUDE_DIRECTORIES )
2009-09-25 23:42:53 +04:00
if ( CUDA_NVCC_INCLUDE_DIRECTORIES )
foreach ( dir ${ CUDA_NVCC_INCLUDE_DIRECTORIES } )
2011-12-06 04:16:05 +04:00
list ( APPEND CUDA_NVCC_INCLUDE_ARGS -I ${ dir } )
2009-09-25 23:42:53 +04:00
endforeach ( )
endif ( )
# Reset these variables
set ( CUDA_WRAP_OPTION_NVCC_FLAGS )
foreach ( config ${ CUDA_configuration_types } )
string ( TOUPPER ${ config } config_upper )
set ( CUDA_WRAP_OPTION_NVCC_FLAGS_ ${ config_upper } )
endforeach ( )
CUDA_GET_SOURCES_AND_OPTIONS ( _cuda_wrap_sources _cuda_wrap_cmake_options _cuda_wrap_options ${ ARGN } )
CUDA_PARSE_NVCC_OPTIONS ( CUDA_WRAP_OPTION_NVCC_FLAGS ${ _cuda_wrap_options } )
2009-11-04 09:15:31 +03:00
# Figure out if we are building a shared library. BUILD_SHARED_LIBS is
# respected in CUDA_ADD_LIBRARY.
set ( _cuda_build_shared_libs FALSE )
2009-09-25 23:42:53 +04:00
# SHARED, MODULE
list ( FIND _cuda_wrap_cmake_options SHARED _cuda_found_SHARED )
list ( FIND _cuda_wrap_cmake_options MODULE _cuda_found_MODULE )
if ( _cuda_found_SHARED GREATER -1 OR _cuda_found_MODULE GREATER -1 )
set ( _cuda_build_shared_libs TRUE )
endif ( )
# STATIC
list ( FIND _cuda_wrap_cmake_options STATIC _cuda_found_STATIC )
if ( _cuda_found_STATIC GREATER -1 )
set ( _cuda_build_shared_libs FALSE )
endif ( )
# CUDA_HOST_FLAGS
if ( _cuda_build_shared_libs )
# If we are setting up code for a shared library, then we need to add extra flags for
# compiling objects for shared libraries.
set ( CUDA_HOST_SHARED_FLAGS ${ CMAKE_SHARED_LIBRARY_${CUDA_C_OR_CXX } _FLAGS} )
2009-11-04 09:15:31 +03:00
else ( )
set ( CUDA_HOST_SHARED_FLAGS )
2009-09-25 23:42:53 +04:00
endif ( )
# Only add the CMAKE_{C,CXX}_FLAGS if we are propagating host flags. We
# always need to set the SHARED_FLAGS, though.
2009-09-29 07:17:13 +04:00
if ( CUDA_PROPAGATE_HOST_FLAGS )
2012-08-21 03:33:35 +04:00
set ( _cuda_host_flags "set(CMAKE_HOST_FLAGS ${CMAKE_${CUDA_C_OR_CXX}_FLAGS} ${CUDA_HOST_SHARED_FLAGS})" )
2009-09-29 07:17:13 +04:00
else ( )
2012-08-21 03:33:35 +04:00
set ( _cuda_host_flags "set(CMAKE_HOST_FLAGS ${CUDA_HOST_SHARED_FLAGS})" )
2009-09-29 07:17:13 +04:00
endif ( )
2012-08-21 03:33:35 +04:00
set ( _cuda_nvcc_flags_config "# Build specific configuration flags" )
2009-09-29 07:17:13 +04:00
# Loop over all the configuration types to generate appropriate flags for run_nvcc.cmake
foreach ( config ${ CUDA_configuration_types } )
string ( TOUPPER ${ config } config_upper )
# CMAKE_FLAGS are strings and not lists. By not putting quotes around CMAKE_FLAGS
# we convert the strings to lists (like we want).
2009-09-25 23:42:53 +04:00
2009-09-29 07:17:13 +04:00
if ( CUDA_PROPAGATE_HOST_FLAGS )
2010-10-05 02:42:21 +04:00
# nvcc chokes on -g3 in versions previous to 3.0, so replace it with -g
2012-06-19 20:04:51 +04:00
set ( _cuda_fix_g3 FALSE )
if ( CMAKE_COMPILER_IS_GNUCC )
if ( CUDA_VERSION VERSION_LESS "3.0" OR
C U D A _ V E R S I O N V E R S I O N _ E Q U A L " 4 . 1 " O R
C U D A _ V E R S I O N V E R S I O N _ E Q U A L " 4 . 2 "
)
set ( _cuda_fix_g3 TRUE )
endif ( )
endif ( )
if ( _cuda_fix_g3 )
2009-09-25 23:42:53 +04:00
string ( REPLACE "-g3" "-g" _cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}" )
else ( )
set ( _cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}" )
endif ( )
2009-09-29 07:17:13 +04:00
2012-08-21 03:33:35 +04:00
set ( _cuda_host_flags "${_cuda_host_flags}\nset(CMAKE_HOST_FLAGS_${config_upper} ${_cuda_C_FLAGS})" )
2009-09-29 07:17:13 +04:00
endif ( )
# Note that if we ever want CUDA_NVCC_FLAGS_<CONFIG> to be string (instead of a list
# like it is currently), we can remove the quotes around the
# ${CUDA_NVCC_FLAGS_${config_upper}} variable like the CMAKE_HOST_FLAGS_<CONFIG> variable.
2012-08-21 03:33:35 +04:00
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}})" )
2009-09-29 07:17:13 +04:00
endforeach ( )
2009-09-25 23:42:53 +04:00
2015-03-22 08:01:24 +03:00
# Process the C++11 flag. If the host sets the flag, we need to add it to nvcc and
# remove it from the host. This is because -Xcompile -std=c++ will choke nvcc (it uses
# the C preprocessor). In order to get this to work correctly, we need to use nvcc's
# specific c++11 flag.
if ( "${_cuda_host_flags}" MATCHES "-std=c\\+\\+11" )
# Add the c++11 flag to nvcc if it isn't already present. Note that we only look at
# the main flag instead of the configuration specific flags.
if ( NOT "${CUDA_NVCC_FLAGS}" MATCHES "-std;c\\+\\+11" )
list ( APPEND nvcc_flags --std c++11 )
endif ( )
string ( REGEX REPLACE "[-]+std=c\\+\\+11" "" _cuda_host_flags "${_cuda_host_flags}" )
endif ( )
2009-09-25 23:42:53 +04:00
# Get the list of definitions from the directory property
get_directory_property ( CUDA_NVCC_DEFINITIONS COMPILE_DEFINITIONS )
if ( CUDA_NVCC_DEFINITIONS )
foreach ( _definition ${ CUDA_NVCC_DEFINITIONS } )
list ( APPEND nvcc_flags "-D${_definition}" )
endforeach ( )
endif ( )
if ( _cuda_build_shared_libs )
list ( APPEND nvcc_flags "-D${cuda_target}_EXPORTS" )
endif ( )
# Reset the output variable
set ( _cuda_wrap_generated_files "" )
# Iterate over the macro arguments and create custom
# commands for all the .cu files.
foreach ( file ${ ARGN } )
# Ignore any file marked as a HEADER_FILE_ONLY
get_source_file_property ( _is_header ${ file } HEADER_FILE_ONLY )
2015-03-27 08:46:35 +03:00
# Allow per source file overrides of the format. Also allows compiling non-.cu files.
get_source_file_property ( _cuda_source_format ${ file } CUDA_SOURCE_PROPERTY_FORMAT )
if ( ( ${ file } MATCHES "\\.cu$" OR _cuda_source_format ) AND NOT _is_header )
2009-09-25 23:42:53 +04:00
2012-08-21 03:33:35 +04:00
if ( NOT _cuda_source_format )
set ( _cuda_source_format ${ format } )
endif ( )
2015-03-27 08:46:35 +03:00
# If file isn't a .cu file, we need to tell nvcc to treat it as such.
if ( NOT ${ file } MATCHES "\\.cu$" )
2015-04-02 02:23:51 +03:00
set ( cuda_language_flag -x=cu )
else ( )
set ( cuda_language_flag )
2015-03-27 08:46:35 +03:00
endif ( )
2012-08-21 03:33:35 +04:00
2014-04-30 02:01:57 +04:00
if ( ${ _cuda_source_format } MATCHES "OBJ" )
set ( cuda_compile_to_external_module OFF )
2012-08-21 03:33:35 +04:00
else ( )
2014-04-30 02:01:57 +04:00
set ( cuda_compile_to_external_module ON )
if ( ${ _cuda_source_format } MATCHES "PTX" )
set ( cuda_compile_to_external_module_type "ptx" )
elseif ( ${ _cuda_source_format } MATCHES "CUBIN" )
set ( cuda_compile_to_external_module_type "cubin" )
elseif ( ${ _cuda_source_format } MATCHES "FATBIN" )
set ( cuda_compile_to_external_module_type "fatbin" )
else ( )
2015-03-27 08:46:35 +03:00
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." )
2014-04-30 02:01:57 +04:00
endif ( )
2012-08-21 03:33:35 +04:00
endif ( )
2014-04-30 02:01:57 +04:00
if ( cuda_compile_to_external_module )
2012-08-21 03:33:35 +04:00
# Don't use any of the host compilation flags for PTX targets.
set ( CUDA_HOST_FLAGS )
set ( CUDA_NVCC_FLAGS_CONFIG )
else ( )
set ( CUDA_HOST_FLAGS ${ _cuda_host_flags } )
set ( CUDA_NVCC_FLAGS_CONFIG ${ _cuda_nvcc_flags_config } )
endif ( )
2011-12-06 06:00:00 +04:00
# Determine output directory
cuda_compute_build_path ( "${file}" cuda_build_path )
set ( cuda_compile_intermediate_directory "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${cuda_build_path}" )
if ( CUDA_GENERATED_OUTPUT_DIR )
set ( cuda_compile_output_dir "${CUDA_GENERATED_OUTPUT_DIR}" )
else ( )
2014-04-30 02:01:57 +04:00
if ( cuda_compile_to_external_module )
2011-12-06 06:00:00 +04:00
set ( cuda_compile_output_dir "${CMAKE_CURRENT_BINARY_DIR}" )
else ( )
set ( cuda_compile_output_dir "${cuda_compile_intermediate_directory}" )
endif ( )
endif ( )
2009-09-25 23:42:53 +04:00
# Add a custom target to generate a c or ptx file. ######################
get_filename_component ( basename ${ file } NAME )
2014-04-30 02:01:57 +04:00
if ( cuda_compile_to_external_module )
2009-09-25 23:42:53 +04:00
set ( generated_file_path "${cuda_compile_output_dir}" )
2014-04-30 02:01:57 +04:00
set ( generated_file_basename "${cuda_target}_generated_${basename}.${cuda_compile_to_external_module_type}" )
set ( format_flag "-${cuda_compile_to_external_module_type}" )
2009-09-25 23:42:53 +04:00
file ( MAKE_DIRECTORY "${cuda_compile_output_dir}" )
2012-08-13 21:50:14 +04:00
else ( )
2009-09-25 23:42:53 +04:00
set ( generated_file_path "${cuda_compile_output_dir}/${CMAKE_CFG_INTDIR}" )
set ( generated_file_basename "${cuda_target}_generated_${basename}${generated_extension}" )
2013-03-05 00:08:20 +04:00
if ( CUDA_SEPARABLE_COMPILATION )
set ( format_flag "-dc" )
else ( )
set ( format_flag "-c" )
endif ( )
2012-08-13 21:50:14 +04:00
endif ( )
2009-09-25 23:42:53 +04:00
# Set all of our file names. Make sure that whatever filenames that have
# generated_file_path in them get passed in through as a command line
# argument, so that the ${CMAKE_CFG_INTDIR} gets expanded at run time
# instead of configure time.
set ( generated_file "${generated_file_path}/${generated_file_basename}" )
2011-12-06 06:00:00 +04:00
set ( cmake_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.depend" )
set ( NVCC_generated_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.NVCC-depend" )
2009-09-25 23:42:53 +04:00
set ( generated_cubin_file "${generated_file_path}/${generated_file_basename}.cubin.txt" )
2011-12-06 06:00:00 +04:00
set ( custom_target_script "${cuda_compile_intermediate_directory}/${generated_file_basename}.cmake" )
2009-09-25 23:42:53 +04:00
# Setup properties for obj files:
2014-04-30 02:01:57 +04:00
if ( NOT cuda_compile_to_external_module )
2009-09-25 23:42:53 +04:00
set_source_files_properties ( "${generated_file}"
P R O P E R T I E S
E X T E R N A L _ O B J E C T t r u e # This is an object file not to be compiled, but only be linked.
)
endif ( )
# Don't add CMAKE_CURRENT_SOURCE_DIR if the path is already an absolute path.
get_filename_component ( file_path "${file}" PATH )
if ( IS_ABSOLUTE "${file_path}" )
set ( source_file "${file}" )
else ( )
set ( source_file "${CMAKE_CURRENT_SOURCE_DIR}/${file}" )
endif ( )
2014-04-30 02:01:57 +04:00
if ( NOT cuda_compile_to_external_module AND CUDA_SEPARABLE_COMPILATION )
2013-03-05 00:08:20 +04:00
list ( APPEND ${ cuda_target } _SEPARABLE_COMPILATION_OBJECTS "${generated_file}" )
endif ( )
2009-09-25 23:42:53 +04:00
# Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND #######
cuda_include_nvcc_dependencies ( ${ cmake_dependency_file } )
# Convience string for output ###########################################
if ( CUDA_BUILD_EMULATION )
set ( cuda_build_type "Emulation" )
2012-08-13 21:50:14 +04:00
else ( )
2009-09-25 23:42:53 +04:00
set ( cuda_build_type "Device" )
2012-08-13 21:50:14 +04:00
endif ( )
2009-09-25 23:42:53 +04:00
# Build the NVCC made dependency file ###################################
set ( build_cubin OFF )
if ( NOT CUDA_BUILD_EMULATION AND CUDA_BUILD_CUBIN )
2014-04-30 02:01:57 +04:00
if ( NOT cuda_compile_to_external_module )
2009-09-25 23:42:53 +04:00
set ( build_cubin ON )
2012-08-13 21:50:14 +04:00
endif ( )
endif ( )
2009-09-25 23:42:53 +04:00
# Configure the build script
configure_file ( "${CUDA_run_nvcc}" "${custom_target_script}" @ONLY )
# So if a user specifies the same cuda file as input more than once, you
# can have bad things happen with dependencies. Here we check an option
# to see if this is the behavior they want.
if ( CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE )
set ( main_dep MAIN_DEPENDENCY ${ source_file } )
else ( )
set ( main_dep DEPENDS ${ source_file } )
endif ( )
if ( CUDA_VERBOSE_BUILD )
set ( verbose_output ON )
elseif ( CMAKE_GENERATOR MATCHES "Makefiles" )
set ( verbose_output "$(VERBOSE)" )
else ( )
set ( verbose_output OFF )
endif ( )
# Create up the comment string
file ( RELATIVE_PATH generated_file_relative_path "${CMAKE_BINARY_DIR}" "${generated_file}" )
2014-04-30 02:01:57 +04:00
if ( cuda_compile_to_external_module )
set ( cuda_build_comment_string "Building NVCC ${cuda_compile_to_external_module_type} file ${generated_file_relative_path}" )
2009-09-25 23:42:53 +04:00
else ( )
set ( cuda_build_comment_string "Building NVCC (${cuda_build_type}) object ${generated_file_relative_path}" )
endif ( )
# Build the generated file and dependency file ##########################
add_custom_command (
O U T P U T $ { g e n e r a t e d _ f i l e }
# These output files depend on the source_file and the contents of cmake_dependency_file
$ { m a i n _ d e p }
D E P E N D S $ { C U D A _ N V C C _ D E P E N D }
D E P E N D S $ { c u s t o m _ t a r g e t _ s c r i p t }
2009-10-07 06:52:52 +04:00
# Make sure the output directory exists before trying to write to it.
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y " $ { g e n e r a t e d _ f i l e _ p a t h } "
2009-09-25 23:42:53 +04:00
C O M M A N D $ { C M A K E _ C O M M A N D } A R G S
- D v e r b o s e : B O O L = $ { v e r b o s e _ o u t p u t }
$ { c c b i n _ f l a g s }
- D b u i l d _ c o n f i g u r a t i o n : S T R I N G = $ { C U D A _ b u i l d _ c o n f i g u r a t i o n }
- D " g e n e r a t e d _ f i l e : S T R I N G = $ { g e n e r a t e d _ f i l e } "
- D " g e n e r a t e d _ c u b i n _ f i l e : S T R I N G = $ { g e n e r a t e d _ c u b i n _ f i l e } "
- P " $ { c u s t o m _ t a r g e t _ s c r i p t } "
2011-12-06 06:00:00 +04:00
W O R K I N G _ D I R E C T O R Y " $ { c u d a _ c o m p i l e _ i n t e r m e d i a t e _ d i r e c t o r y } "
2009-09-25 23:42:53 +04:00
C O M M E N T " $ { c u d a _ b u i l d _ c o m m e n t _ s t r i n g } "
2016-01-15 16:44:15 +03:00
V E R B A T I M
2009-09-25 23:42:53 +04:00
)
# Make sure the build system knows the file is generated.
set_source_files_properties ( ${ generated_file } PROPERTIES GENERATED TRUE )
2013-09-13 18:08:43 +04:00
list ( APPEND _cuda_wrap_generated_files ${ generated_file } )
2009-09-25 23:42:53 +04:00
# Add the other files that we want cmake to clean on a cleanup ##########
list ( APPEND CUDA_ADDITIONAL_CLEAN_FILES "${cmake_dependency_file}" )
list ( REMOVE_DUPLICATES CUDA_ADDITIONAL_CLEAN_FILES )
set ( CUDA_ADDITIONAL_CLEAN_FILES ${ CUDA_ADDITIONAL_CLEAN_FILES } CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning." )
2012-08-13 21:50:14 +04:00
endif ( )
endforeach ( )
2009-09-25 23:42:53 +04:00
# Set the return parameter
set ( ${ generated_files } ${ _cuda_wrap_generated_files } )
2012-08-13 21:50:14 +04:00
endmacro ( )
2009-09-25 23:42:53 +04:00
2013-03-05 00:08:20 +04:00
function ( _cuda_get_important_host_flags important_flags flag_string )
if ( CMAKE_GENERATOR MATCHES "Visual Studio" )
2015-03-27 08:46:35 +03:00
string ( REGEX MATCHALL "/M[DT][d]?" flags "${flag_string}" )
2013-03-05 00:08:20 +04:00
list ( APPEND ${ important_flags } ${ flags } )
else ( )
2015-03-27 08:46:35 +03:00
string ( REGEX MATCHALL "-fPIC" flags "${flag_string}" )
2013-03-05 00:08:20 +04:00
list ( APPEND ${ important_flags } ${ flags } )
endif ( )
set ( ${ important_flags } ${ ${important_flags } } PARENT_SCOPE )
endfunction ( )
###############################################################################
###############################################################################
# Separable Compilation Link
###############################################################################
###############################################################################
# Compute the filename to be used by CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS
function ( CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME output_file_var cuda_target object_files )
if ( object_files )
set ( generated_extension ${ CMAKE_${CUDA_C_OR_CXX } _OUTPUT_EXTENSION} )
set ( output_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${CMAKE_CFG_INTDIR}/${cuda_target}_intermediate_link${generated_extension}" )
else ( )
set ( output_file )
endif ( )
set ( ${ output_file_var } "${output_file}" PARENT_SCOPE )
endfunction ( )
# Setup the build rule for the separable compilation intermediate link file.
function ( CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options object_files )
if ( object_files )
set_source_files_properties ( "${output_file}"
P R O P E R T I E S
E X T E R N A L _ O B J E C T T R U E # This is an object file not to be compiled, but only
# be linked.
G E N E R A T E D T R U E # This file is generated during the build
)
# For now we are ignoring all the configuration specific flags.
set ( nvcc_flags )
CUDA_PARSE_NVCC_OPTIONS ( nvcc_flags ${ options } )
if ( CUDA_64_BIT_DEVICE_CODE )
list ( APPEND nvcc_flags -m64 )
else ( )
list ( APPEND nvcc_flags -m32 )
endif ( )
# If -ccbin, --compiler-bindir has been specified, don't do anything. Otherwise add it here.
list ( FIND nvcc_flags "-ccbin" ccbin_found0 )
list ( FIND nvcc_flags "--compiler-bindir" ccbin_found1 )
2014-06-12 21:46:50 +04:00
if ( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 AND CUDA_HOST_COMPILER )
2013-03-05 00:08:20 +04:00
list ( APPEND nvcc_flags -ccbin "\" ${ CUDA_HOST_COMPILER } \"")
endif ( )
2015-01-07 02:28:05 +03:00
# Create a list of flags specified by CUDA_NVCC_FLAGS_${CONFIG} and CMAKE_${CUDA_C_OR_CXX}_FLAGS*
2014-05-18 10:26:26 +04:00
set ( config_specific_flags )
2013-03-05 00:08:20 +04:00
set ( flags )
foreach ( config ${ CUDA_configuration_types } )
string ( TOUPPER ${ config } config_upper )
2014-05-18 10:26:26 +04:00
# Add config specific flags
foreach ( f ${ CUDA_NVCC_FLAGS_${config_upper } } )
list ( APPEND config_specific_flags $< $<CONFIG:${config} > : ${ f } > )
endforeach ( )
2013-03-05 00:08:20 +04:00
set ( important_host_flags )
2015-03-27 08:46:35 +03:00
_cuda_get_important_host_flags ( important_host_flags "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}" )
2013-03-05 00:08:20 +04:00
foreach ( f ${ important_host_flags } )
list ( APPEND flags $< $<CONFIG:${config} > :-Xcompiler> $< $<CONFIG:${config} > : ${ f } > )
endforeach ( )
endforeach ( )
2015-01-07 02:28:05 +03:00
# Add CMAKE_${CUDA_C_OR_CXX}_FLAGS
set ( important_host_flags )
2015-03-27 08:46:35 +03:00
_cuda_get_important_host_flags ( important_host_flags "${CMAKE_${CUDA_C_OR_CXX}_FLAGS}" )
2015-01-07 02:28:05 +03:00
foreach ( f ${ important_host_flags } )
list ( APPEND flags -Xcompiler ${ f } )
endforeach ( )
2014-05-18 10:26:26 +04:00
# Add our general CUDA_NVCC_FLAGS with the configuration specifig flags
set ( nvcc_flags ${ CUDA_NVCC_FLAGS } ${ config_specific_flags } ${ nvcc_flags } )
2013-03-05 00:08:20 +04:00
file ( RELATIVE_PATH output_file_relative_path "${CMAKE_BINARY_DIR}" "${output_file}" )
2013-03-14 09:57:37 +04:00
# Some generators don't handle the multiple levels of custom command
# dependencies correctly (obj1 depends on file1, obj2 depends on obj1), so
# we work around that issue by compiling the intermediate link object as a
# pre-link custom command in that situation.
set ( do_obj_build_rule TRUE )
2015-08-20 17:28:07 +03:00
if ( MSVC_VERSION GREATER 1599 AND MSVC_VERSION LESS 1800 )
# VS 2010 and 2012 have this problem.
2013-03-14 09:57:37 +04:00
set ( do_obj_build_rule FALSE )
endif ( )
if ( do_obj_build_rule )
add_custom_command (
O U T P U T $ { o u t p u t _ f i l e }
D E P E N D S $ { o b j e c t _ f i l e s }
C O M M A N D $ { C U D A _ N V C C _ E X E C U T A B L E } $ { n v c c _ f l a g s } - d l i n k $ { o b j e c t _ f i l e s } - o $ { o u t p u t _ f i l e }
$ { f l a g s }
C O M M E N T " B u i l d i n g N V C C i n t e r m e d i a t e l i n k f i l e $ { o u t p u t _ f i l e _ r e l a t i v e _ p a t h } "
2016-01-15 16:44:15 +03:00
V E R B A T I M
2013-03-14 09:57:37 +04:00
)
else ( )
2015-04-16 19:27:23 +03:00
get_filename_component ( output_file_dir "${output_file}" DIRECTORY )
2013-03-14 09:57:37 +04:00
add_custom_command (
T A R G E T $ { c u d a _ t a r g e t }
P R E _ L I N K
C O M M A N D $ { C M A K E _ C O M M A N D } - E e c h o " B u i l d i n g N V C C i n t e r m e d i a t e l i n k f i l e $ { o u t p u t _ f i l e _ r e l a t i v e _ p a t h } "
2015-04-16 19:27:23 +03:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E m a k e _ d i r e c t o r y " $ { o u t p u t _ f i l e _ d i r } "
2013-03-14 09:57:37 +04:00
C O M M A N D $ { C U D A _ N V C C _ E X E C U T A B L E } $ { n v c c _ f l a g s } $ { f l a g s } - d l i n k $ { o b j e c t _ f i l e s } - o " $ { o u t p u t _ f i l e } "
2016-01-15 16:44:15 +03:00
V E R B A T I M
2013-03-14 09:57:37 +04:00
)
endif ( )
2013-03-05 00:08:20 +04:00
endif ( )
endfunction ( )
2009-09-25 23:42:53 +04:00
###############################################################################
###############################################################################
# ADD LIBRARY
###############################################################################
###############################################################################
macro ( CUDA_ADD_LIBRARY cuda_target )
CUDA_ADD_CUDA_INCLUDE_ONCE ( )
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS ( _sources _cmake_options _options ${ ARGN } )
2009-11-04 09:15:31 +03:00
CUDA_BUILD_SHARED_LIBRARY ( _cuda_shared_flag ${ ARGN } )
2009-09-25 23:42:53 +04:00
# Create custom commands and targets for each file.
2009-11-04 09:15:31 +03:00
CUDA_WRAP_SRCS ( ${ cuda_target } OBJ _generated_files ${ _sources }
$ { _ c m a k e _ o p t i o n s } $ { _ c u d a _ s h a r e d _ f l a g }
2009-09-25 23:42:53 +04:00
O P T I O N S $ { _ o p t i o n s } )
2013-03-05 00:08:20 +04:00
# Compute the file name of the intermedate link file used for separable
# compilation.
CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME ( link_file ${ cuda_target } "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}" )
2009-09-25 23:42:53 +04:00
# Add the library.
add_library ( ${ cuda_target } ${ _cmake_options }
$ { _ g e n e r a t e d _ f i l e s }
$ { _ s o u r c e s }
2013-03-05 00:08:20 +04:00
$ { l i n k _ f i l e }
2009-09-25 23:42:53 +04:00
)
2013-03-05 00:08:20 +04:00
# Add a link phase for the separable compilation if it has been enabled. If
# it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS
# variable will have been defined.
CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS ( "${link_file}" ${ cuda_target } "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}" )
2009-09-25 23:42:53 +04:00
target_link_libraries ( ${ cuda_target }
$ { C U D A _ L I B R A R I E S }
)
# We need to set the linker language based on what the expected generated file
# would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP.
set_target_properties ( ${ cuda_target }
P R O P E R T I E S
L I N K E R _ L A N G U A G E $ { C U D A _ C _ O R _ C X X }
)
2012-08-13 21:50:14 +04:00
endmacro ( )
2009-09-25 23:42:53 +04:00
###############################################################################
###############################################################################
# ADD EXECUTABLE
###############################################################################
###############################################################################
macro ( CUDA_ADD_EXECUTABLE cuda_target )
CUDA_ADD_CUDA_INCLUDE_ONCE ( )
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS ( _sources _cmake_options _options ${ ARGN } )
# Create custom commands and targets for each file.
CUDA_WRAP_SRCS ( ${ cuda_target } OBJ _generated_files ${ _sources } OPTIONS ${ _options } )
2013-03-05 00:08:20 +04:00
# Compute the file name of the intermedate link file used for separable
# compilation.
CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME ( link_file ${ cuda_target } "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}" )
2009-09-25 23:42:53 +04:00
# Add the library.
add_executable ( ${ cuda_target } ${ _cmake_options }
$ { _ g e n e r a t e d _ f i l e s }
$ { _ s o u r c e s }
2013-03-05 00:08:20 +04:00
$ { l i n k _ f i l e }
2009-09-25 23:42:53 +04:00
)
2013-03-05 00:08:20 +04:00
# Add a link phase for the separable compilation if it has been enabled. If
# it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS
# variable will have been defined.
CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS ( "${link_file}" ${ cuda_target } "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}" )
2009-09-25 23:42:53 +04:00
target_link_libraries ( ${ cuda_target }
$ { C U D A _ L I B R A R I E S }
)
# We need to set the linker language based on what the expected generated file
# would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP.
set_target_properties ( ${ cuda_target }
P R O P E R T I E S
L I N K E R _ L A N G U A G E $ { C U D A _ C _ O R _ C X X }
)
2012-08-13 21:50:14 +04:00
endmacro ( )
2009-09-25 23:42:53 +04:00
###############################################################################
###############################################################################
2014-04-30 02:01:57 +04:00
# (Internal) helper for manually added cuda source files with specific targets
2009-09-25 23:42:53 +04:00
###############################################################################
###############################################################################
2014-04-30 02:01:57 +04:00
macro ( cuda_compile_base cuda_target format generated_files )
2009-09-25 23:42:53 +04:00
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS ( _sources _cmake_options _options ${ ARGN } )
# Create custom commands and targets for each file.
2014-04-30 02:01:57 +04:00
CUDA_WRAP_SRCS ( ${ cuda_target } ${ format } _generated_files ${ _sources } ${ _cmake_options }
2009-09-25 23:42:53 +04:00
O P T I O N S $ { _ o p t i o n s } )
set ( ${ generated_files } ${ _generated_files } )
2012-08-13 21:50:14 +04:00
endmacro ( )
2009-09-25 23:42:53 +04:00
2014-04-30 02:01:57 +04:00
###############################################################################
###############################################################################
# CUDA COMPILE
###############################################################################
###############################################################################
macro ( CUDA_COMPILE generated_files )
cuda_compile_base ( cuda_compile OBJ ${ generated_files } ${ ARGN } )
endmacro ( )
2009-09-25 23:42:53 +04:00
###############################################################################
###############################################################################
# CUDA COMPILE PTX
###############################################################################
###############################################################################
macro ( CUDA_COMPILE_PTX generated_files )
2014-04-30 02:01:57 +04:00
cuda_compile_base ( cuda_compile_ptx PTX ${ generated_files } ${ ARGN } )
endmacro ( )
2009-09-25 23:42:53 +04:00
2014-04-30 02:01:57 +04:00
###############################################################################
###############################################################################
# CUDA COMPILE FATBIN
###############################################################################
###############################################################################
macro ( CUDA_COMPILE_FATBIN generated_files )
cuda_compile_base ( cuda_compile_fatbin FATBIN ${ generated_files } ${ ARGN } )
endmacro ( )
2009-09-25 23:42:53 +04:00
2014-04-30 02:01:57 +04:00
###############################################################################
###############################################################################
# CUDA COMPILE CUBIN
###############################################################################
###############################################################################
macro ( CUDA_COMPILE_CUBIN generated_files )
cuda_compile_base ( cuda_compile_cubin CUBIN ${ generated_files } ${ ARGN } )
2012-08-13 21:50:14 +04:00
endmacro ( )
2009-09-25 23:42:53 +04:00
2014-04-30 02:01:57 +04:00
2009-09-25 23:42:53 +04:00
###############################################################################
###############################################################################
# CUDA ADD CUFFT TO TARGET
###############################################################################
###############################################################################
macro ( CUDA_ADD_CUFFT_TO_TARGET target )
if ( CUDA_BUILD_EMULATION )
target_link_libraries ( ${ target } ${ CUDA_cufftemu_LIBRARY } )
else ( )
target_link_libraries ( ${ target } ${ CUDA_cufft_LIBRARY } )
endif ( )
endmacro ( )
###############################################################################
###############################################################################
# CUDA ADD CUBLAS TO TARGET
###############################################################################
###############################################################################
macro ( CUDA_ADD_CUBLAS_TO_TARGET target )
if ( CUDA_BUILD_EMULATION )
target_link_libraries ( ${ target } ${ CUDA_cublasemu_LIBRARY } )
else ( )
target_link_libraries ( ${ target } ${ CUDA_cublas_LIBRARY } )
endif ( )
endmacro ( )
###############################################################################
###############################################################################
# CUDA BUILD CLEAN TARGET
###############################################################################
###############################################################################
macro ( CUDA_BUILD_CLEAN_TARGET )
# Call this after you add all your CUDA targets, and you will get a convience
# target. You should also make clean after running this target to get the
# build system to generate all the code again.
set ( cuda_clean_target_name clean_cuda_depends )
if ( CMAKE_GENERATOR MATCHES "Visual Studio" )
string ( TOUPPER ${ cuda_clean_target_name } cuda_clean_target_name )
endif ( )
add_custom_target ( ${ cuda_clean_target_name }
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e m o v e $ { C U D A _ A D D I T I O N A L _ C L E A N _ F I L E S } )
# Clear out the variable, so the next time we configure it will be empty.
# This is useful so that the files won't persist in the list after targets
# have been removed.
set ( CUDA_ADDITIONAL_CLEAN_FILES "" CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning." )
2012-08-13 21:50:14 +04:00
endmacro ( )