Skip to content

Commit

Permalink
Check for missing inline on functions in public headers.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alliepiper committed Oct 12, 2024
1 parent 7d5fb2a commit ca79507
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmake/CCCLGenerateHeaderTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,13 @@ 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_library(${link_target} SHARED)
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()

0 comments on commit ca79507

Please sign in to comment.