summaryrefslogtreecommitdiffstats
path: root/Modules/FindCUDA.cmake
diff options
context:
space:
mode:
authorJames Bigler <jamesbigler@gmail.com>2011-12-06 02:00:00 (GMT)
committerJames Bigler <jamesbigler@gmail.com>2011-12-06 02:00:00 (GMT)
commit80e279d37c246fb2b3da5e3cf396bab51e8b8f6b (patch)
treeae0daae110a68f9b78149e66b721118ba818b950 /Modules/FindCUDA.cmake
parente0bc42aa4ff086e9c6976ab91ba924530df0bf72 (diff)
downloadCMake-80e279d37c246fb2b3da5e3cf396bab51e8b8f6b.zip
CMake-80e279d37c246fb2b3da5e3cf396bab51e8b8f6b.tar.gz
CMake-80e279d37c246fb2b3da5e3cf396bab51e8b8f6b.tar.bz2
Make CUDA working directory unique for each target.
This allows you to have more than source file with the same name but different directories. The intermediate and configuration files are now in this same directory.
Diffstat (limited to 'Modules/FindCUDA.cmake')
-rw-r--r--Modules/FindCUDA.cmake64
1 files changed, 54 insertions, 10 deletions
diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake
index d5ef430..8750d30 100644
--- a/Modules/FindCUDA.cmake
+++ b/Modules/FindCUDA.cmake
@@ -809,6 +809,43 @@ function(CUDA_BUILD_SHARED_LIBRARY shared_flag)
endfunction()
##############################################################################
+# Helper to avoid clashes of files with the same basename but different paths.
+# This doesn't attempt to do exactly what CMake internals do, which is to only
+# add this path when there is a conflict, since by the time a second collision
+# in names is detected it's already too late to fix the first one. For
+# consistency sake the relative path will be added to all files.
+function(CUDA_COMPUTE_BUILD_PATH path build_path)
+ #message("CUDA_COMPUTE_BUILD_PATH([${path}] ${build_path})")
+ # Only deal with CMake style paths from here on out
+ file(TO_CMAKE_PATH "${path}" bpath)
+ if (IS_ABSOLUTE "${bpath}")
+ # Absolute paths are generally unnessary, especially if something like
+ # FILE(GLOB_RECURSE) is used to pick up the files.
+ file(RELATIVE_PATH bpath "${CMAKE_CURRENT_SOURCE_DIR}" "${bpath}")
+ endif()
+
+ # This recipie is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the
+ # CMake source.
+
+ # Remove leading /
+ string(REGEX REPLACE "^[/]+" "" bpath "${bpath}")
+ # Avoid absolute paths by removing ':'
+ string(REPLACE ":" "_" bpath "${bpath}")
+ # Avoid relative paths that go up the tree
+ string(REPLACE "../" "__/" bpath "${bpath}")
+ # Avoid spaces
+ string(REPLACE " " "_" bpath "${bpath}")
+
+ # Strip off the filename. I wait until here to do it, since removin the
+ # basename can make a path that looked like path/../basename turn into
+ # path/.. (notice the trailing slash).
+ get_filename_component(bpath "${bpath}" PATH)
+
+ set(${build_path} "${bpath}" PARENT_SCOPE)
+ #message("${build_path} = ${bpath}")
+endfunction()
+
+##############################################################################
# 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
# dependent upon the format parameter. The compiler is invoked once with -M
@@ -977,13 +1014,6 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
list(APPEND nvcc_flags "-D${cuda_target}_EXPORTS")
endif()
- # Determine output directory
- if(CUDA_GENERATED_OUTPUT_DIR)
- set(cuda_compile_output_dir "${CUDA_GENERATED_OUTPUT_DIR}")
- else()
- set(cuda_compile_output_dir "${CMAKE_CURRENT_BINARY_DIR}")
- endif()
-
# Reset the output variable
set(_cuda_wrap_generated_files "")
@@ -994,6 +1024,19 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
get_source_file_property(_is_header ${file} HEADER_FILE_ONLY)
if(${file} MATCHES ".*\\.cu$" AND NOT _is_header)
+ # Determine output directory
+ cuda_compute_build_path("${file}" cuda_build_path)
+ set(cuda_compile_intermediate_directory "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${cuda_build_path}")
+ if(CUDA_GENERATED_OUTPUT_DIR)
+ set(cuda_compile_output_dir "${CUDA_GENERATED_OUTPUT_DIR}")
+ else()
+ if ( compile_to_ptx )
+ set(cuda_compile_output_dir "${CMAKE_CURRENT_BINARY_DIR}")
+ else()
+ set(cuda_compile_output_dir "${cuda_compile_intermediate_directory}")
+ endif()
+ endif()
+
# Add a custom target to generate a c or ptx file. ######################
get_filename_component( basename ${file} NAME )
@@ -1013,10 +1056,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}/CMakeFiles/${generated_file_basename}.depend")
- set(NVCC_generated_dependency_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${generated_file_basename}.NVCC-depend")
+ set(cmake_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.depend")
+ set(NVCC_generated_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.NVCC-depend")
set(generated_cubin_file "${generated_file_path}/${generated_file_basename}.cubin.txt")
- set(custom_target_script "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${generated_file_basename}.cmake")
+ set(custom_target_script "${cuda_compile_intermediate_directory}/${generated_file_basename}.cmake")
# Setup properties for obj files:
if( NOT compile_to_ptx )
@@ -1096,6 +1139,7 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
-D "generated_file:STRING=${generated_file}"
-D "generated_cubin_file:STRING=${generated_cubin_file}"
-P "${custom_target_script}"
+ WORKING_DIRECTORY "${cuda_compile_intermediate_directory}"
COMMENT "${cuda_build_comment_string}"
)