Skip to content

Commit 11b166d

Browse files
committed
Cleanup CMP0220 tests and write_language behavior
1 parent 3b8e31d commit 11b166d

6 files changed

Lines changed: 56 additions & 22 deletions

File tree

rapids-cmake/export/write_language.cmake

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ for packages included via `CPM` to enable extra languages.
3636
the language is enabled globally.
3737
3838
In CMake 4.5 and later this is not needed as `enable_language` supports being called from
39-
within functions and in subdirectories to enable languages globally. This function will act as
40-
a no-op in these versions when the policy `CMP0220` is set to `NEW`.
39+
within functions and in subdirectories to enable languages globally. This function will just
40+
call `enable_language` in these versions when the policy `CMP0220` is set to `NEW` where the
41+
`<file_path>` is included.
4142
4243
#]=======================================================================]
4344
function(rapids_export_write_language type lang file_path)
@@ -51,15 +52,6 @@ function(rapids_export_write_language type lang file_path)
5152
# since linking to a target with language standards
5253
# means `using`
5354
54-
# When CMP0220 is set to NEW, `enable_language` will make the language available globally
55-
if(POLICY CMP0220)
56-
cmake_policy(GET CMP0220 rapids_cmp0220_value)
57-
if(rapids_cmp0220_value STREQUAL "NEW")
58-
message(DEBUG "CMP0220 is set to NEW, skipping custom language hook propagation logic for @lang@.")
59-
return()
60-
endif()
61-
endif()
62-
6355
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
6456
if(NOT DEFINED CMAKE_CURRENT_FUNCTION)
6557
#Can't be called inside a function
@@ -90,6 +82,14 @@ endif()
9082
# Expose the language at the current scope
9183
enable_language(@lang@)
9284
85+
# When CMP0220 is set to NEW, `enable_language` will make the language available globally
86+
if(POLICY CMP0220)
87+
cmake_policy(GET CMP0220 rapids_cmp0220_value)
88+
if(rapids_cmp0220_value STREQUAL "NEW")
89+
return()
90+
endif()
91+
endif()
92+
9393
if(NOT EXISTS "${CMAKE_BINARY_DIR}/cmake/PropagateCMake@lang@Compiler.cmake")
9494
# 1.
9595
# Take everything that `enable_language` generated and transform all sets to PARENT_SCOPE ()

testing/export/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ add_cmake_config_test(write_dependencies-multiple-directories)
6969
add_cmake_config_test(write_dependencies-root-dirs.cmake)
7070

7171
if(POLICY CMP0220)
72-
add_cmake_build_test(write_language-CMP0220
73-
EXPECT_MATCH
74-
"CMP0220 is set to NEW, skipping custom language hook propagation logic for CUDA\\."
75-
)
72+
add_cmake_build_test(write_language-CMP0220)
7673
endif()
7774
add_cmake_build_test(write_language-multiple-nested-enables)
7875
add_cmake_build_test(write_language-nested-dirs)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# =============================================================================
2+
# cmake-format: off
3+
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# cmake-format: on
6+
# =============================================================================
7+
include(${rapids-cmake-dir}/export/write_language.cmake)
8+
9+
set(path "${CMAKE_CURRENT_BINARY_DIR}/enable_cuda.cmake")
10+
rapids_export_write_language(BUILD CUDA "${path}")
11+
12+
include(${path})
13+
14+
add_library(A STATIC static.cu)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
static __global__ void example_cuda_kernel(int& r, int x, int y) { r = x * y + (x * 4 - (y / 2)); }
2+
3+
int static_launch_kernelA(int x, int y)
4+
{
5+
int r;
6+
example_cuda_kernel<<<1, 1>>>(r, x, y);
7+
return r;
8+
}

testing/export/write_language-CMP0220/CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
# =============================================================================
77
cmake_minimum_required(VERSION 4.0 FATAL_ERROR)
88

9-
project(write_language-CMP0220 LANGUAGES NONE)
10-
11-
include(${rapids-cmake-dir}/export/write_language.cmake)
9+
project(write_language-CMP0220 LANGUAGES CXX)
1210

1311
cmake_policy(SET CMP0220 NEW)
1412

15-
set(path "${CMAKE_CURRENT_BINARY_DIR}/enable_cuda.cmake")
16-
rapids_export_write_language(BUILD CUDA "${path}")
13+
add_subdirectory(A)
14+
15+
add_executable(write_language-CMP0220 main.cpp)
16+
target_link_libraries(write_language-CMP0220 PRIVATE A)
1717

18-
add_custom_target(check_write_language_CMP0220 ALL COMMAND ${CMAKE_COMMAND} --log-level=DEBUG -P
19-
"${path}")
18+
cmake_language(DEFER GET_CALL_IDS all_ids)
19+
list(LENGTH all_ids list_len)
20+
if(NOT list_len EQUAL 1)
21+
message(FATAL_ERROR "Language hooks detected when CMP0220 is set to NEW: ${all_ids}")
22+
endif()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <iostream>
2+
3+
int static_launch_kernelA(int x, int y);
4+
5+
int main(int argc, char**)
6+
{
7+
auto resultA = static_launch_kernelA(3, argc);
8+
9+
if (resultA != 6) { return 1; }
10+
11+
return 0;
12+
}

0 commit comments

Comments
 (0)