Commit 393b09cb authored by Brad King's avatar Brad King
Browse files

Convert FindCUDA helper newlines from CRLF to LF

These files were committed to the repository with Windows newlines.
This converts them to Unix newlines so they will show up natively.
parent 6f010f1c
# For more information, please see: http://software.sci.utah.edu # For more information, please see: http://software.sci.utah.edu
# #
# The MIT License # The MIT License
# #
# Copyright (c) 2007 # Copyright (c) 2007
# 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 # License for the specific language governing rights and limitations under
# Permission is hereby granted, free of charge, to any person obtaining a # Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"), # copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation # to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense, # the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the # 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: # Software is furnished to do so, subject to the following conditions:
# #
# The above copyright notice and this permission notice shall be included # The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software. # in all copies or substantial portions of the Software.
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # 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 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
# Make2cmake CMake Script # Make2cmake CMake Script
# Abe Stephens and James Bigler # Abe Stephens and James Bigler
# (c) 2007 Scientific Computing and Imaging Institute, University of Utah # (c) 2007 Scientific Computing and Imaging Institute, University of Utah
# Note that the REGEX expressions may need to be tweaked for different dependency generators. # Note that the REGEX expressions may need to be tweaked for different dependency generators.
file(READ ${input_file} depend_text) file(READ ${input_file} depend_text)
if (${depend_text} MATCHES ".+") if (${depend_text} MATCHES ".+")
# message("FOUND DEPENDS") # message("FOUND DEPENDS")
# Remember, four backslashes is escaped to one backslash in the string. # Remember, four backslashes is escaped to one backslash in the string.
string(REGEX REPLACE "\\\\ " " " depend_text ${depend_text}) string(REGEX REPLACE "\\\\ " " " depend_text ${depend_text})
# This works for the nvcc -M generated dependency files. # This works for the nvcc -M generated dependency files.
string(REGEX REPLACE "^.* : " "" depend_text ${depend_text}) string(REGEX REPLACE "^.* : " "" depend_text ${depend_text})
string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text}) string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text})
set(dependency_list "") set(dependency_list "")
foreach(file ${depend_text}) foreach(file ${depend_text})
string(REGEX REPLACE "^ +" "" file ${file}) string(REGEX REPLACE "^ +" "" file ${file})
if(NOT IS_DIRECTORY ${file}) if(NOT IS_DIRECTORY ${file})
# If softlinks start to matter, we should change this to REALPATH. For now we need # 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 # to flatten paths, because nvcc can generate stuff like /bin/../include instead of
# just /include. # just /include.
get_filename_component(file_absolute "${file}" ABSOLUTE) get_filename_component(file_absolute "${file}" ABSOLUTE)
list(APPEND dependency_list "${file_absolute}") list(APPEND dependency_list "${file_absolute}")
endif(NOT IS_DIRECTORY ${file}) endif(NOT IS_DIRECTORY ${file})
endforeach(file) endforeach(file)
else() else()
# message("FOUND NO DEPENDS") # message("FOUND NO DEPENDS")
endif() endif()
# Remove the duplicate entries and sort them. # Remove the duplicate entries and sort them.
list(REMOVE_DUPLICATES dependency_list) list(REMOVE_DUPLICATES dependency_list)
list(SORT dependency_list) list(SORT dependency_list)
foreach(file ${dependency_list}) foreach(file ${dependency_list})
set(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n") set(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n")
endforeach() endforeach()
file(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n") file(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n")
# This file runs the nvcc commands to produce the desired output file along with # 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 # 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 # file checks the output of each command and if the command fails it deletes the
# output files. # output files.
# Input variables # Input variables
# #
# verbose:BOOL=<> OFF: Be as quiet as possible (default) # verbose:BOOL=<> OFF: Be as quiet as possible (default)
# ON : Describe each step # ON : Describe each step
# #
# build_configuration:STRING=<> Typically one of Debug, MinSizeRel, Release, or # build_configuration:STRING=<> Typically one of Debug, MinSizeRel, Release, or
# RelWithDebInfo, but it should match one of the # RelWithDebInfo, but it should match one of the
# entries in CUDA_HOST_FLAGS. This is the build # entries in CUDA_HOST_FLAGS. This is the build
# configuration used when compiling the code. If # configuration used when compiling the code. If
# blank or unspecified Debug is assumed as this is # blank or unspecified Debug is assumed as this is
# what CMake does. # what CMake does.
# #
# generated_file:STRING=<> File to generate. This argument must be passed in. # generated_file:STRING=<> File to generate. This argument must be passed in.
# #
# generated_cubin_file:STRING=<> File to generate. This argument must be passed # generated_cubin_file:STRING=<> File to generate. This argument must be passed
# in if build_cubin is true. # in if build_cubin is true.
if(NOT generated_file) if(NOT generated_file)
message(FATAL_ERROR "You must specify generated_file on the command line") message(FATAL_ERROR "You must specify generated_file on the command line")
endif() endif()
# Set these up as variables to make reading the generated file easier # Set these up as variables to make reading the generated file easier
set(CMAKE_COMMAND "@CMAKE_COMMAND@") set(CMAKE_COMMAND "@CMAKE_COMMAND@")
set(source_file "@source_file@") set(source_file "@source_file@")
set(NVCC_generated_dependency_file "@NVCC_generated_dependency_file@") set(NVCC_generated_dependency_file "@NVCC_generated_dependency_file@")
set(cmake_dependency_file "@cmake_dependency_file@") set(cmake_dependency_file "@cmake_dependency_file@")
set(CUDA_make2cmake "@CUDA_make2cmake@") set(CUDA_make2cmake "@CUDA_make2cmake@")
set(CUDA_parse_cubin "@CUDA_parse_cubin@") set(CUDA_parse_cubin "@CUDA_parse_cubin@")
set(build_cubin @build_cubin@) set(build_cubin @build_cubin@)
# We won't actually use these variables for now, but we need to set this, in # 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. # order to force this file to be run again if it changes.
set(generated_file_path "@generated_file_path@") set(generated_file_path "@generated_file_path@")
set(generated_file_internal "@generated_file@") set(generated_file_internal "@generated_file@")
set(generated_cubin_file_internal "@generated_cubin_file@") set(generated_cubin_file_internal "@generated_cubin_file@")
set(CUDA_NVCC_EXECUTABLE "@CUDA_NVCC_EXECUTABLE@") 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@ @CUDA_NVCC_FLAGS_CONFIG@
set(nvcc_flags "@nvcc_flags@") set(nvcc_flags "@nvcc_flags@")
set(CUDA_NVCC_INCLUDE_ARGS "@CUDA_NVCC_INCLUDE_ARGS@") set(CUDA_NVCC_INCLUDE_ARGS "@CUDA_NVCC_INCLUDE_ARGS@")
set(format_flag "@format_flag@") set(format_flag "@format_flag@")
if(build_cubin AND NOT generated_cubin_file) if(build_cubin AND NOT generated_cubin_file)
message(FATAL_ERROR "You must specify generated_cubin_file on the command line") message(FATAL_ERROR "You must specify generated_cubin_file on the command line")
endif() endif()
# This is the list of host compilation flags. It C or CXX should already have # This is the list of host compilation flags. It C or CXX should already have
# been chosen by FindCUDA.cmake. # been chosen by FindCUDA.cmake.
@CUDA_HOST_FLAGS@ @CUDA_HOST_FLAGS@
# Take the compiler flags and package them up to be sent to the compiler via -Xcompiler # Take the compiler flags and package them up to be sent to the compiler via -Xcompiler
set(nvcc_host_compiler_flags "") set(nvcc_host_compiler_flags "")
# If we weren't given a build_configuration, use Debug. # If we weren't given a build_configuration, use Debug.
if(NOT build_configuration) if(NOT build_configuration)
set(build_configuration Debug) set(build_configuration Debug)
endif() endif()
string(TOUPPER "${build_configuration}" build_configuration) string(TOUPPER "${build_configuration}" build_configuration)
#message("CUDA_NVCC_HOST_COMPILER_FLAGS = ${CUDA_NVCC_HOST_COMPILER_FLAGS}") #message("CUDA_NVCC_HOST_COMPILER_FLAGS = ${CUDA_NVCC_HOST_COMPILER_FLAGS}")
foreach(flag ${CMAKE_HOST_FLAGS} ${CMAKE_HOST_FLAGS_${build_configuration}}) foreach(flag ${CMAKE_HOST_FLAGS} ${CMAKE_HOST_FLAGS_${build_configuration}})
# Extra quotes are added around each flag to help nvcc parse out flags with spaces. # Extra quotes are added around each flag to help nvcc parse out flags with spaces.
set(nvcc_host_compiler_flags "${nvcc_host_compiler_flags},\"${flag}\"") set(nvcc_host_compiler_flags "${nvcc_host_compiler_flags},\"${flag}\"")
endforeach() endforeach()
if (nvcc_host_compiler_flags) if (nvcc_host_compiler_flags)
set(nvcc_host_compiler_flags "-Xcompiler" ${nvcc_host_compiler_flags}) set(nvcc_host_compiler_flags "-Xcompiler" ${nvcc_host_compiler_flags})
endif() endif()
#message("nvcc_host_compiler_flags = \"${nvcc_host_compiler_flags}\"") #message("nvcc_host_compiler_flags = \"${nvcc_host_compiler_flags}\"")
# Add the build specific configuration flags # Add the build specific configuration flags
list(APPEND CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS_${build_configuration}}) list(APPEND CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS_${build_configuration}})
if(DEFINED CCBIN) if(DEFINED CCBIN)
set(CCBIN -ccbin "${CCBIN}") set(CCBIN -ccbin "${CCBIN}")
endif() endif()
# cuda_execute_process - Executes a command with optional command echo and status message. # cuda_execute_process - Executes a command with optional command echo and status message.
# #
# status - Status message to print if verbose is true # status - Status message to print if verbose is true
# command - COMMAND argument from the usual execute_process argument structure # command - COMMAND argument from the usual execute_process argument structure
# ARGN - Remaining arguments are the command with arguments # ARGN - Remaining arguments are the command with arguments
# #
# CUDA_result - return value from running the command # CUDA_result - return value from running the command
# #
# Make this a macro instead of a function, so that things like RESULT_VARIABLE # Make this a macro instead of a function, so that things like RESULT_VARIABLE
# and other return variables are present after executing the process. # and other return variables are present after executing the process.
macro(cuda_execute_process status command) macro(cuda_execute_process status command)
set(_command ${command}) set(_command ${command})
if(NOT _command STREQUAL "COMMAND") if(NOT _command STREQUAL "COMMAND")
message(FATAL_ERROR "Malformed call to cuda_execute_process. Missing COMMAND as second argument. (command = ${command})") message(FATAL_ERROR "Malformed call to cuda_execute_process. Missing COMMAND as second argument. (command = ${command})")
endif() endif()
if(verbose) if(verbose)
execute_process(COMMAND "${CMAKE_COMMAND}" -E echo -- ${status}) execute_process(COMMAND "${CMAKE_COMMAND}" -E echo -- ${status})
# Now we need to build up our command string. We are accounting for quotes # Now we need to build up our command string. We are accounting for quotes
# and spaces, anything else is left up to the user to fix if they want to # and spaces, anything else is left up to the user to fix if they want to
# copy and paste a runnable command line. # copy and paste a runnable command line.
set(cuda_execute_process_string) set(cuda_execute_process_string)
foreach(arg ${ARGN}) foreach(arg ${ARGN})
# If there are quotes, excape them, so they come through. # If there are quotes, excape them, so they come through.
string(REPLACE "\"" "\\\"" arg ${arg}) string(REPLACE "\"" "\\\"" arg ${arg})
# Args with spaces need quotes around them to get them to be parsed as a single argument. # Args with spaces need quotes around them to get them to be parsed as a single argument.
if(arg MATCHES " ") if(arg MATCHES " ")
list(APPEND cuda_execute_process_string "\"${arg}\"") list(APPEND cuda_execute_process_string "\"${arg}\"")
else() else()
list(APPEND cuda_execute_process_string ${arg}) list(APPEND cuda_execute_process_string ${arg})
endif() endif()
endforeach() endforeach()
# Echo the command # Echo the command
execute_process(COMMAND ${CMAKE_COMMAND} -E echo ${cuda_execute_process_string}) execute_process(COMMAND ${CMAKE_COMMAND} -E echo ${cuda_execute_process_string})
endif(verbose) endif(verbose)
# Run the command # Run the command
execute_process(COMMAND ${ARGN} RESULT_VARIABLE CUDA_result ) execute_process(COMMAND ${ARGN} RESULT_VARIABLE CUDA_result )
endmacro() endmacro()
# Delete the target file # Delete the target file
cuda_execute_process( cuda_execute_process(
"Removing ${generated_file}" "Removing ${generated_file}"
COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}" COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
) )
# Make sure the output directory is present # Make sure the output directory is present
cuda_execute_process( cuda_execute_process(
"Creating output directory: ${generated_file_path}" "Creating output directory: ${generated_file_path}"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${generated_file_path}" COMMAND "${CMAKE_COMMAND}" -E make_directory "${generated_file_path}"
) )
# Generate the dependency file # Generate the dependency file
cuda_execute_process( cuda_execute_process(
"Generating dependency file: ${NVCC_generated_dependency_file}" "Generating dependency file: ${NVCC_generated_dependency_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}" COMMAND "${CUDA_NVCC_EXECUTABLE}"
"${source_file}" "${source_file}"
${CUDA_NVCC_FLAGS} ${CUDA_NVCC_FLAGS}
${nvcc_flags} ${nvcc_flags}
${CCBIN} ${CCBIN}
${nvcc_host_compiler_flags} ${nvcc_host_compiler_flags}
-DNVCC -DNVCC
-M -M
-o "${NVCC_generated_dependency_file}" -o "${NVCC_generated_dependency_file}"
${CUDA_NVCC_INCLUDE_ARGS} ${CUDA_NVCC_INCLUDE_ARGS}
) )
if(CUDA_result) if(CUDA_result)
message(FATAL_ERROR "Error generating ${generated_file}") message(FATAL_ERROR "Error generating ${generated_file}")
endif() endif()
# Generate the cmake readable dependency file to a temp file. Don't put the # Generate the cmake readable dependency file to a temp file. Don't put the
# quotes just around the filenames for the input_file and output_file variables. # quotes just around the filenames for the input_file and output_file variables.
# CMake will pass the quotes through and not be able to find the file. # CMake will pass the quotes through and not be able to find the file.
cuda_execute_process( cuda_execute_process(
"Generating temporary cmake readable file: ${cmake_dependency_file}.tmp" "Generating temporary cmake readable file: ${cmake_dependency_file}.tmp"
COMMAND "${CMAKE_COMMAND}" COMMAND "${CMAKE_COMMAND}"
-D "input_file:FILEPATH=${NVCC_generated_dependency_file}" -D "input_file:FILEPATH=${NVCC_generated_dependency_file}"
-D "output_file:FILEPATH=${cmake_dependency_file}.tmp" -D "output_file:FILEPATH=${cmake_dependency_file}.tmp"
-P "${CUDA_make2cmake}" -P "${CUDA_make2cmake}"
) )
if(CUDA_result) if(CUDA_result)
message(FATAL_ERROR "Error generating ${generated_file}") message(FATAL_ERROR "Error generating ${generated_file}")
endif() endif()
# Copy the file if it is different # Copy the file if it is different
cuda_execute_process( cuda_execute_process(
"Copy if different ${cmake_dependency_file}.tmp to ${cmake_dependency_file}" "Copy if different ${cmake_dependency_file}.tmp to ${cmake_dependency_file}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${cmake_dependency_file}.tmp" "${cmake_dependency_file}" COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${cmake_dependency_file}.tmp" "${cmake_dependency_file}"
) )
if(CUDA_result) if(CUDA_result)
message(FATAL_ERROR "Error generating ${generated_file}") message(FATAL_ERROR "Error generating ${generated_file}")
endif() endif()
# Delete the temporary file # Delete the temporary file
cuda_execute_process( cuda_execute_process(
"Removing ${cmake_dependency_file}.tmp and ${NVCC_generated_dependency_file}" "Removing ${cmake_dependency_file}.tmp and ${NVCC_generated_dependency_file}"
COMMAND "${CMAKE_COMMAND}" -E remove "${cmake_dependency_file}.tmp" "${NVCC_generated_dependency_file}" COMMAND "${CMAKE_COMMAND}" -E remove "${cmake_dependency_file}.tmp" "${NVCC_generated_dependency_file}"
) )
if(CUDA_result) if(CUDA_result)
message(FATAL_ERROR "Error generating ${generated_file}") message(FATAL_ERROR "Error generating ${generated_file}")
endif() endif()
# Generate the code # Generate the code
cuda_execute_process( cuda_execute_process(
"Generating ${generated_file}" "Generating ${generated_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}" COMMAND "${CUDA_NVCC_EXECUTABLE}"
"${source_file}" "${source_file}"
${CUDA_NVCC_FLAGS} ${CUDA_NVCC_FLAGS}
${nvcc_flags} ${nvcc_flags}
${CCBIN} ${CCBIN}
${nvcc_host_compiler_flags} ${nvcc_host_compiler_flags}
-DNVCC -DNVCC
${format_flag} -o "${generated_file}" ${format_flag} -o "${generated_file}"
${CUDA_NVCC_INCLUDE_ARGS} ${CUDA_NVCC_INCLUDE_ARGS}
) )
if(CUDA_result) if(CUDA_result)
# Since nvcc can sometimes leave half done files make sure that we delete the output file. # Since nvcc can sometimes leave half done files make sure that we delete the output file.
cuda_execute_process( cuda_execute_process(
"Removing ${generated_file}" "Removing ${generated_file}"
COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}" COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
) )
message(FATAL_ERROR "Error generating file ${generated_file}") message(FATAL_ERROR "Error generating file ${generated_file}")
else() else()
if(verbose) if(verbose)
message("Generated ${generated_file} successfully.") message("Generated ${generated_file} successfully.")
endif() endif()
endif() endif()
# Cubin resource report commands. # Cubin resource report commands.
if( build_cubin ) if( build_cubin )
# Run with -cubin to produce resource usage report. # Run with -cubin to produce resource usage report.
cuda_execute_process( cuda_execute_process(
"Generating ${generated_cubin_file}" "Generating ${generated_cubin_file}"
COMMAND "${CUDA_NVCC_EXECUTABLE}" COMMAND "${CUDA_NVCC_EXECUTABLE}"
"${source_file}" "${source_file}"
${CUDA_NVCC_FLAGS} ${CUDA_NVCC_FLAGS}
${nvcc_flags} ${nvcc_flags}
${CCBIN} ${CCBIN}
${nvcc_host_compiler_flags} ${nvcc_host_compiler_flags}
-DNVCC -DNVCC
-cubin -cubin
-o "${generated_cubin_file}" -o "${generated_cubin_file}"
${CUDA_NVCC_INCLUDE_ARGS} ${CUDA_NVCC_INCLUDE_ARGS}
) )
# Execute the parser script. # Execute the parser script.
cuda_execute_process( cuda_execute_process(
"Executing the parser script" "Executing the parser script"
COMMAND "${CMAKE_COMMAND}" COMMAND "${CMAKE_COMMAND}"
-D "input_file:STRING=${generated_cubin_file}" -D "input_file:STRING=${generated_cubin_file}"
-P "${CUDA_parse_cubin}" -P "${CUDA_parse_cubin}"
) )
endif( build_cubin ) endif( build_cubin )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment