From d2be863b5ed5b66112290ee2f0a29765e89393f6 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Mon, 2 Jun 2025 12:17:04 -0400 Subject: CUDA: Add include paths from nvcc SYSTEM_INCLUDES entry Upcoming versions of nvcc are adding support for `SYSTEM_INCLUDES` which contain includes that are implicitly used with `-isystem` instead of `-I`. Support of this is needed in CMake as some CUDA Toolkit releases will start to have a different include directory layout and using only the output from `INCLUDES` will be insufficient to find all headers. --- Modules/FindCUDAToolkit.cmake | 14 +++++++++++++- Modules/Internal/CMakeNVCCParseImplicitInfo.cmake | 21 ++++++++++++++++++++- Tests/Cuda/IncludePathNoToolkit/main.cpp | 4 ++++ Tests/Cuda/Toolkit/main.cpp | 4 ++++ Tests/Cuda/ToolkitBeforeLang/main.cpp | 4 ++++ Tests/CudaOnly/Toolkit/main.cu | 4 ++++ Tests/CudaOnly/ToolkitBeforeLang/main.cu | 4 ++++ Tests/CudaOnly/ToolkitMultipleDirs/main.cu | 4 ++++ 8 files changed, 57 insertions(+), 2 deletions(-) diff --git a/Modules/FindCUDAToolkit.cmake b/Modules/FindCUDAToolkit.cmake index 15ffd48..9406796 100644 --- a/Modules/FindCUDAToolkit.cmake +++ b/Modules/FindCUDAToolkit.cmake @@ -694,9 +694,21 @@ else() get_filename_component(line "${line}" ABSOLUTE) list(APPEND _cmake_CUDAToolkit_include_directories "${line}") endforeach() + endif() + if(_CUDA_NVCC_OUT MATCHES "\\#\\$ SYSTEM_INCLUDES=([^\r\n]*)") + unset(_nvcc_output) + separate_arguments(_nvcc_output NATIVE_COMMAND "${CMAKE_MATCH_1}") + foreach(line IN LISTS _nvcc_output) + string(REGEX REPLACE "^-isystem" "" line "${line}") + if(line) + get_filename_component(line "${line}" ABSOLUTE) + list(APPEND _cmake_CUDAToolkit_include_directories "${line}") + endif() + endforeach() + endif() + if(DEFINED _cmake_CUDAToolkit_include_directories) message(CONFIGURE_LOG "Parsed CUDAToolkit nvcc implicit include information:\n${_cmake_CUDAToolkit_include_directories}\n\n") - set(_cmake_CUDAToolkit_include_directories "${_cmake_CUDAToolkit_include_directories}" CACHE INTERNAL "CUDAToolkit internal list of include directories") endif() if(_CUDA_NVCC_OUT MATCHES "\\#\\$ LIBRARIES=([^\r\n]*)") diff --git a/Modules/Internal/CMakeNVCCParseImplicitInfo.cmake b/Modules/Internal/CMakeNVCCParseImplicitInfo.cmake index 3aa10a2..cc8dd26 100644 --- a/Modules/Internal/CMakeNVCCParseImplicitInfo.cmake +++ b/Modules/Internal/CMakeNVCCParseImplicitInfo.cmake @@ -29,6 +29,14 @@ macro(cmake_nvcc_parse_implicit_info lang lang_var_) 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_output_orig MATCHES "#\\\$ +SYSTEM_INCLUDES= *([^\n]*)\n") + set(_nvcc_system_includes "${CMAKE_MATCH_1}") + string(APPEND _nvcc_log " found 'SYSTEM_INCLUDES=' string: [${_nvcc_system_includes}]\n") + else() + set(_nvcc_system_includes "") + string(REPLACE "\n" "\n " _nvcc_output_log "\n${_nvcc_output_orig}") + string(APPEND _nvcc_log " no 'SYSTEM_INCLUDES=' string found in nvcc output:${_nvcc_output_log}\n") + endif() string(REGEX MATCHALL "-arch compute_([0-9]+)" _nvcc_target_cpus "${_nvcc_output_orig}") foreach(_nvcc_target_cpu ${_nvcc_target_cpus}) if(_nvcc_target_cpu MATCHES "-arch compute_([0-9]+)") @@ -134,7 +142,7 @@ macro(cmake_nvcc_parse_implicit_info lang lang_var_) endif() set(${lang_var_}TOOLKIT_INCLUDE_DIRECTORIES) - if(_nvcc_includes) + if(_nvcc_includes OR _nvcc_system_includes) # across all operating system each include directory is prefixed with -I separate_arguments(_nvcc_output NATIVE_COMMAND "${_nvcc_includes}") foreach(line IN LISTS _nvcc_output) @@ -143,6 +151,17 @@ macro(cmake_nvcc_parse_implicit_info lang lang_var_) list(APPEND ${lang_var_}TOOLKIT_INCLUDE_DIRECTORIES "${line}") endforeach() + # across all operating system each system include directory is prefixed with -isystem + unset(_nvcc_output) + separate_arguments(_nvcc_output NATIVE_COMMAND "${_nvcc_system_includes}") + foreach(line IN LISTS _nvcc_output) + string(REGEX REPLACE "^-isystem" "" line "${line}") + if(line) + get_filename_component(line "${line}" ABSOLUTE) + list(APPEND ${lang_var_}TOOLKIT_INCLUDE_DIRECTORIES "${line}") + endif() + endforeach() + message(CONFIGURE_LOG "Parsed CUDA nvcc include information:\n${_nvcc_log}\n${log}\n\n") else() diff --git a/Tests/Cuda/IncludePathNoToolkit/main.cpp b/Tests/Cuda/IncludePathNoToolkit/main.cpp index c8d5c6b..9902536 100644 --- a/Tests/Cuda/IncludePathNoToolkit/main.cpp +++ b/Tests/Cuda/IncludePathNoToolkit/main.cpp @@ -1,6 +1,10 @@ // Only thing we care about is that these headers are found #include #include +#if CUDA_VERSION >= 11040 +# include +#endif +#include int main() { diff --git a/Tests/Cuda/Toolkit/main.cpp b/Tests/Cuda/Toolkit/main.cpp index c8d5c6b..9902536 100644 --- a/Tests/Cuda/Toolkit/main.cpp +++ b/Tests/Cuda/Toolkit/main.cpp @@ -1,6 +1,10 @@ // Only thing we care about is that these headers are found #include #include +#if CUDA_VERSION >= 11040 +# include +#endif +#include int main() { diff --git a/Tests/Cuda/ToolkitBeforeLang/main.cpp b/Tests/Cuda/ToolkitBeforeLang/main.cpp index c8d5c6b..9902536 100644 --- a/Tests/Cuda/ToolkitBeforeLang/main.cpp +++ b/Tests/Cuda/ToolkitBeforeLang/main.cpp @@ -1,6 +1,10 @@ // Only thing we care about is that these headers are found #include #include +#if CUDA_VERSION >= 11040 +# include +#endif +#include int main() { diff --git a/Tests/CudaOnly/Toolkit/main.cu b/Tests/CudaOnly/Toolkit/main.cu index 0f3ccdc..01a30c2 100644 --- a/Tests/CudaOnly/Toolkit/main.cu +++ b/Tests/CudaOnly/Toolkit/main.cu @@ -1,6 +1,10 @@ // Only thing we care about is that these headers are found #include #include +#if CUDA_VERSION >= 11040 +# include +#endif +#include int main(int argc, char** argv) { diff --git a/Tests/CudaOnly/ToolkitBeforeLang/main.cu b/Tests/CudaOnly/ToolkitBeforeLang/main.cu index 0f3ccdc..01a30c2 100644 --- a/Tests/CudaOnly/ToolkitBeforeLang/main.cu +++ b/Tests/CudaOnly/ToolkitBeforeLang/main.cu @@ -1,6 +1,10 @@ // Only thing we care about is that these headers are found #include #include +#if CUDA_VERSION >= 11040 +# include +#endif +#include int main(int argc, char** argv) { diff --git a/Tests/CudaOnly/ToolkitMultipleDirs/main.cu b/Tests/CudaOnly/ToolkitMultipleDirs/main.cu index 0f3ccdc..01a30c2 100644 --- a/Tests/CudaOnly/ToolkitMultipleDirs/main.cu +++ b/Tests/CudaOnly/ToolkitMultipleDirs/main.cu @@ -1,6 +1,10 @@ // Only thing we care about is that these headers are found #include #include +#if CUDA_VERSION >= 11040 +# include +#endif +#include int main(int argc, char** argv) { -- cgit v0.12