Update FindCUDA.

pull/216/head
castano 14 years ago
parent 322dcd72c1
commit 357b91a9b2

@ -1,132 +1,156 @@
###############################################################################
# For more information, please see: http://software.sci.utah.edu
# - 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.
#
# The MIT License
# 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.
#
# Copyright (c) 2008-2009
# NVIDIA Corp.
# 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.
#
# Copyright (c) 2007-2009
# Scientific Computing and Imaging Institute, University of Utah
# It might be necessary to set CUDA_TOOLKIT_ROOT_DIR manually on certain
# 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.
#
# 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 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 CUDA_ADD_EXECUTABLE,
# CUDA_ADD_LIBRARY, CUDA_COMPILE, CUDA_COMPILE_PTX or CUDA_WRAP_SRCS.
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
# 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.
#
# 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.
# 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 script locates the Nvidia Compute Unified Driver Architecture (CUDA)
# tools. It should work on linux, windows, and mac and should be reasonably
# up to date with cuda releases.
# 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.
#
# 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.
# 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.
#
# 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. 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).
# 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.
#
# Set CUDA_BUILD_EMULATION to ON for Emulation mode. Defaults to OFF (device
# mode).
# _DEVICEEMU is defined 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.
#
# Set CUDA_HOST_COMPILATION_CPP to OFF for C compilation of host code.
# Default TRUE.
# CUDA_HOST_COMPILATION_CPP (Default ON)
# -- Set to OFF for C compilation of host code.
#
# Set CUDA_BUILD_CUBIN to "ON" or "OFF" 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. Default ON.
# 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)
#
# Set CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE to ON if you want the custom build
# rule to be attached to the source file in Visual Studio. Defaults to ON.
# Turn OFF if you add the same cuda file to multiple targets.
# 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.
#
# 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. This is
# because 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. Therefore,
# the rule assigned to the source file really only applies to one target you get
# clashes when it is run from multiple targets. Eventually everything will get
# built, but if the user is unaware of this behavior, there may be confusion.
# It would be nice if we 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_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.
#
# Set CUDA_64_BIT_DEVICE_CODE to ON to compile for 64 bit devices. Defaults to
# match host bit size. Note that making this different than the host code when
# generating 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.
# The script creates the following macros (in alphebetical order):
#
# Set CUDA_VERBOSE_BUILD 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). You can override this by setting
# CUDA_VERBOSE_BUILD to ON.
# 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.
#
# Set CUDA_GENERATED_OUTPUT_DIR 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.
# 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.
#
# The script creates the following macros:
# 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_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 ... [OPTIONS ...] )
# -- Creates a shared library "cuda_target" which contains all of the source
# (*.c, *.cc, etc.) specified and all of the nvcc'ed .cu files specified.
# All of the specified source files and generated .cpp files are compiled
# using the standard CMake compiler, so the normal INCLUDE_DIRECTORIES,
# LINK_DIRECTORIES, and TARGET_LINK_LIBRARIES can be used to affect their
# build and link. In addition CUDA_INCLUDE_DIRS is added automatically added
# to include_directories().
# 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_ADD_EXECUTABLE( cuda_target file0 file1 ... [OPTIONS ...] )
# -- Same as CUDA_ADD_LIBRARY except that an exectuable 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 ... [OPTIONS ...] )
# 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.
#
# 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_WRAP_SRCS ( cuda_target format generated_files file0 file1 ...
# [OPTIONS ...] )
# [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.
# 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.
# 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.
# 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
@ -136,59 +160,56 @@
#
# 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 and will link in the
# resulting object file automatically.
# 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 serveral 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
# checks the error codes and produces errors when there was a problem.
#
# 2. nvcc has been known to not delete intermediate results when it
# encounters problems. The build rules then don't complete, because there
# exists a partially written output file. The script now deletes the
# output files if there was an error.
# 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, when the options change the
# output files will be regenerated.
# make the build rule dependent on the file, the output files will be
# regenerated when the options change.
#
# CUDA_ADD_CUFFT_TO_TARGET( cuda_target )
# -- Adds the cufft library to the target. Handles whether you are in emulation
# mode or not.
# 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.
#
# CUDA_ADD_CUBLAS_TO_TARGET( cuda_target )
# -- Adds the cublas library to the target. Handles whether you are in emulation
# mode or not.
#
# 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.
# Flags passed into add_definitions with -D or /D are passed along to nvcc.
#
# The script defines the following variables:
#
# ( Note CUDA_ADD_* macros setup cuda/cut library dependencies automatically.
# These variables are only needed if a cuda API call must be made from code in
# a outside library or executable. )
#
# 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_CUT_INCLUDE_DIR -- Include directory for cuda SDK headers (cutil.h).
# CUDA_CUT_LIBRARIES -- SDK libraries.
# CUDA_NVCC_FLAGS -- Additional NVCC command line arguments. NOTE:
# multiple arguments must be semi-colon delimited
# e.g. --compiler-options;-Wall
# CUDA_NVCC_FLAGS_<CONFIG> -- Confugration specific flags for NVCC.
# CUDA_CUFFT_LIBRARIES -- Device or emulation library for the Cuda FFT
# implementation (alternative to:
# CUDA_ADD_CUFFT_TO_TARGET macro)
@ -197,35 +218,45 @@
# CUDA_ADD_CUBLAS_TO_TARGET macro).
#
#
# The script now builds object files instead of generating C files. In order to
# facilitate this, the script now makes use of the CMAKE_{C,CXX}_FLAGS along
# with their configuration dependent counterparts (i.e. CMAKE_C_FLAGS_DEBUG).
# These flags are passed through nvcc to the native compiler. In addition, on
# some systems special flags are added for building objects intended for shared
# libraries. FindCUDA make use of the CMake variable BUILD_SHARED_LIBS to
# determine if these flags should be used. Please set this variable according
# to how the objects are to be used before calling CUDA_ADD_LIBRARY. A
# preprocessor macro, <target_name>_EXPORTS is defined when BUILD_SHARED_LIBS is
# defined. In addition, flags passed into add_definitions with -D or /D are
# passed along to nvcc.
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
#
# Files with the HEADER_FILE_ONLY property set will not be compiled.
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
#
# It might be necessary to set CUDA_TOOLKIT_ROOT_DIR manually on certain 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.
# 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.
# 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.
#
# -- Abe Stephens SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
# -- James Bigler NVIDIA Corp
###############################################################################
# FindCUDA.cmake
# We need to have at least this version to support the VERSION_LESS argument to 'if'.
# We need to have at least this version to support the VERSION_LESS argument to 'if' (2.6.2) and unset (2.6.3)
cmake_policy(PUSH)
cmake_minimum_required(VERSION 2.6.2)
cmake_minimum_required(VERSION 2.6.3)
cmake_policy(POP)
# This macro helps us find the location of helper files we will need the full path to
@ -235,7 +266,7 @@ macro(CUDA_FIND_HELPER_FILE _name _extension)
# 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)
find_file(CUDA_${_name} ${_full_name} PATHS ${CMAKE_CURRENT_LIST_DIR} NO_DEFAULT_PATH)
find_file(CUDA_${_name} ${_full_name} PATHS ${CMAKE_CURRENT_LIST_DIR}/FindCUDA NO_DEFAULT_PATH)
if(NOT CUDA_${_name})
set(error_message "${_full_name} not found in CMAKE_MODULE_PATH")
if(CUDA_FIND_REQUIRED)
@ -315,14 +346,10 @@ endmacro(CUDA_INCLUDE_NVCC_DEPENDENCIES)
###############################################################################
###############################################################################
# Setup default variables
# Setup variables' defaults
###############################################################################
###############################################################################
# Set whether we are using emulation or device mode.
option(CUDA_BUILD_EMULATION "Build in Emulation mode" OFF)
# Parse HOST_COMPILATION mode.
option(CUDA_HOST_COMPILATION_CPP "Generated file extension" ON)
# 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)
@ -330,22 +357,38 @@ 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." ON)
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.")
# 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)
# 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)
# 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)
# 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")
mark_as_advanced(
CUDA_HOST_COMPILATION_CPP
CUDA_64_BIT_DEVICE_CODE
CUDA_NVCC_FLAGS
CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE
CUDA_GENERATED_OUTPUT_DIR
CUDA_HOST_COMPILATION_CPP
CUDA_NVCC_FLAGS
CUDA_PROPAGATE_HOST_FLAGS
)
# Makefile and similar generators don't define CMAKE_CONFIGURATION_TYPES, so we
@ -383,8 +426,11 @@ if(NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}")
endif()
if(NOT "${CUDA_SDK_ROOT_DIR}" STREQUAL "${CUDA_SDK_ROOT_DIR_INTERNAL}")
unset(CUDA_CUT_INCLUDE_DIR CACHE)
unset(CUDA_CUT_LIBRARY CACHE)
# 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)
endif()
# Search for the cuda distribution.
@ -406,7 +452,7 @@ if(NOT CUDA_TOOLKIT_ROOT_DIR)
)
if (CUDA_TOOLKIT_ROOT_DIR)
string(REGEX REPLACE "[/\\\\]?bin[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${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)
endif(CUDA_TOOLKIT_ROOT_DIR)
@ -423,6 +469,7 @@ endif (NOT CUDA_TOOLKIT_ROOT_DIR)
find_program(CUDA_NVCC_EXECUTABLE
NAMES nvcc
PATHS "${CUDA_TOOLKIT_ROOT_DIR}/bin"
"${CUDA_TOOLKIT_ROOT_DIR}/bin64"
ENV CUDA_BIN_PATH
NO_DEFAULT_PATH
)
@ -432,7 +479,7 @@ mark_as_advanced(CUDA_NVCC_EXECUTABLE)
if(CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION)
# Compute the version.
exec_program(${CUDA_NVCC_EXECUTABLE} ARGS "--version" OUTPUT_VARIABLE NVCC_OUT)
execute_process (COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
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.")
@ -481,9 +528,13 @@ set (CUDA_NVCC_INCLUDE_ARGS_USER "")
set (CUDA_INCLUDE_DIRS ${CUDA_TOOLKIT_INCLUDE})
macro(FIND_LIBRARY_LOCAL_FIRST _var _names _doc)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_cuda_64bit_lib_dir "${CUDA_TOOLKIT_ROOT_DIR}/lib64")
endif()
find_library(${_var}
NAMES ${_names}
PATHS "${CUDA_TOOLKIT_ROOT_DIR}/lib"
PATHS ${_cuda_64bit_lib_dir}
"${CUDA_TOOLKIT_ROOT_DIR}/lib"
ENV CUDA_LIB_PATH
DOC ${_doc}
NO_DEFAULT_PATH
@ -495,6 +546,14 @@ endmacro()
# CUDA_LIBRARIES
find_library_local_first(CUDA_CUDART_LIBRARY cudart "\"cudart\" library")
set(CUDA_LIBRARIES ${CUDA_CUDART_LIBRARY})
if(APPLE)
# We need to add the path to cudart to the linker using rpath, since the
# library name for the cuda libraries is prepended with @rpath.
get_filename_component(_cuda_path_to_cudart "${CUDA_CUDART_LIBRARY}" PATH)
if(_cuda_path_to_cudart)
list(APPEND CUDA_LIBRARIES -Wl,-rpath "-Wl,${_cuda_path_to_cudart}")
endif()
endif()
# 1.1 toolkit on linux doesn't appear to have a separate library on
# some platforms.
@ -536,6 +595,7 @@ endif()
find_path(CUDA_SDK_ROOT_DIR common/inc/cutil.h
"$ENV{NVSDKCUDA_ROOT}"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Installed Products\\NVIDIA SDK 10\\Compute;InstallDir]"
"/Developer/GPU\ Computing/C"
)
# Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the
@ -549,43 +609,46 @@ set(CUDA_SDK_SEARCH_PATH
"$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX"
"/Developer/CUDA"
)
# CUDA_CUT_INCLUDE_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 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")
# CUDA_CUT_LIBRARIES
# mark_as_advanced(CUDA_CUT_INCLUDE_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)
else(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(cuda_cutil_name cutil32)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
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})
# 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)
# else(CMAKE_SIZEOF_VOID_P EQUAL 8)
# set(cuda_cutil_name cutil32)
# endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
# 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})
@ -632,13 +695,23 @@ cuda_find_helper_file(run_nvcc cmake)
##############################################################################
# Separate the OPTIONS out from the sources
#
macro(CUDA_GET_SOURCES_AND_OPTIONS _sources _options)
macro(CUDA_GET_SOURCES_AND_OPTIONS _sources _cmake_options _options)
set( ${_sources} )
set( ${_cmake_options} )
set( ${_options} )
set( _found_options FALSE )
foreach(arg ${ARGN})
if(arg STREQUAL "OPTIONS")
set( _found_options TRUE )
elseif(
arg STREQUAL "WIN32" OR
arg STREQUAL "MACOSX_BUNDLE" OR
arg STREQUAL "EXCLUDE_FROM_ALL" OR
arg STREQUAL "STATIC" OR
arg STREQUAL "SHARED" OR
arg STREQUAL "MODULE"
)
list(APPEND ${_cmake_options} "${arg}")
else()
if ( _found_options )
list(APPEND ${_options} "${arg}")
@ -689,6 +762,27 @@ function(CUDA_ADD_CUDA_INCLUDE_ONCE)
endif()
endfunction()
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
_cuda_found_MODULE GREATER -1 OR
_cuda_found_STATIC GREATER -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()
##############################################################################
# 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
@ -730,7 +824,11 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
if(CUDA_HOST_COMPILATION_CPP)
set(CUDA_C_OR_CXX CXX)
else(CUDA_HOST_COMPILATION_CPP)
if(CUDA_VERSION VERSION_LESS "3.0")
set(nvcc_flags ${nvcc_flags} --host-compilation C)
else()
message(WARNING "--host-compilation flag is deprecated in CUDA version >= 3.0. Removing --host-compilation C flag" )
endif()
set(CUDA_C_OR_CXX C)
endif(CUDA_HOST_COMPILATION_CPP)
@ -778,16 +876,40 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
set(CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper})
endforeach()
CUDA_GET_SOURCES_AND_OPTIONS(_cuda_wrap_sources _cuda_wrap_options ${ARGN})
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})
# Figure out if we are building a shared library. BUILD_SHARED_LIBS is
# respected in CUDA_ADD_LIBRARY.
set(_cuda_build_shared_libs FALSE)
# 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(BUILD_SHARED_LIBS)
# If BUILD_SHARED_LIBS is true, then we need to add extra flags for
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})
else()
set(CUDA_HOST_SHARED_FLAGS)
endif()
# Only add the CMAKE_{C,CXX}_FLAGS if we are propagating host flags. We
# always need to set the SHARED_FLAGS, though.
if(CUDA_PROPAGATE_HOST_FLAGS)
set(CUDA_HOST_FLAGS "set(CMAKE_HOST_FLAGS ${CMAKE_${CUDA_C_OR_CXX}_FLAGS} ${CUDA_HOST_SHARED_FLAGS})")
else()
set(CUDA_HOST_FLAGS "set(CMAKE_HOST_FLAGS ${CUDA_HOST_SHARED_FLAGS})")
endif()
set(CUDA_NVCC_FLAGS_CONFIG "# Build specific configuration flags")
# Loop over all the configuration types to generate appropriate flags for run_nvcc.cmake
foreach(config ${CUDA_configuration_types})
@ -795,19 +917,29 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
# CMAKE_FLAGS are strings and not lists. By not putting quotes around CMAKE_FLAGS
# we convert the strings to lists (like we want).
if(CUDA_PROPAGATE_HOST_FLAGS)
# nvcc chokes on -g3, so replace it with -g
if(CMAKE_COMPILER_IS_GNUCC)
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()
set(CUDA_HOST_FLAGS "${CUDA_HOST_FLAGS}\nset(CMAKE_HOST_FLAGS_${config_upper} ${_cuda_C_FLAGS})")
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.
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}}\")")
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}}\")")
endforeach()
if(compile_to_ptx)
# Don't use any of the host compilation flags for PTX targets.
set(CUDA_HOST_FLAGS)
set(CUDA_NVCC_FLAGS_CONFIG)
endif()
# Get the list of definitions from the directory property
get_directory_property(CUDA_NVCC_DEFINITIONS COMPILE_DEFINITIONS)
if(CUDA_NVCC_DEFINITIONS)
@ -816,7 +948,7 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
endforeach()
endif()
if(BUILD_SHARED_LIBS)
if(_cuda_build_shared_libs)
list(APPEND nvcc_flags "-D${cuda_target}_EXPORTS")
endif()
@ -856,10 +988,10 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
# 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}")
set(cmake_dependency_file "${CMAKE_CURRENT_BINARY_DIR}/${generated_file_basename}.depend")
set(NVCC_generated_dependency_file "${CMAKE_CURRENT_BINARY_DIR}/${generated_file_basename}.NVCC-depend")
set(cmake_dependency_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${generated_file_basename}.depend")
set(NVCC_generated_dependency_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${generated_file_basename}.NVCC-depend")
set(generated_cubin_file "${generated_file_path}/${generated_file_basename}.cubin.txt")
set(custom_target_script "${CMAKE_CURRENT_BINARY_DIR}/${generated_file_basename}.cmake")
set(custom_target_script "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${generated_file_basename}.cmake")
# Setup properties for obj files:
if( NOT compile_to_ptx )
@ -930,6 +1062,8 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
${main_dep}
DEPENDS ${CUDA_NVCC_DEPEND}
DEPENDS ${custom_target_script}
# Make sure the output directory exists before trying to write to it.
COMMAND ${CMAKE_COMMAND} -E make_directory "${generated_file_path}"
COMMAND ${CMAKE_COMMAND} ARGS
-D verbose:BOOL=${verbose_output}
${ccbin_flags}
@ -951,6 +1085,7 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
if(NOT compile_to_ptx AND CMAKE_GENERATOR MATCHES "Visual Studio" AND CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE)
# Visual Studio 8 crashes when you close the solution when you don't add the object file.
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio 8")
#message("Not adding ${generated_file}")
set(cuda_add_generated_file FALSE)
endif()
endif()
@ -982,12 +1117,15 @@ macro(CUDA_ADD_LIBRARY cuda_target)
CUDA_ADD_CUDA_INCLUDE_ONCE()
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS(_sources _options ${ARGN})
CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
CUDA_BUILD_SHARED_LIBRARY(_cuda_shared_flag ${ARGN})
# Create custom commands and targets for each file.
CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources} OPTIONS ${_options} )
CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources}
${_cmake_options} ${_cuda_shared_flag}
OPTIONS ${_options} )
# Add the library.
add_library(${cuda_target}
add_library(${cuda_target} ${_cmake_options}
${_generated_files}
${_sources}
)
@ -1016,12 +1154,12 @@ macro(CUDA_ADD_EXECUTABLE cuda_target)
CUDA_ADD_CUDA_INCLUDE_ONCE()
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS(_sources _options ${ARGN})
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} )
# Add the library.
add_executable(${cuda_target}
add_executable(${cuda_target} ${_cmake_options}
${_generated_files}
${_sources}
)
@ -1048,9 +1186,10 @@ endmacro(CUDA_ADD_EXECUTABLE cuda_target)
macro(CUDA_COMPILE generated_files)
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS(_sources _options ${ARGN})
CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
# Create custom commands and targets for each file.
CUDA_WRAP_SRCS( cuda_compile OBJ _generated_files ${_sources} OPTIONS ${_options} )
CUDA_WRAP_SRCS( cuda_compile OBJ _generated_files ${_sources} ${_cmake_options}
OPTIONS ${_options} )
set( ${generated_files} ${_generated_files})
@ -1065,9 +1204,10 @@ endmacro(CUDA_COMPILE)
macro(CUDA_COMPILE_PTX generated_files)
# Separate the sources from the options
CUDA_GET_SOURCES_AND_OPTIONS(_sources _options ${ARGN})
CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN})
# Create custom commands and targets for each file.
CUDA_WRAP_SRCS( cuda_compile_ptx PTX _generated_files ${_sources} OPTIONS ${_options} )
CUDA_WRAP_SRCS( cuda_compile_ptx PTX _generated_files ${_sources} ${_cmake_options}
OPTIONS ${_options} )
set( ${generated_files} ${_generated_files})

