diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2017-02-08 21:51:18 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-02-10 21:08:06 (GMT) |
commit | 44f3acb202c316bc6a863a1823aaafae486c899a (patch) | |
tree | 58969a6efd466eee165d0e288cb7f15778242783 /Modules/CMakeDetermineCUDACompiler.cmake | |
parent | 84df4a49500e51ac6e2a19a77e385e66234386f7 (diff) | |
download | CMake-44f3acb202c316bc6a863a1823aaafae486c899a.zip CMake-44f3acb202c316bc6a863a1823aaafae486c899a.tar.gz CMake-44f3acb202c316bc6a863a1823aaafae486c899a.tar.bz2 |
CUDA: Detect the toolkit include directories
The `nvcc -v` output provides what include directories need to be added
to use the CUDA toolkit from other languages ( C/C++ ).
Diffstat (limited to 'Modules/CMakeDetermineCUDACompiler.cmake')
-rw-r--r-- | Modules/CMakeDetermineCUDACompiler.cmake | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index bef6d0e..7b6d17b 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -84,20 +84,20 @@ endif() #the compiler with cuda-fake-ld and pass too CMAKE_PARSE_IMPLICIT_LINK_INFO if(CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA) set(_nvcc_log "") - string(REPLACE "\r" "" _nvcc_output "${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}") - if(_nvcc_output MATCHES "#\\\$ +LIBRARIES= *([^\n]*)\n") + string(REPLACE "\r" "" _nvcc_output_orig "${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}") + if(_nvcc_output_orig MATCHES "#\\\$ +LIBRARIES= *([^\n]*)\n") set(_nvcc_libraries "${CMAKE_MATCH_1}") string(APPEND _nvcc_log " found 'LIBRARIES=' string: [${_nvcc_libraries}]\n") else() set(_nvcc_libraries "") - string(REPLACE "\n" "\n " _nvcc_output_log "\n${_nvcc_output}") + string(REPLACE "\n" "\n " _nvcc_output_log "\n${_nvcc_output_orig}") string(APPEND _nvcc_log " no 'LIBRARIES=' string found in nvcc output:${_nvcc_output_log}\n") endif() set(_nvcc_link_line "") if(_nvcc_libraries) # Remove variable assignments. - string(REGEX REPLACE "#\\\$ *[^= ]+=[^\n]*\n" "" _nvcc_output "${_nvcc_output}") + string(REGEX REPLACE "#\\\$ *[^= ]+=[^\n]*\n" "" _nvcc_output "${_nvcc_output_orig}") # Split lines. string(REGEX REPLACE "\n+(#\\\$ )?" ";" _nvcc_output "${_nvcc_output}") foreach(line IN LISTS _nvcc_output) @@ -150,6 +150,32 @@ if(CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA) message(FATAL_ERROR "Failed to extract nvcc implicit link line.") endif() + set(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES ) + if(_nvcc_output_orig MATCHES "#\\\$ +INCLUDES= *([^\n]*)\n") + set(_nvcc_includes "${CMAKE_MATCH_1}") + string(APPEND _nvcc_log " found 'INCLUDES=' string: [${_nvcc_includes}]\n") + else() + set(_nvcc_includes "") + string(REPLACE "\n" "\n " _nvcc_output_log "\n${_nvcc_output_orig}") + string(APPEND _nvcc_log " no 'INCLUDES=' string found in nvcc output:${_nvcc_output_log}\n") + endif() + if(_nvcc_includes) + # across all operating system each include directory is prefixed with -I + separate_arguments(_nvcc_output UNIX_COMMAND "${_nvcc_includes}") + foreach(line IN LISTS _nvcc_output) + string(REGEX REPLACE "^-I" "" line "${line}") + get_filename_component(line "${line}" ABSOLUTE) + list(APPEND CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES "${line}") + endforeach() + + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Parsed CUDA nvcc include information from above output:\n${_nvcc_log}\n${log}\n\n") + else() + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Failed to detect CUDA nvcc include information:\n${_nvcc_log}\n\n") + endif() + + endif() # configure all variables set in this file |