diff options
author | Brad King <brad.king@kitware.com> | 2009-09-28 15:04:33 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-09-28 15:04:33 (GMT) |
commit | 393b09cb85522d9f2e4433844f17625b064f929d (patch) | |
tree | 60c06631c2770b6f0e5343c924fdee6fe549625f /Modules/FindCUDA/run_nvcc.cmake | |
parent | 6f010f1c407704eea31c889fb8cf54f477e1d9c7 (diff) | |
download | CMake-393b09cb85522d9f2e4433844f17625b064f929d.zip CMake-393b09cb85522d9f2e4433844f17625b064f929d.tar.gz CMake-393b09cb85522d9f2e4433844f17625b064f929d.tar.bz2 |
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.
Diffstat (limited to 'Modules/FindCUDA/run_nvcc.cmake')
-rw-r--r-- | Modules/FindCUDA/run_nvcc.cmake | 470 |
1 files changed, 235 insertions, 235 deletions
diff --git a/Modules/FindCUDA/run_nvcc.cmake b/Modules/FindCUDA/run_nvcc.cmake index 8fdee9a..fc04dd2 100644 --- a/Modules/FindCUDA/run_nvcc.cmake +++ b/Modules/FindCUDA/run_nvcc.cmake @@ -1,235 +1,235 @@ -# 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
-# output files.
-
-# Input variables
-#
-# verbose:BOOL=<> OFF: Be as quiet as possible (default)
-# ON : Describe each step
-#
-# build_configuration:STRING=<> Typically one of Debug, MinSizeRel, Release, or
-# RelWithDebInfo, but it should match one of the
-# entries in CUDA_HOST_FLAGS. This is the build
-# configuration used when compiling the code. If
-# blank or unspecified Debug is assumed as this is
-# what CMake does.
-#
-# generated_file:STRING=<> File to generate. This argument must be passed in.
-#
-# generated_cubin_file:STRING=<> File to generate. This argument must be passed
-# in if build_cubin is true.
-
-if(NOT generated_file)
- message(FATAL_ERROR "You must specify generated_file on the command line")
-endif()
-
-# Set these up as variables to make reading the generated file easier
-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@")
-set(CUDA_make2cmake "@CUDA_make2cmake@")
-set(CUDA_parse_cubin "@CUDA_parse_cubin@")
-set(build_cubin @build_cubin@)
-# 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.
-set(generated_file_path "@generated_file_path@")
-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@")
-@CUDA_NVCC_FLAGS_CONFIG@
-set(nvcc_flags "@nvcc_flags@")
-set(CUDA_NVCC_INCLUDE_ARGS "@CUDA_NVCC_INCLUDE_ARGS@")
-set(format_flag "@format_flag@")
-
-if(build_cubin AND NOT generated_cubin_file)
- message(FATAL_ERROR "You must specify generated_cubin_file on the command line")
-endif()
-
-# This is the list of host compilation flags. It C or CXX should already have
-# been chosen by FindCUDA.cmake.
-@CUDA_HOST_FLAGS@
-
-# Take the compiler flags and package them up to be sent to the compiler via -Xcompiler
-set(nvcc_host_compiler_flags "")
-# If we weren't given a build_configuration, use Debug.
-if(NOT build_configuration)
- set(build_configuration Debug)
-endif()
-string(TOUPPER "${build_configuration}" build_configuration)
-#message("CUDA_NVCC_HOST_COMPILER_FLAGS = ${CUDA_NVCC_HOST_COMPILER_FLAGS}")
-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.
- set(nvcc_host_compiler_flags "${nvcc_host_compiler_flags},\"${flag}\"")
-endforeach()
-if (nvcc_host_compiler_flags)
- set(nvcc_host_compiler_flags "-Xcompiler" ${nvcc_host_compiler_flags})
-endif()
-#message("nvcc_host_compiler_flags = \"${nvcc_host_compiler_flags}\"")
-# Add the build specific configuration flags
-list(APPEND CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS_${build_configuration}})
-
-if(DEFINED CCBIN)
- set(CCBIN -ccbin "${CCBIN}")
-endif()
-
-# cuda_execute_process - Executes a command with optional command echo and status message.
-#
-# status - Status message to print if verbose is true
-# command - COMMAND argument from the usual execute_process argument structure
-# ARGN - Remaining arguments are the command with arguments
-#
-# CUDA_result - return value from running the command
-#
-# Make this a macro instead of a function, so that things like RESULT_VARIABLE
-# and other return variables are present after executing the process.
-macro(cuda_execute_process status command)
- set(_command ${command})
- if(NOT _command STREQUAL "COMMAND")
- message(FATAL_ERROR "Malformed call to cuda_execute_process. Missing COMMAND as second argument. (command = ${command})")
- endif()
- if(verbose)
- execute_process(COMMAND "${CMAKE_COMMAND}" -E echo -- ${status})
- # 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
- # copy and paste a runnable command line.
- set(cuda_execute_process_string)
- foreach(arg ${ARGN})
- # If there are quotes, excape them, so they come through.
- string(REPLACE "\"" "\\\"" arg ${arg})
- # Args with spaces need quotes around them to get them to be parsed as a single argument.
- if(arg MATCHES " ")
- list(APPEND cuda_execute_process_string "\"${arg}\"")
- else()
- list(APPEND cuda_execute_process_string ${arg})
- endif()
- endforeach()
- # Echo the command
- execute_process(COMMAND ${CMAKE_COMMAND} -E echo ${cuda_execute_process_string})
- endif(verbose)
- # Run the command
- execute_process(COMMAND ${ARGN} RESULT_VARIABLE CUDA_result )
-endmacro()
-
-# Delete the target file
-cuda_execute_process(
- "Removing ${generated_file}"
- COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}"
- )
-
-# Make sure the output directory is present
-cuda_execute_process(
- "Creating output directory: ${generated_file_path}"
- COMMAND "${CMAKE_COMMAND}" -E make_directory "${generated_file_path}"
- )
-
-# Generate the dependency file
-cuda_execute_process(
- "Generating dependency file: ${NVCC_generated_dependency_file}"
- COMMAND "${CUDA_NVCC_EXECUTABLE}"
- "${source_file}"
- ${CUDA_NVCC_FLAGS}
- ${nvcc_flags}
- ${CCBIN}
- ${nvcc_host_compiler_flags}
- -DNVCC
- -M
- -o "${NVCC_generated_dependency_file}"
- ${CUDA_NVCC_INCLUDE_ARGS}
- )
-
-if(CUDA_result)
- message(FATAL_ERROR "Error generating ${generated_file}")
-endif()
-
-# 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.
-# CMake will pass the quotes through and not be able to find the file.
-cuda_execute_process(
- "Generating temporary cmake readable file: ${cmake_dependency_file}.tmp"
- COMMAND "${CMAKE_COMMAND}"
- -D "input_file:FILEPATH=${NVCC_generated_dependency_file}"
- -D "output_file:FILEPATH=${cmake_dependency_file}.tmp"
- -P "${CUDA_make2cmake}"
- )
-
-if(CUDA_result)
- message(FATAL_ERROR "Error generating ${generated_file}")
-endif()
-
-# Copy the file if it is different
-cuda_execute_process(
- "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}"
- )
-
-if(CUDA_result)
- message(FATAL_ERROR "Error generating ${generated_file}")
-endif()
-
-# Delete the temporary file
-cuda_execute_process(
- "Removing ${cmake_dependency_file}.tmp and ${NVCC_generated_dependency_file}"
- COMMAND "${CMAKE_COMMAND}" -E remove "${cmake_dependency_file}.tmp" "${NVCC_generated_dependency_file}"
- )
-
-if(CUDA_result)
- message(FATAL_ERROR "Error generating ${generated_file}")
-endif()
-
-# Generate the code
-cuda_execute_process(
- "Generating ${generated_file}"
- COMMAND "${CUDA_NVCC_EXECUTABLE}"
- "${source_file}"
- ${CUDA_NVCC_FLAGS}
- ${nvcc_flags}
- ${CCBIN}
- ${nvcc_host_compiler_flags}
- -DNVCC
- ${format_flag} -o "${generated_file}"
- ${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 )
+# 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 +# output files. + +# Input variables +# +# verbose:BOOL=<> OFF: Be as quiet as possible (default) +# ON : Describe each step +# +# build_configuration:STRING=<> Typically one of Debug, MinSizeRel, Release, or +# RelWithDebInfo, but it should match one of the +# entries in CUDA_HOST_FLAGS. This is the build +# configuration used when compiling the code. If +# blank or unspecified Debug is assumed as this is +# what CMake does. +# +# generated_file:STRING=<> File to generate. This argument must be passed in. +# +# generated_cubin_file:STRING=<> File to generate. This argument must be passed +# in if build_cubin is true. + +if(NOT generated_file) + message(FATAL_ERROR "You must specify generated_file on the command line") +endif() + +# Set these up as variables to make reading the generated file easier +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@") +set(CUDA_make2cmake "@CUDA_make2cmake@") +set(CUDA_parse_cubin "@CUDA_parse_cubin@") +set(build_cubin @build_cubin@) +# 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. +set(generated_file_path "@generated_file_path@") +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@") +@CUDA_NVCC_FLAGS_CONFIG@ +set(nvcc_flags "@nvcc_flags@") +set(CUDA_NVCC_INCLUDE_ARGS "@CUDA_NVCC_INCLUDE_ARGS@") +set(format_flag "@format_flag@") + +if(build_cubin AND NOT generated_cubin_file) + message(FATAL_ERROR "You must specify generated_cubin_file on the command line") +endif() + +# This is the list of host compilation flags. It C or CXX should already have +# been chosen by FindCUDA.cmake. +@CUDA_HOST_FLAGS@ + +# Take the compiler flags and package them up to be sent to the compiler via -Xcompiler +set(nvcc_host_compiler_flags "") +# If we weren't given a build_configuration, use Debug. +if(NOT build_configuration) + set(build_configuration Debug) +endif() +string(TOUPPER "${build_configuration}" build_configuration) +#message("CUDA_NVCC_HOST_COMPILER_FLAGS = ${CUDA_NVCC_HOST_COMPILER_FLAGS}") +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. + set(nvcc_host_compiler_flags "${nvcc_host_compiler_flags},\"${flag}\"") +endforeach() +if (nvcc_host_compiler_flags) + set(nvcc_host_compiler_flags "-Xcompiler" ${nvcc_host_compiler_flags}) +endif() +#message("nvcc_host_compiler_flags = \"${nvcc_host_compiler_flags}\"") +# Add the build specific configuration flags +list(APPEND CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS_${build_configuration}}) + +if(DEFINED CCBIN) + set(CCBIN -ccbin "${CCBIN}") +endif() + +# cuda_execute_process - Executes a command with optional command echo and status message. +# +# status - Status message to print if verbose is true +# command - COMMAND argument from the usual execute_process argument structure +# ARGN - Remaining arguments are the command with arguments +# +# CUDA_result - return value from running the command +# +# Make this a macro instead of a function, so that things like RESULT_VARIABLE +# and other return variables are present after executing the process. +macro(cuda_execute_process status command) + set(_command ${command}) + if(NOT _command STREQUAL "COMMAND") + message(FATAL_ERROR "Malformed call to cuda_execute_process. Missing COMMAND as second argument. (command = ${command})") + endif() + if(verbose) + execute_process(COMMAND "${CMAKE_COMMAND}" -E echo -- ${status}) + # 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 + # copy and paste a runnable command line. + set(cuda_execute_process_string) + foreach(arg ${ARGN}) + # If there are quotes, excape them, so they come through. + string(REPLACE "\"" "\\\"" arg ${arg}) + # Args with spaces need quotes around them to get them to be parsed as a single argument. + if(arg MATCHES " ") + list(APPEND cuda_execute_process_string "\"${arg}\"") + else() + list(APPEND cuda_execute_process_string ${arg}) + endif() + endforeach() + # Echo the command + execute_process(COMMAND ${CMAKE_COMMAND} -E echo ${cuda_execute_process_string}) + endif(verbose) + # Run the command + execute_process(COMMAND ${ARGN} RESULT_VARIABLE CUDA_result ) +endmacro() + +# Delete the target file +cuda_execute_process( + "Removing ${generated_file}" + COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}" + ) + +# Make sure the output directory is present +cuda_execute_process( + "Creating output directory: ${generated_file_path}" + COMMAND "${CMAKE_COMMAND}" -E make_directory "${generated_file_path}" + ) + +# Generate the dependency file +cuda_execute_process( + "Generating dependency file: ${NVCC_generated_dependency_file}" + COMMAND "${CUDA_NVCC_EXECUTABLE}" + "${source_file}" + ${CUDA_NVCC_FLAGS} + ${nvcc_flags} + ${CCBIN} + ${nvcc_host_compiler_flags} + -DNVCC + -M + -o "${NVCC_generated_dependency_file}" + ${CUDA_NVCC_INCLUDE_ARGS} + ) + +if(CUDA_result) + message(FATAL_ERROR "Error generating ${generated_file}") +endif() + +# 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. +# CMake will pass the quotes through and not be able to find the file. +cuda_execute_process( + "Generating temporary cmake readable file: ${cmake_dependency_file}.tmp" + COMMAND "${CMAKE_COMMAND}" + -D "input_file:FILEPATH=${NVCC_generated_dependency_file}" + -D "output_file:FILEPATH=${cmake_dependency_file}.tmp" + -P "${CUDA_make2cmake}" + ) + +if(CUDA_result) + message(FATAL_ERROR "Error generating ${generated_file}") +endif() + +# Copy the file if it is different +cuda_execute_process( + "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}" + ) + +if(CUDA_result) + message(FATAL_ERROR "Error generating ${generated_file}") +endif() + +# Delete the temporary file +cuda_execute_process( + "Removing ${cmake_dependency_file}.tmp and ${NVCC_generated_dependency_file}" + COMMAND "${CMAKE_COMMAND}" -E remove "${cmake_dependency_file}.tmp" "${NVCC_generated_dependency_file}" + ) + +if(CUDA_result) + message(FATAL_ERROR "Error generating ${generated_file}") +endif() + +# Generate the code +cuda_execute_process( + "Generating ${generated_file}" + COMMAND "${CUDA_NVCC_EXECUTABLE}" + "${source_file}" + ${CUDA_NVCC_FLAGS} + ${nvcc_flags} + ${CCBIN} + ${nvcc_host_compiler_flags} + -DNVCC + ${format_flag} -o "${generated_file}" + ${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 ) |