Skip to content

Commit

Permalink
Check for missing inline on functions in public headers. (NVIDIA#2570)
Browse files Browse the repository at this point in the history
* 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 $<TARGET_OBJECTS:target> bypasses the duplicate checks.

* Add -fPIC, formatting.

* Switch link_check to executable to avoid -fPIC issues
  • Loading branch information
alliepiper authored and fbusato committed Nov 5, 2024
1 parent df0f305 commit e70640d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmake/CCCLGenerateHeaderTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_OBJECTS:${target_name}> 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}
$<TARGET_OBJECTS:${target_name}>
)

endfunction()
4 changes: 4 additions & 0 deletions cmake/link_check_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int main()
{
return 0;
}

0 comments on commit e70640d

Please sign in to comment.