CMake function which adds a target to check every that header in your project has all required #include's
Example usage:
check_header_includes(
HEADERS include/*.h
LIBRARIES ${PROJECT_NAME}
)
Your CMake project will get a new target added (with one child target per header file).
Run the generated target and it will try to compile each header of your project INDIVIDUALLY.
If there are errors, you can run each header individually by running its target.
LIBRARIES
specified libraries which the generated targets should link against.
If the rare circumstance that your *.h headers require libraries which your
project doesn't link against (or links PRIVATE
instead of PUBLIC
) then you
can specify a full list of libraries for the generated targets to link against:
check_header_includes(
HEADERS include/*.h
LIBRARIES ${PROJECT_NAME} CommonLibSSE::CommonLibSSE Catch2::Catch2 GTest::gtest
)
You can even provide PACKAGES
and we'll find_package for you...
check_header_includes(
HEADERS include/*.h
PACKAGES GTest Catch2
LIBRARIES ${PROJECT_NAME} CommonLibSSE::CommonLibSSE Catch2::Catch2 GTest::gtest
)
And LIBRARY_PATHS
and we'll both find_path and target_include_directories for you...
check_header_includes(
HEADERS include/*.h
PACKAGES GTest Catch2
LIBRARIES ${PROJECT_NAME} CommonLibSSE::CommonLibSSE Catch2::Catch2 GTest::gtest
LIBRARY_PATHS bandit/adapters.h snowhouse/assert.h
)
If you get complaints from Ninja about file paths, you can provide your own TEMP_DIR
check_header_includes(
...
TEMP_DIR "${CMAKE_SOURCE_DIR}/.tmp"
)