diff --git a/rapids-cmake/export/write_language.cmake b/rapids-cmake/export/write_language.cmake index 5e565663..7a046775 100644 --- a/rapids-cmake/export/write_language.cmake +++ b/rapids-cmake/export/write_language.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# Copyright (c) 2021-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -115,16 +115,14 @@ include("${CMAKE_BINARY_DIR}/cmake/PropagateCMake@lang@Compiler.cmake") # - Each directory but the root needs to include `PropagateCMake@lang@Compiler.cmake` # - Since the root directory doesn't have a parent it only needs to include # `CMake@lang@Information` +set(rapids_directories "${CMAKE_CURRENT_SOURCE_DIR}") +get_directory_property(parent_dir DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_DIRECTORY) +while(parent_dir) + list(APPEND rapids_directories "${parent_dir}") + get_directory_property(parent_dir DIRECTORY "${parent_dir}" PARENT_DIRECTORY) +endwhile() -set(rapids_directory "${CMAKE_CURRENT_SOURCE_DIR}") -if(DEFINED CMAKE_CURRENT_FUNCTION) - string(APPEND rapids_directory "/fake_dir") -endif() - -set(rapids_root_directory "${CMAKE_SOURCE_DIR}") -cmake_path(GET rapids_directory PARENT_PATH rapids_directory) -while(NOT rapids_directory STREQUAL rapids_root_directory) - +foreach(rapids_directory IN LISTS rapids_directories) # Make sure we haven't already installed a language hook for this directory # Once we found a directory with an existing hook we can safely stop # as that means hooks exist from that point up in the graph @@ -136,20 +134,10 @@ while(NOT rapids_directory STREQUAL rapids_root_directory) else() break() endif() - - cmake_path(GET rapids_directory PARENT_PATH rapids_directory) -endwhile() - -# Make sure we haven't already installed a language hook for this directory -cmake_language(DEFER DIRECTORY "${CMAKE_SOURCE_DIR}" GET_CALL_IDS rapids_existing_calls) -if(NOT rapids_@lang@_hook IN_LIST rapids_existing_calls) - cmake_language(DEFER DIRECTORY "${CMAKE_SOURCE_DIR}" - ID rapids_@lang@_hook - CALL include "CMake@lang@Information") -endif() +endforeach() unset(rapids_existing_calls) -unset(rapids_directory) +unset(rapids_directories) unset(rapids_root_directory) ]=]) diff --git a/testing/export/write_language-nested-dirs/A/B/CMakeLists.txt b/testing/export/write_language-nested-dirs/A/B/CMakeLists.txt index c1f3be39..17d0ca93 100644 --- a/testing/export/write_language-nested-dirs/A/B/CMakeLists.txt +++ b/testing/export/write_language-nested-dirs/A/B/CMakeLists.txt @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2024, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,13 +16,6 @@ include(${rapids-cmake-dir}/export/write_language.cmake) -function(enable_nested_language file_path) - #replicates CPM including the file - include("${file_path}") -endfunction() - -set(path "${CMAKE_CURRENT_BINARY_DIR}/enable_cuda_language.cmake") -rapids_export_write_language(INSTALL CUDA "${path}") -enable_nested_language("${path}") +add_subdirectory(../C C) add_library(B STATIC static.cu) diff --git a/testing/export/write_language-nested-dirs/A/C/CMakeLists.txt b/testing/export/write_language-nested-dirs/A/C/CMakeLists.txt new file mode 100644 index 00000000..1865c344 --- /dev/null +++ b/testing/export/write_language-nested-dirs/A/C/CMakeLists.txt @@ -0,0 +1,28 @@ +#============================================================================= +# Copyright (c) 2021-2024, NVIDIA CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= + +include(${rapids-cmake-dir}/export/write_language.cmake) + +function(enable_nested_language file_path) + #replicates CPM including the file + include("${file_path}") +endfunction() + +set(path "${CMAKE_CURRENT_BINARY_DIR}/enable_cuda_language.cmake") +rapids_export_write_language(INSTALL CUDA "${path}") +enable_nested_language("${path}") + +add_library(C STATIC static.cu) diff --git a/testing/export/write_language-nested-dirs/A/C/static.cu b/testing/export/write_language-nested-dirs/A/C/static.cu new file mode 100644 index 00000000..fd20dc3f --- /dev/null +++ b/testing/export/write_language-nested-dirs/A/C/static.cu @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021-2024, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +static __global__ void example_cuda_kernel(int& r, int x, int y) { r = x * y + (x * 4 - (y / 2)); } + +int static_launch_kernelC(int x, int y) +{ + int r; + example_cuda_kernel<<<1, 1>>>(r, x, y); + return r; +}