@ -1,11 +1,16 @@
# For more information, please see: http://software.sci.utah.edu
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
#
# The MIT License
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
#
# Copyright (c) 2007
# 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.
# 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"),
@ -24,11 +29,11 @@
# 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.
#
# Make2cmake CMake Script
# Abe Stephens and James Bigler
# (c) 2007 Scientific Computing and Imaging Institute, University of Utah
# Note that the REGEX expressions may need to be tweaked for different dependency generators.
#######################################################################
# This converts a file written in makefile syntax into one that can be included
# by CMake.
file(READ ${input_file} depend_text)
@ -43,12 +48,18 @@ if (${depend_text} MATCHES ".+")
string(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})
set(dependency_list "")
foreach(file ${depend_text})
string(REGEX REPLACE "^ +" "" file ${file})
if(NOT IS_DIRECTORY ${file})
set(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n")
# If softlinks start to matter, we should change this to REALPATH. For now we need
# to flatten paths, because nvcc can generate stuff like /bin/../include instead of
# just /include.
get_filename_component(file_absolute "${file}" ABSOLUTE)
list(APPEND dependency_list "${file_absolute}")
endif(NOT IS_DIRECTORY ${file})
endforeach(file)
@ -57,5 +68,12 @@ else()
# message("FOUND NO DEPENDS")
endif()
# Remove the duplicate entries and sort them.
list(REMOVE_DUPLICATES dependency_list)
list(SORT dependency_list)
foreach(file ${dependency_list})
set(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n")
endforeach()
file(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n")

@ -1,10 +1,16 @@
# For more information, please see: http://software.sci.utah.edu
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
# Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
#
# The MIT License
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
#
# Copyright (c) 2007
# 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.
# 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"),
@ -23,10 +29,11 @@
# 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.
#
#######################################################################
# Parses a .cubin file produced by nvcc and reports statistics about the file.
# .cubin Parsing CMake Script
# Abe Stephens
# (c) 2007 Scientific Computing and Imaging Institute, University of Utah
file(READ ${input_file} file_text)
@ -68,26 +75,26 @@ if (${file_text} MATCHES ".+")
if(NOT skip)
# Registers
if (${entry} MATCHES "reg = ([^ ]+)")
string(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
if (${entry} MATCHES "reg([ ]+)=([ ]+)([^ ]+)")
string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry})
message("Registers: ${entry}")
endif(${entry} MATCHES "reg = ([^ ]+)")
endif()
# Local memory
if (${entry} MATCHES "lmem = ([^ ]+)")
string(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
if (${entry} MATCHES "lmem([ ]+)=([ ]+)([^ ]+)")
string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry})
message("Local: ${entry}")
endif(${entry} MATCHES "lmem = ([^ ]+)")
endif()
# Shared memory
if (${entry} MATCHES "smem = ([^ ]+)")
string(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry})
if (${entry} MATCHES "smem([ ]+)=([ ]+)([^ ]+)")
string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry})
message("Shared: ${entry}")
endif(${entry} MATCHES "smem = ([^ ]+)")
endif()
if (${entry} MATCHES "^}")
message("")
endif(${entry} MATCHES "^}")
endif()
endif(NOT skip)

