From db397f441997f975b07fe0c09ca5a85d0970e4b7 Mon Sep 17 00:00:00 2001 From: Allison Piper Date: Mon, 28 Oct 2024 13:39:40 -0400 Subject: [PATCH] Check for missing `inline` on functions in public headers. (#2570) * Check for missing `inline` on functions in public headers. We can test for missing `inline` markup by linking the header objects into the same target twice. By default CMake will eliminate duplicate link targets, but linking both the target and the $ bypasses the duplicate checks. * Add -fPIC, formatting. * Switch link_check to executable to avoid -fPIC issues --- cmake/CCCLGenerateHeaderTests.cmake | 12 ++++++++++++ cmake/link_check_main.cpp | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 cmake/link_check_main.cpp diff --git a/cmake/CCCLGenerateHeaderTests.cmake b/cmake/CCCLGenerateHeaderTests.cmake index e483b194513..9371cbaa7d7 100644 --- a/cmake/CCCLGenerateHeaderTests.cmake +++ b/cmake/CCCLGenerateHeaderTests.cmake @@ -108,4 +108,16 @@ function(cccl_generate_header_tests target_name project_include_path) add_library(${target_name} OBJECT ${header_srcs}) cccl_configure_target(${target_name} ${cccl_configure_target_options}) + # Check that all functions in headers are either template functions or inline: + set(link_target ${target_name}.link_check) + add_executable(${link_target} "${CCCL_SOURCE_DIR}/cmake/link_check_main.cpp") + cccl_configure_target(${link_target} ${cccl_configure_target_options}) + # Linking both ${target_name} and $ forces CMake to + # link the same objects twice. The compiler will complain about duplicate symbols if + # any functions are missing inline markup. + target_link_libraries(${link_target} PRIVATE + ${target_name} + $ + ) + endfunction() diff --git a/cmake/link_check_main.cpp b/cmake/link_check_main.cpp new file mode 100644 index 00000000000..f8b643afbf2 --- /dev/null +++ b/cmake/link_check_main.cpp @@ -0,0 +1,4 @@ +int main() +{ + return 0; +}