Commit 7914fb82 authored by Brad King's avatar Brad King
Browse files

CUDA: Fix default selection of host compiler used to drive linking

When no explicit `CMAKE_CUDA_HOST_COMPILER` is specified by the user
then we do not pass `-ccbin` to `nvcc`.  In this case, nvcc's link line
we extract during the compiler identification step may not have the
absolute path to the host compiler it uses to drive linking.  If it is
not absolute, use the `PATH=` from nvcc's output to search for it since
that is the one `nvcc` would use.

This fixes our internal `CMAKE_CUDA_HOST_LINK_LAUNCHER` value used to
construct link lines when using `CUDA` as the linker language.  It needs
to match the host compiler `nvcc` uses internally during compilation.

Fixes: #17323
parent 0e1ef0ca
......@@ -87,6 +87,15 @@ if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
elseif(CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA)
set(_nvcc_log "")
string(REPLACE "\r" "" _nvcc_output_orig "${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}")
if(_nvcc_output_orig MATCHES "#\\\$ +PATH= *([^\n]*)\n")
set(_nvcc_path "${CMAKE_MATCH_1}")
string(APPEND _nvcc_log " found 'PATH=' string: [${_nvcc_path}]\n")
string(REPLACE ":" ";" _nvcc_path "${_nvcc_path}")
else()
set(_nvcc_path "")
string(REPLACE "\n" "\n " _nvcc_output_log "\n${_nvcc_output_orig}")
string(APPEND _nvcc_log " no 'PATH=' string found in nvcc output:${_nvcc_output_log}\n")
endif()
if(_nvcc_output_orig MATCHES "#\\\$ +LIBRARIES= *([^\n]*)\n")
set(_nvcc_libraries "${CMAKE_MATCH_1}")
string(APPEND _nvcc_log " found 'LIBRARIES=' string: [${_nvcc_libraries}]\n")
......@@ -131,7 +140,26 @@ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA)
else()
#extract the compiler that is being used for linking
separate_arguments(_nvcc_link_line_args UNIX_COMMAND "${_nvcc_link_line}")
list(GET _nvcc_link_line_args 0 CMAKE_CUDA_HOST_LINK_LAUNCHER)
list(GET _nvcc_link_line_args 0 _nvcc_host_link_launcher)
if(IS_ABSOLUTE "${_nvcc_host_link_launcher}")
string(APPEND _nvcc_log " extracted link launcher absolute path: [${_nvcc_host_link_launcher}]\n")
set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${_nvcc_host_link_launcher}")
else()
string(APPEND _nvcc_log " extracted link launcher name: [${_nvcc_host_link_launcher}]\n")
find_program(_nvcc_find_host_link_launcher
NAMES ${_nvcc_host_link_launcher}
PATHS ${_nvcc_path} NO_DEFAULT_PATH)
find_program(_nvcc_find_host_link_launcher
NAMES ${_nvcc_host_link_launcher})
if(_nvcc_find_host_link_launcher)
string(APPEND _nvcc_log " found link launcher absolute path: [${_nvcc_find_host_link_launcher}]\n")
set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${_nvcc_find_host_link_launcher}")
else()
string(APPEND _nvcc_log " could not find link launcher absolute path\n")
set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${_nvcc_host_link_launcher}")
endif()
unset(_nvcc_find_host_link_launcher CACHE)
endif()
endif()
#prefix the line with cuda-fake-ld so that implicit link info believes it is
......
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