@ -1,3 +1,33 @@
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
#
# Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
#
# This code is licensed under the MIT License. See the FindCUDA.cmake script
# for the text of the license.
# 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.
##########################################################################
# This file runs the nvcc commands to produce the desired output file along with
# the dependency file needed by CMake to compute dependencies. In addition the
# file checks the output of each command and if the command fails it deletes the
@ -39,7 +69,7 @@ set(generated_file_internal "@generated_file@")
set(generated_cubin_file_internal "@generated_cubin_file@")
set(CUDA_NVCC_EXECUTABLE "@CUDA_NVCC_EXECUTABLE@")
set(CUDA_NVCC_FLAGS "@CUDA_NVCC_FLAGS@;@CUDA_WRAP_OPTION_NVCC_FLAGS@")
set(CUDA_NVCC_FLAGS "@CUDA_NVCC_FLAGS@;;@CUDA_WRAP_OPTION_NVCC_FLAGS@")
@CUDA_NVCC_FLAGS_CONFIG@
set(nvcc_flags "@nvcc_flags@")
set(CUDA_NVCC_INCLUDE_ARGS "@CUDA_NVCC_INCLUDE_ARGS@")
@ -120,18 +150,39 @@ cuda_execute_process(
COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
)
# For CUDA 2.3 and below, -G -M doesn't work, so remove the -G flag
# for dependency generation and hope for the best.
set(depends_CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}")
set(CUDA_VERSION @CUDA_VERSION@)
if(CUDA_VERSION VERSION_LESS "3.0")
cmake_policy(PUSH)
# CMake policy 0007 NEW states that empty list elements are not
# ignored. I'm just setting it to avoid the warning that's printed.
cmake_policy(SET CMP0007 NEW)
# Note that this will remove all occurances of -G.
list(REMOVE_ITEM depends_CUDA_NVCC_FLAGS "-G")
cmake_policy(POP)
endif()
# nvcc doesn't define __CUDACC__ for some reason when generating dependency files. This
# can cause incorrect dependencies when #including files based on this macro which is
# defined in the generating passes of nvcc invokation. We will go ahead and manually
# define this for now until a future version fixes this bug.
set(CUDACC_DEFINE -D__CUDACC__)
# Generate the dependency file
cuda_execute_process(
"Generating dependency file: ${NVCC_generated_dependency_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}"
-M
${CUDACC_DEFINE}
"${source_file}"
${CUDA_NVCC_FLAGS}
${nvcc_flags}
-o "${NVCC_generated_dependency_file}"
${CCBIN}
${nvcc_flags}
${nvcc_host_compiler_flags}
${depends_CUDA_NVCC_FLAGS}
-DNVCC
-M
-o "${NVCC_generated_dependency_file}"
${CUDA_NVCC_INCLUDE_ARGS}
)
@ -179,12 +230,12 @@ cuda_execute_process(
"Generating ${generated_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}"
"${source_file}"
${CUDA_NVCC_FLAGS}
${nvcc_flags}
${format_flag} -o "${generated_file}"
${CCBIN}
${nvcc_flags}
${nvcc_host_compiler_flags}
${CUDA_NVCC_FLAGS}
-DNVCC
${format_flag} -o "${generated_file}"
${CUDA_NVCC_INCLUDE_ARGS}
)
@ -196,7 +247,9 @@ if(CUDA_result)
)
message(FATAL_ERROR "Error generating file ${generated_file}")
else()
if(verbose)
message("Generated ${generated_file} successfully.")
endif()
endif()
# Cubin resource report commands.

Loading…
Cancel
Save