FindCUDA: Take NVCC include directories from target properties
Fixes issue where include directories specified on the target are not passed on to NVCC. This includes both target_include_directories() as well as include directories added by dependency chaining. Closes: #14201
This commit is contained in:
parent
e240a7c017
commit
7ded655f7b
|
@ -730,7 +730,7 @@ else()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Set the user list of include dir to nothing to initialize it.
|
# Set the user list of include dir to nothing to initialize it.
|
||||||
set (CUDA_NVCC_INCLUDE_ARGS_USER "")
|
set (CUDA_NVCC_INCLUDE_DIRS_USER "")
|
||||||
set (CUDA_INCLUDE_DIRS ${CUDA_TOOLKIT_INCLUDE})
|
set (CUDA_INCLUDE_DIRS ${CUDA_TOOLKIT_INCLUDE})
|
||||||
|
|
||||||
macro(cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext )
|
macro(cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext )
|
||||||
|
@ -1025,7 +1025,7 @@ find_package_handle_standard_args(CUDA
|
||||||
# Add include directories to pass to the nvcc command.
|
# Add include directories to pass to the nvcc command.
|
||||||
macro(CUDA_INCLUDE_DIRECTORIES)
|
macro(CUDA_INCLUDE_DIRECTORIES)
|
||||||
foreach(dir ${ARGN})
|
foreach(dir ${ARGN})
|
||||||
list(APPEND CUDA_NVCC_INCLUDE_ARGS_USER -I${dir})
|
list(APPEND CUDA_NVCC_INCLUDE_DIRS_USER ${dir})
|
||||||
endforeach()
|
endforeach()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
@ -1249,17 +1249,15 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Initialize our list of includes with the user ones followed by the CUDA system ones.
|
# Initialize our list of includes with the user ones followed by the CUDA system ones.
|
||||||
set(CUDA_NVCC_INCLUDE_ARGS ${CUDA_NVCC_INCLUDE_ARGS_USER} "-I${CUDA_INCLUDE_DIRS}")
|
set(CUDA_NVCC_INCLUDE_DIRS ${CUDA_NVCC_INCLUDE_DIRS_USER} "${CUDA_INCLUDE_DIRS}")
|
||||||
# Get the include directories for this directory and use them for our nvcc command.
|
# Append the include directories for this target via generator expression, which is
|
||||||
# Remove duplicate entries which may be present since include_directories
|
# expanded by the FILE(GENERATE) call below. This generator expression captures all
|
||||||
# in CMake >= 2.8.8 does not remove them.
|
# include dirs set by the user, whether via directory properties or target properties
|
||||||
get_directory_property(CUDA_NVCC_INCLUDE_DIRECTORIES INCLUDE_DIRECTORIES)
|
list(APPEND CUDA_NVCC_INCLUDE_DIRS "$<TARGET_PROPERTY:${cuda_target},INCLUDE_DIRECTORIES>")
|
||||||
list(REMOVE_DUPLICATES CUDA_NVCC_INCLUDE_DIRECTORIES)
|
|
||||||
if(CUDA_NVCC_INCLUDE_DIRECTORIES)
|
# Do the same thing with compile definitions
|
||||||
foreach(dir ${CUDA_NVCC_INCLUDE_DIRECTORIES})
|
set(CUDA_NVCC_COMPILE_DEFINITIONS "$<TARGET_PROPERTY:${cuda_target},COMPILE_DEFINITIONS>")
|
||||||
list(APPEND CUDA_NVCC_INCLUDE_ARGS -I${dir})
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Reset these variables
|
# Reset these variables
|
||||||
set(CUDA_WRAP_OPTION_NVCC_FLAGS)
|
set(CUDA_WRAP_OPTION_NVCC_FLAGS)
|
||||||
|
@ -1349,14 +1347,6 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
|
||||||
string(REGEX REPLACE "[-]+std=c\\+\\+11" "" _cuda_host_flags "${_cuda_host_flags}")
|
string(REGEX REPLACE "[-]+std=c\\+\\+11" "" _cuda_host_flags "${_cuda_host_flags}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Get the list of definitions from the directory property
|
|
||||||
get_directory_property(CUDA_NVCC_DEFINITIONS COMPILE_DEFINITIONS)
|
|
||||||
if(CUDA_NVCC_DEFINITIONS)
|
|
||||||
foreach(_definition ${CUDA_NVCC_DEFINITIONS})
|
|
||||||
list(APPEND nvcc_flags "-D${_definition}")
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(_cuda_build_shared_libs)
|
if(_cuda_build_shared_libs)
|
||||||
list(APPEND nvcc_flags "-D${cuda_target}_EXPORTS")
|
list(APPEND nvcc_flags "-D${cuda_target}_EXPORTS")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -73,10 +73,25 @@ set(CUDA_NVCC_EXECUTABLE "@CUDA_NVCC_EXECUTABLE@") # path
|
||||||
set(CUDA_NVCC_FLAGS @CUDA_NVCC_FLAGS@ ;; @CUDA_WRAP_OPTION_NVCC_FLAGS@) # list
|
set(CUDA_NVCC_FLAGS @CUDA_NVCC_FLAGS@ ;; @CUDA_WRAP_OPTION_NVCC_FLAGS@) # list
|
||||||
@CUDA_NVCC_FLAGS_CONFIG@
|
@CUDA_NVCC_FLAGS_CONFIG@
|
||||||
set(nvcc_flags @nvcc_flags@) # list
|
set(nvcc_flags @nvcc_flags@) # list
|
||||||
set(CUDA_NVCC_INCLUDE_ARGS "@CUDA_NVCC_INCLUDE_ARGS@") # list (needs to be in quotes to handle spaces properly).
|
set(CUDA_NVCC_INCLUDE_DIRS "@CUDA_NVCC_INCLUDE_DIRS@") # list (needs to be in quotes to handle spaces properly).
|
||||||
|
set(CUDA_NVCC_COMPILE_DEFINITIONS "@CUDA_NVCC_COMPILE_DEFINITIONS@") # list (needs to be in quotes to handle spaces properly).
|
||||||
set(format_flag "@format_flag@") # string
|
set(format_flag "@format_flag@") # string
|
||||||
set(cuda_language_flag @cuda_language_flag@) # list
|
set(cuda_language_flag @cuda_language_flag@) # list
|
||||||
|
|
||||||
|
# Clean up list of include directories and add -I flags
|
||||||
|
list(REMOVE_DUPLICATES CUDA_NVCC_INCLUDE_DIRS)
|
||||||
|
set(CUDA_NVCC_INCLUDE_ARGS)
|
||||||
|
foreach(dir ${CUDA_NVCC_INCLUDE_DIRS})
|
||||||
|
# Extra quotes are added around each flag to help nvcc parse out flags with spaces.
|
||||||
|
list(APPEND CUDA_NVCC_INCLUDE_ARGS "-I${dir}")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Clean up list of compile definitions, add -D flags, and append to nvcc_flags
|
||||||
|
list(REMOVE_DUPLICATES CUDA_NVCC_COMPILE_DEFINITIONS)
|
||||||
|
foreach(def ${CUDA_NVCC_COMPILE_DEFINITIONS})
|
||||||
|
list(APPEND nvcc_flags "-D${def}")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
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()
|
||||||
|
|
Loading…
Reference in New Issue