FindCUDA: Use the PRE_LINK mode only for MSVC >= 10

Use normal custom command dependencies by default.  Use the PRE_LINK
approach only to work around what seems to be a bug in msbuild handling
of custom build rules that chain together.
This commit is contained in:
James Bigler 2013-03-13 23:57:37 -06:00 committed by Brad King
parent 6a19150b54
commit b6e9b8f127
1 changed files with 28 additions and 13 deletions

View File

@ -1327,13 +1327,6 @@ endfunction()
function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options object_files) function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options object_files)
if (object_files) if (object_files)
if(NOT EXISTS "${output_file}")
# Some generators (e.g. makefiles) can't proceed to the link phase if all
# input files aren't available. This guarantees the file exists, so that
# linking can begin.
execute_process(COMMAND ${CMAKE_COMMAND} -E touch "${output_file}")
endif()
set_source_files_properties("${output_file}" set_source_files_properties("${output_file}"
PROPERTIES PROPERTIES
EXTERNAL_OBJECT TRUE # This is an object file not to be compiled, but only EXTERNAL_OBJECT TRUE # This is an object file not to be compiled, but only
@ -1365,6 +1358,27 @@ function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options
endforeach() endforeach()
endforeach() endforeach()
file(RELATIVE_PATH output_file_relative_path "${CMAKE_BINARY_DIR}" "${output_file}") file(RELATIVE_PATH output_file_relative_path "${CMAKE_BINARY_DIR}" "${output_file}")
# Some generators don't handle the multiple levels of custom command
# dependencies correctly (obj1 depends on file1, obj2 depends on obj1), so
# we work around that issue by compiling the intermediate link object as a
# pre-link custom command in that situation.
set(do_obj_build_rule TRUE)
if (MSVC_VERSION GREATER 1599)
# VS 2010 and 2012 have this problem. If future versions fix this issue,
# it should still work, it just won't be as nice as the other method.
set(do_obj_build_rule FALSE)
endif()
if (do_obj_build_rule)
add_custom_command(
OUTPUT ${output_file}
DEPENDS ${object_files}
COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file}
${flags}
COMMENT "Building NVCC intermediate link file ${output_file_relative_path}"
)
else()
add_custom_command( add_custom_command(
TARGET ${cuda_target} TARGET ${cuda_target}
PRE_LINK PRE_LINK
@ -1372,6 +1386,7 @@ function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options
COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} ${flags} -dlink ${object_files} -o "${output_file}" COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} ${flags} -dlink ${object_files} -o "${output_file}"
) )
endif() endif()
endif()
endfunction() endfunction()
############################################################################### ###############################################################################