|
| 1 | +# ============================================================================= |
| 2 | +# Copyright (c) 2025, NVIDIA CORPORATION. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | +# in compliance with the License. You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | +# or implied. See the License for the specific language governing permissions and limitations under |
| 12 | +# the License. |
| 13 | +# ============================================================================= |
| 14 | + |
| 15 | +# Build a list of all headers in `c/include/cuvs` |
| 16 | +# |
| 17 | +# cmake-lint: disable=E1126 |
| 18 | +function(cuvs_c_add_header_check project_root binding_header COMPONENT_PLACEHOLDER install_set) |
| 19 | + file( |
| 20 | + GLOB_RECURSE all_headers_to_match |
| 21 | + RELATIVE "${project_root}/include/" |
| 22 | + "${project_root}/include/*.h" |
| 23 | + ) |
| 24 | + |
| 25 | + set(template_contents |
| 26 | + [=[ |
| 27 | + set(all_headers_to_match @all_headers_to_match@) |
| 28 | + set(binding_header_name @binding_header@) |
| 29 | + set(binary_dir @CMAKE_CURRENT_BINARY_DIR@) |
| 30 | + set(src_dir @CMAKE_SOURCE_DIR@) |
| 31 | + |
| 32 | + function(check_binding_header mode header_list_var) |
| 33 | + |
| 34 | + if(mode STREQUAL BUILD) |
| 35 | + set(path "${src_dir}/include/${binding_header_name}") |
| 36 | + else() |
| 37 | + # Walk up the binary dir till we |
| 38 | + set(path "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/include/${binding_header_name}") |
| 39 | + endif() |
| 40 | + |
| 41 | + if(EXISTS "${path}") |
| 42 | + file(READ "${path}" binding_header_contents) |
| 43 | + string(REPLACE "\n" "" binding_header_contents "${binding_header_contents}") |
| 44 | + foreach(entry ${${header_list_var}}) |
| 45 | + if(NOT entry STREQUAL binding_header_name) |
| 46 | + string(FIND "${binding_header_contents}" "<${entry}>" contains) |
| 47 | + if(contains STREQUAL "-1") |
| 48 | + message(FATAL_ERROR "include \"${entry}\" not found in contents of ${binding_header_name}.") |
| 49 | + endif() |
| 50 | + endif() |
| 51 | + endforeach() |
| 52 | + else() |
| 53 | + message(FATAL_ERROR "check_binding_header failed to find ${binding_header_name} on disk.") |
| 54 | + endif() |
| 55 | + endfunction() |
| 56 | + |
| 57 | + function(check_installed_headers ) |
| 58 | + set(path "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/include/") |
| 59 | + file(GLOB_RECURSE installed_headers RELATIVE "${path}/" "${path}/cuvs/*.h") |
| 60 | + check_binding_header(INSTALL installed_headers) |
| 61 | + endfunction() |
| 62 | + |
| 63 | + if(CMAKE_CURRENT_LIST_DIR STREQUAL binary_dir) |
| 64 | + # Build directory checks |
| 65 | + # |
| 66 | + # 1. Check that binding header content includes all headers |
| 67 | + # that we cached |
| 68 | + # |
| 69 | + check_binding_header(BUILD all_headers_to_match) |
| 70 | + else() |
| 71 | + # Install directory checks |
| 72 | + # |
| 73 | + # 1. Check that all headers we have in our cached list are installed |
| 74 | + # 2. Check that binding header content includes all headers |
| 75 | + # that have have installed |
| 76 | + check_binding_header(INSTALL all_headers_to_match) |
| 77 | + check_installed_headers() |
| 78 | + endif() |
| 79 | + |
| 80 | +]=] |
| 81 | + ) |
| 82 | + |
| 83 | + set(output_path "${CMAKE_CURRENT_BINARY_DIR}/cuvs_header_check.cmake") |
| 84 | + file(CONFIGURE OUTPUT "${output_path}" CONTENT "${template_contents}" @ONLY) |
| 85 | + |
| 86 | + # Most likely need to roll all this into a CMake |
| 87 | + add_test(NAME cuvs_c_verify_install_headers COMMAND ${CMAKE_COMMAND} "-P=${output_path}") |
| 88 | + install( |
| 89 | + FILES "${output_path}" |
| 90 | + COMPONENT testing |
| 91 | + DESTINATION "." |
| 92 | + EXCLUDE_FROM_ALL |
| 93 | + ) |
| 94 | + set_property( |
| 95 | + TARGET rapids_test_install_${install_set} |
| 96 | + APPEND |
| 97 | + PROPERTY "TESTS_TO_RUN" "cuvs_c_verify_install_headers" |
| 98 | + ) |
| 99 | +endfunction() |
0 commit comments