-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write_language
now properly walks up the add_subdirectory
call st…
…ack (#671) Instead of assuming the filesystem directory layout matches `add_subdirectory` calls, we now walk the CMake `PARENT_DIRECTORY` property. This allows us to handle more custom layouts of CMake projects Authors: - Robert Maynard (https://github.com/robertmaynard) Approvers: - Vyas Ramasubramani (https://github.com/vyasr) URL: #671
- Loading branch information
1 parent
1f26d58
commit 20bb29b
Showing
4 changed files
with
64 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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@[email protected]") | |
# - Each directory but the root needs to include `PropagateCMake@[email protected]` | ||
# - 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) | ||
]=]) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
testing/export/write_language-nested-dirs/A/C/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |