Update FindCUDA.

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

File diff suppressed because it is too large Load Diff

@ -1,61 +1,79 @@
# James Bigler, NVIDIA Corp (nvidia.com - jbigler)
# For more information, please see: http://software.sci.utah.edu # 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 # Scientific Computing and Imaging Institute, University of Utah
# #
# License for the specific language governing rights and limitations under # This code is licensed under the MIT License. See the FindCUDA.cmake script
# Permission is hereby granted, free of charge, to any person obtaining a # for the text of the license.
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation # The MIT License
# the rights to use, copy, modify, merge, publish, distribute, sublicense, #
# and/or sell copies of the Software, and to permit persons to whom the # License for the specific language governing rights and limitations under
# Software is furnished to do so, subject to the following conditions: # Permission is hereby granted, free of charge, to any person obtaining a
# # copy of this software and associated documentation files (the "Software"),
# The above copyright notice and this permission notice shall be included # to deal in the Software without restriction, including without limitation
# in all copies or substantial portions of the Software. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
# # and/or sell copies of the Software, and to permit persons to whom the
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # Software is furnished to do so, subject to the following conditions:
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # The above copyright notice and this permission notice shall be included
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # in all copies or substantial portions of the Software.
# 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 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# DEALINGS IN THE SOFTWARE. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# Make2cmake CMake Script # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# Abe Stephens and James Bigler # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# (c) 2007 Scientific Computing and Imaging Institute, University of Utah # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# Note that the REGEX expressions may need to be tweaked for different dependency generators. # DEALINGS IN THE SOFTWARE.
#
file(READ ${input_file} depend_text)
#######################################################################
if (${depend_text} MATCHES ".+") # This converts a file written in makefile syntax into one that can be included
# by CMake.
# message("FOUND DEPENDS")
file(READ ${input_file} depend_text)
# Remember, four backslashes is escaped to one backslash in the string.
string(REGEX REPLACE "\\\\ " " " depend_text ${depend_text}) if (${depend_text} MATCHES ".+")
# This works for the nvcc -M generated dependency files. # message("FOUND DEPENDS")
string(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text}) # Remember, four backslashes is escaped to one backslash in the string.
string(REGEX REPLACE "\\\\ " " " depend_text ${depend_text})
foreach(file ${depend_text})
# This works for the nvcc -M generated dependency files.
string(REGEX REPLACE "^ +" "" file ${file}) string(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})
if(NOT IS_DIRECTORY ${file})
set(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n") set(dependency_list "")
endif(NOT IS_DIRECTORY ${file})
foreach(file ${depend_text})
endforeach(file)
string(REGEX REPLACE "^ +" "" file ${file})
else()
# message("FOUND NO DEPENDS") if(NOT IS_DIRECTORY ${file})
endif() # 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.
file(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n") get_filename_component(file_absolute "${file}" ABSOLUTE)
list(APPEND dependency_list "${file_absolute}")
endif(NOT IS_DIRECTORY ${file})
endforeach(file)
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,32 +1,39 @@
# 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 # Scientific Computing and Imaging Institute, University of Utah
# #
# License for the specific language governing rights and limitations under # This code is licensed under the MIT License. See the FindCUDA.cmake script
# Permission is hereby granted, free of charge, to any person obtaining a # for the text of the license.
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation # The MIT License
# the rights to use, copy, modify, merge, publish, distribute, sublicense, #
# and/or sell copies of the Software, and to permit persons to whom the # License for the specific language governing rights and limitations under
# Software is furnished to do so, subject to the following conditions: # 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 above copyright notice and this permission notice shall be included # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# in all copies or substantial portions of the Software. # 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.
# #
# 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 # Parses a .cubin file produced by nvcc and reports statistics about the file.
# 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.
# .cubin Parsing CMake Script
# Abe Stephens
# (c) 2007 Scientific Computing and Imaging Institute, University of Utah
file(READ ${input_file} file_text) file(READ ${input_file} file_text)
@ -68,26 +75,26 @@ if (${file_text} MATCHES ".+")
if(NOT skip) if(NOT skip)
# Registers # Registers
if (${entry} MATCHES "reg = ([^ ]+)") if (${entry} MATCHES "reg([ ]+)=([ ]+)([^ ]+)")
string(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry}) string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry})
message("Registers: ${entry}") message("Registers: ${entry}")
endif(${entry} MATCHES "reg = ([^ ]+)") endif()
# Local memory # Local memory
if (${entry} MATCHES "lmem = ([^ ]+)") if (${entry} MATCHES "lmem([ ]+)=([ ]+)([^ ]+)")
string(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry}) string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry})
message("Local: ${entry}") message("Local: ${entry}")
endif(${entry} MATCHES "lmem = ([^ ]+)") endif()
# Shared memory # Shared memory
if (${entry} MATCHES "smem = ([^ ]+)") if (${entry} MATCHES "smem([ ]+)=([ ]+)([^ ]+)")
string(REGEX REPLACE ".* = ([^ ]+)" "\\1" entry ${entry}) string(REGEX REPLACE ".*([ ]+)=([ ]+)([^ ]+)" "\\3" entry ${entry})
message("Shared: ${entry}") message("Shared: ${entry}")
endif(${entry} MATCHES "smem = ([^ ]+)") endif()
if (${entry} MATCHES "^}") if (${entry} MATCHES "^}")
message("") message("")
endif(${entry} MATCHES "^}") endif()
endif(NOT skip) endif(NOT skip)

@ -1,227 +1,280 @@
# This file runs the nvcc commands to produce the desired output file along with # James Bigler, NVIDIA Corp (nvidia.com - jbigler)
# 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 # Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
# output files. #
# This code is licensed under the MIT License. See the FindCUDA.cmake script
# Input variables # for the text of the license.
#
# verbose:BOOL=<> OFF: Be as quiet as possible (default) # The MIT License
# ON : Describe each step #
# # License for the specific language governing rights and limitations under
# build_configuration:STRING=<> Typically one of Debug, MinSizeRel, Release, or # Permission is hereby granted, free of charge, to any person obtaining a
# RelWithDebInfo, but it should match one of the # copy of this software and associated documentation files (the "Software"),
# entries in CUDA_HOST_FLAGS. This is the build # to deal in the Software without restriction, including without limitation
# configuration used when compiling the code. If # the rights to use, copy, modify, merge, publish, distribute, sublicense,
# blank or unspecified Debug is assumed as this is # and/or sell copies of the Software, and to permit persons to whom the
# what CMake does. # Software is furnished to do so, subject to the following conditions:
# #
# generated_file:STRING=<> File to generate. This argument must be passed in. # The above copyright notice and this permission notice shall be included
# # in all copies or substantial portions of the Software.
# generated_cubin_file:STRING=<> File to generate. This argument must be passed #
# in if build_cubin is true. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
if(NOT generated_file) # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
message(FATAL_ERROR "You must specify generated_file on the command line") # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
endif() # 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
# Set these up as variables to make reading the generated file easier # DEALINGS IN THE SOFTWARE.
set(CMAKE_COMMAND "@CMAKE_COMMAND@")
set(source_file "@source_file@")
set(NVCC_generated_dependency_file "@NVCC_generated_dependency_file@") ##########################################################################
set(cmake_dependency_file "@cmake_dependency_file@") # This file runs the nvcc commands to produce the desired output file along with
set(CUDA_make2cmake "@CUDA_make2cmake@") # the dependency file needed by CMake to compute dependencies. In addition the
set(CUDA_parse_cubin "@CUDA_parse_cubin@") # file checks the output of each command and if the command fails it deletes the
set(build_cubin @build_cubin@) # output files.
# We won't actually use these variables for now, but we need to set this, in
# order to force this file to be run again if it changes. # Input variables
set(generated_file_path "@generated_file_path@") #
set(generated_file_internal "@generated_file@") # verbose:BOOL=<> OFF: Be as quiet as possible (default)
set(generated_cubin_file_internal "@generated_cubin_file@") # ON : Describe each step
#
set(CUDA_NVCC_EXECUTABLE "@CUDA_NVCC_EXECUTABLE@") # build_configuration:STRING=<> Typically one of Debug, MinSizeRel, Release, or
set(CUDA_NVCC_FLAGS "@CUDA_NVCC_FLAGS@;@CUDA_WRAP_OPTION_NVCC_FLAGS@") # RelWithDebInfo, but it should match one of the
@CUDA_NVCC_FLAGS_CONFIG@ # entries in CUDA_HOST_FLAGS. This is the build
set(nvcc_flags "@nvcc_flags@") # configuration used when compiling the code. If
set(CUDA_NVCC_INCLUDE_ARGS "@CUDA_NVCC_INCLUDE_ARGS@") # blank or unspecified Debug is assumed as this is
set(format_flag "@format_flag@") # what CMake does.
#
if(build_cubin AND NOT generated_cubin_file) # generated_file:STRING=<> File to generate. This argument must be passed in.
message(FATAL_ERROR "You must specify generated_cubin_file on the command line") #
endif() # generated_cubin_file:STRING=<> File to generate. This argument must be passed
# in if build_cubin is true.
# This is the list of host compilation flags. It C or CXX should already have
# been chosen by FindCUDA.cmake. if(NOT generated_file)
@CUDA_HOST_FLAGS@ message(FATAL_ERROR "You must specify generated_file on the command line")
endif()
# Take the compiler flags and package them up to be sent to the compiler via -Xcompiler
set(nvcc_host_compiler_flags "") # Set these up as variables to make reading the generated file easier
# If we weren't given a build_configuration, use Debug. set(CMAKE_COMMAND "@CMAKE_COMMAND@")
if(NOT build_configuration) set(source_file "@source_file@")
set(build_configuration Debug) set(NVCC_generated_dependency_file "@NVCC_generated_dependency_file@")
endif() set(cmake_dependency_file "@cmake_dependency_file@")
string(TOUPPER "${build_configuration}" build_configuration) set(CUDA_make2cmake "@CUDA_make2cmake@")
#message("CUDA_NVCC_HOST_COMPILER_FLAGS = ${CUDA_NVCC_HOST_COMPILER_FLAGS}") set(CUDA_parse_cubin "@CUDA_parse_cubin@")
foreach(flag ${CMAKE_HOST_FLAGS} ${CMAKE_HOST_FLAGS_${build_configuration}}) set(build_cubin @build_cubin@)
# Extra quotes are added around each flag to help nvcc parse out flags with spaces. # We won't actually use these variables for now, but we need to set this, in
set(nvcc_host_compiler_flags "${nvcc_host_compiler_flags},\"${flag}\"") # order to force this file to be run again if it changes.
endforeach() set(generated_file_path "@generated_file_path@")
if (nvcc_host_compiler_flags) set(generated_file_internal "@generated_file@")
set(nvcc_host_compiler_flags "-Xcompiler" ${nvcc_host_compiler_flags}) set(generated_cubin_file_internal "@generated_cubin_file@")
endif()
#message("nvcc_host_compiler_flags = \"${nvcc_host_compiler_flags}\"") set(CUDA_NVCC_EXECUTABLE "@CUDA_NVCC_EXECUTABLE@")
# Add the build specific configuration flags set(CUDA_NVCC_FLAGS "@CUDA_NVCC_FLAGS@;;@CUDA_WRAP_OPTION_NVCC_FLAGS@")
list(APPEND CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS_${build_configuration}}) @CUDA_NVCC_FLAGS_CONFIG@
set(nvcc_flags "@nvcc_flags@")
if(DEFINED CCBIN) set(CUDA_NVCC_INCLUDE_ARGS "@CUDA_NVCC_INCLUDE_ARGS@")
set(CCBIN -ccbin "${CCBIN}") set(format_flag "@format_flag@")
endif()
if(build_cubin AND NOT generated_cubin_file)
# cuda_execute_process - Executes a command with optional command echo and status message. message(FATAL_ERROR "You must specify generated_cubin_file on the command line")
# endif()
# status - Status message to print if verbose is true
# command - COMMAND argument from the usual execute_process argument structure # This is the list of host compilation flags. It C or CXX should already have
# ARGN - Remaining arguments are the command with arguments # been chosen by FindCUDA.cmake.
# @CUDA_HOST_FLAGS@
# CUDA_result - return value from running the command
# # Take the compiler flags and package them up to be sent to the compiler via -Xcompiler
# Make this a macro instead of a function, so that things like RESULT_VARIABLE set(nvcc_host_compiler_flags "")
# and other return variables are present after executing the process. # If we weren't given a build_configuration, use Debug.
macro(cuda_execute_process status command) if(NOT build_configuration)
set(_command ${command}) set(build_configuration Debug)
if(NOT _command STREQUAL "COMMAND") endif()
message(FATAL_ERROR "Malformed call to cuda_execute_process. Missing COMMAND as second argument. (command = ${command})") string(TOUPPER "${build_configuration}" build_configuration)
endif() #message("CUDA_NVCC_HOST_COMPILER_FLAGS = ${CUDA_NVCC_HOST_COMPILER_FLAGS}")
if(verbose) foreach(flag ${CMAKE_HOST_FLAGS} ${CMAKE_HOST_FLAGS_${build_configuration}})
execute_process(COMMAND "${CMAKE_COMMAND}" -E echo -- ${status}) # Extra quotes are added around each flag to help nvcc parse out flags with spaces.
# Now we need to build up our command string. We are accounting for quotes set(nvcc_host_compiler_flags "${nvcc_host_compiler_flags},\"${flag}\"")
# and spaces, anything else is left up to the user to fix if they want to endforeach()
# copy and paste a runnable command line. if (nvcc_host_compiler_flags)
set(cuda_execute_process_string) set(nvcc_host_compiler_flags "-Xcompiler" ${nvcc_host_compiler_flags})
foreach(arg ${ARGN}) endif()
# If there are quotes, excape them, so they come through. #message("nvcc_host_compiler_flags = \"${nvcc_host_compiler_flags}\"")
string(REPLACE "\"" "\\\"" arg ${arg}) # Add the build specific configuration flags
# Args with spaces need quotes around them to get them to be parsed as a single argument. list(APPEND CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS_${build_configuration}})
if(arg MATCHES " ")
list(APPEND cuda_execute_process_string "\"${arg}\"") if(DEFINED CCBIN)
else() set(CCBIN -ccbin "${CCBIN}")
list(APPEND cuda_execute_process_string ${arg}) endif()
endif()
endforeach() # cuda_execute_process - Executes a command with optional command echo and status message.
# Echo the command #
execute_process(COMMAND ${CMAKE_COMMAND} -E echo ${cuda_execute_process_string}) # status - Status message to print if verbose is true
endif(verbose) # command - COMMAND argument from the usual execute_process argument structure
# Run the command # ARGN - Remaining arguments are the command with arguments
execute_process(COMMAND ${ARGN} RESULT_VARIABLE CUDA_result ) #
endmacro() # CUDA_result - return value from running the command
#
# Delete the target file # Make this a macro instead of a function, so that things like RESULT_VARIABLE
cuda_execute_process( # and other return variables are present after executing the process.
"Removing ${generated_file}" macro(cuda_execute_process status command)
COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}" set(_command ${command})
) if(NOT _command STREQUAL "COMMAND")
message(FATAL_ERROR "Malformed call to cuda_execute_process. Missing COMMAND as second argument. (command = ${command})")
# Generate the dependency file endif()
cuda_execute_process( if(verbose)
"Generating dependency file: ${NVCC_generated_dependency_file}" execute_process(COMMAND "${CMAKE_COMMAND}" -E echo -- ${status})
COMMAND "${CUDA_NVCC_EXECUTABLE}" # Now we need to build up our command string. We are accounting for quotes
"${source_file}" # and spaces, anything else is left up to the user to fix if they want to
${CUDA_NVCC_FLAGS} # copy and paste a runnable command line.
${nvcc_flags} set(cuda_execute_process_string)
${CCBIN} foreach(arg ${ARGN})
${nvcc_host_compiler_flags} # If there are quotes, excape them, so they come through.
-DNVCC string(REPLACE "\"" "\\\"" arg ${arg})
-M # Args with spaces need quotes around them to get them to be parsed as a single argument.
-o "${NVCC_generated_dependency_file}" if(arg MATCHES " ")
${CUDA_NVCC_INCLUDE_ARGS} list(APPEND cuda_execute_process_string "\"${arg}\"")
) else()
list(APPEND cuda_execute_process_string ${arg})
if(CUDA_result) endif()
message(FATAL_ERROR "Error generating ${generated_file}") endforeach()
endif() # Echo the command
execute_process(COMMAND ${CMAKE_COMMAND} -E echo ${cuda_execute_process_string})
# Generate the cmake readable dependency file to a temp file. Don't put the endif(verbose)
# quotes just around the filenames for the input_file and output_file variables. # Run the command
# CMake will pass the quotes through and not be able to find the file. execute_process(COMMAND ${ARGN} RESULT_VARIABLE CUDA_result )
cuda_execute_process( endmacro()
"Generating temporary cmake readable file: ${cmake_dependency_file}.tmp"
COMMAND "${CMAKE_COMMAND}" # Delete the target file
-D "input_file:FILEPATH=${NVCC_generated_dependency_file}" cuda_execute_process(
-D "output_file:FILEPATH=${cmake_dependency_file}.tmp" "Removing ${generated_file}"
-P "${CUDA_make2cmake}" COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
) )
if(CUDA_result) # For CUDA 2.3 and below, -G -M doesn't work, so remove the -G flag
message(FATAL_ERROR "Error generating ${generated_file}") # for dependency generation and hope for the best.
endif() set(depends_CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}")
set(CUDA_VERSION @CUDA_VERSION@)
# Copy the file if it is different if(CUDA_VERSION VERSION_LESS "3.0")
cuda_execute_process( cmake_policy(PUSH)
"Copy if different ${cmake_dependency_file}.tmp to ${cmake_dependency_file}" # CMake policy 0007 NEW states that empty list elements are not
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${cmake_dependency_file}.tmp" "${cmake_dependency_file}" # 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.
if(CUDA_result) list(REMOVE_ITEM depends_CUDA_NVCC_FLAGS "-G")
message(FATAL_ERROR "Error generating ${generated_file}") cmake_policy(POP)
endif() endif()
# Delete the temporary file # nvcc doesn't define __CUDACC__ for some reason when generating dependency files. This
cuda_execute_process( # can cause incorrect dependencies when #including files based on this macro which is
"Removing ${cmake_dependency_file}.tmp and ${NVCC_generated_dependency_file}" # defined in the generating passes of nvcc invokation. We will go ahead and manually
COMMAND "${CMAKE_COMMAND}" -E remove "${cmake_dependency_file}.tmp" "${NVCC_generated_dependency_file}" # define this for now until a future version fixes this bug.
) set(CUDACC_DEFINE -D__CUDACC__)
if(CUDA_result) # Generate the dependency file
message(FATAL_ERROR "Error generating ${generated_file}") cuda_execute_process(
endif() "Generating dependency file: ${NVCC_generated_dependency_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}"
# Generate the code -M
cuda_execute_process( ${CUDACC_DEFINE}
"Generating ${generated_file}" "${source_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}" -o "${NVCC_generated_dependency_file}"
"${source_file}" ${CCBIN}
${CUDA_NVCC_FLAGS} ${nvcc_flags}
${nvcc_flags} ${nvcc_host_compiler_flags}
${CCBIN} ${depends_CUDA_NVCC_FLAGS}
${nvcc_host_compiler_flags} -DNVCC
-DNVCC ${CUDA_NVCC_INCLUDE_ARGS}
${format_flag} -o "${generated_file}" )
${CUDA_NVCC_INCLUDE_ARGS}
) if(CUDA_result)
message(FATAL_ERROR "Error generating ${generated_file}")
if(CUDA_result) endif()
# Since nvcc can sometimes leave half done files make sure that we delete the output file.
cuda_execute_process( # Generate the cmake readable dependency file to a temp file. Don't put the
"Removing ${generated_file}" # quotes just around the filenames for the input_file and output_file variables.
COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}" # CMake will pass the quotes through and not be able to find the file.
) cuda_execute_process(
message(FATAL_ERROR "Error generating file ${generated_file}") "Generating temporary cmake readable file: ${cmake_dependency_file}.tmp"
else() COMMAND "${CMAKE_COMMAND}"
message("Generated ${generated_file} successfully.") -D "input_file:FILEPATH=${NVCC_generated_dependency_file}"
endif() -D "output_file:FILEPATH=${cmake_dependency_file}.tmp"
-P "${CUDA_make2cmake}"
# Cubin resource report commands. )
if( build_cubin )
# Run with -cubin to produce resource usage report. if(CUDA_result)
cuda_execute_process( message(FATAL_ERROR "Error generating ${generated_file}")
"Generating ${generated_cubin_file}" endif()
COMMAND "${CUDA_NVCC_EXECUTABLE}"
"${source_file}" # Copy the file if it is different
${CUDA_NVCC_FLAGS} cuda_execute_process(
${nvcc_flags} "Copy if different ${cmake_dependency_file}.tmp to ${cmake_dependency_file}"
${CCBIN} COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${cmake_dependency_file}.tmp" "${cmake_dependency_file}"
${nvcc_host_compiler_flags} )
-DNVCC
-cubin if(CUDA_result)
-o "${generated_cubin_file}" message(FATAL_ERROR "Error generating ${generated_file}")
${CUDA_NVCC_INCLUDE_ARGS} endif()
)
# Delete the temporary file
# Execute the parser script. cuda_execute_process(
cuda_execute_process( "Removing ${cmake_dependency_file}.tmp and ${NVCC_generated_dependency_file}"
"Executing the parser script" COMMAND "${CMAKE_COMMAND}" -E remove "${cmake_dependency_file}.tmp" "${NVCC_generated_dependency_file}"
COMMAND "${CMAKE_COMMAND}" )
-D "input_file:STRING=${generated_cubin_file}"
-P "${CUDA_parse_cubin}" if(CUDA_result)
) message(FATAL_ERROR "Error generating ${generated_file}")
endif()
endif( build_cubin )
# Generate the code
cuda_execute_process(
"Generating ${generated_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}"
"${source_file}"
${format_flag} -o "${generated_file}"
${CCBIN}
${nvcc_flags}
${nvcc_host_compiler_flags}
${CUDA_NVCC_FLAGS}
-DNVCC
${CUDA_NVCC_INCLUDE_ARGS}
)
if(CUDA_result)
# Since nvcc can sometimes leave half done files make sure that we delete the output file.
cuda_execute_process(
"Removing ${generated_file}"
COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
)
message(FATAL_ERROR "Error generating file ${generated_file}")
else()
if(verbose)
message("Generated ${generated_file} successfully.")
endif()
endif()
# Cubin resource report commands.
if( build_cubin )
# Run with -cubin to produce resource usage report.
cuda_execute_process(
"Generating ${generated_cubin_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}"
"${source_file}"
${CUDA_NVCC_FLAGS}
${nvcc_flags}
${CCBIN}
${nvcc_host_compiler_flags}
-DNVCC
-cubin
-o "${generated_cubin_file}"
${CUDA_NVCC_INCLUDE_ARGS}
)
# Execute the parser script.
cuda_execute_process(
"Executing the parser script"
COMMAND "${CMAKE_COMMAND}"
-D "input_file:STRING=${generated_cubin_file}"
-P "${CUDA_parse_cubin}"
)
endif( build_cubin )

Loading…
Cancel
Save