mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-24 09:31:34 +08:00
Added header dependency tests.
This commit is contained in:
parent
5550eb9753
commit
2666b6cbf1
@ -12,6 +12,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
add_library(spdlog INTERFACE)
|
||||
|
||||
option(SPDLOG_BUILD_EXAMPLES "Build examples" OFF)
|
||||
option(SPDLOG_BUILD_TESTS "Build tests" OFF)
|
||||
|
||||
target_include_directories(
|
||||
spdlog
|
||||
@ -20,11 +21,17 @@ target_include_directories(
|
||||
"$<INSTALL_INTERFACE:include>"
|
||||
)
|
||||
|
||||
set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
|
||||
if(SPDLOG_BUILD_EXAMPLES)
|
||||
enable_testing()
|
||||
add_subdirectory(example)
|
||||
endif()
|
||||
|
||||
if(SPDLOG_BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
### Install ###
|
||||
# * https://github.com/forexample/package-example
|
||||
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
||||
|
21
tests/CMakeLists.txt
Normal file
21
tests/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
||||
#
|
||||
# Tests
|
||||
#
|
||||
|
||||
enable_testing()
|
||||
|
||||
# Build Catch unit tests
|
||||
#function(add_catch_test _testname)
|
||||
# add_executable(${_testname} ${_testname}.cpp)
|
||||
# target_link_libraries(${_testname} Catch)
|
||||
# add_test(NAME test_${_testname} COMMAND ${_testname})
|
||||
#endfunction()
|
||||
#
|
||||
#file(GLOB catch_tests LIST_DIRECTORIES false *.cpp)
|
||||
#foreach(catch_test IN LIST catch_tests)
|
||||
# add_catch_test(${catch_test})
|
||||
#endforeach()
|
||||
|
||||
# Ensure headers include their own dependencies
|
||||
add_subdirectory(header_dependencies)
|
||||
|
58
tests/header_dependencies/CMakeLists.txt
Normal file
58
tests/header_dependencies/CMakeLists.txt
Normal file
@ -0,0 +1,58 @@
|
||||
#
|
||||
# Ensure all headers include all dependencies
|
||||
#
|
||||
|
||||
set(IGNORED_HEADERS "")
|
||||
|
||||
set(COMMON_TEST_LIBRARIES spdlog)
|
||||
|
||||
add_custom_target(header_dependencies)
|
||||
|
||||
file(GLOB_RECURSE headers RELATIVE "${HEADER_BASE}" ${HEADER_BASE}/*.h)
|
||||
set(test_index 0)
|
||||
foreach(HEADER ${headers})
|
||||
# Sample of relevant variables computed here
|
||||
# HEADER: details/line_logger_impl.h
|
||||
# symbolname: spdlog_details_line_logger_impl
|
||||
|
||||
# Compute symbolname
|
||||
string(REPLACE ".h" "" symbolname "${HEADER}")
|
||||
string(MAKE_C_IDENTIFIER "${symbolname}" symbolname)
|
||||
|
||||
list(FIND IGNORED_HEADERS "${HEADER}" _index)
|
||||
# If we didn't explicitly ignore this and if we built this target
|
||||
if(${_index} EQUAL -1)
|
||||
#message(STATUS "${HEADER}: '${symbolname}'")
|
||||
|
||||
set(extension cpp)
|
||||
|
||||
# Name the test and output file with a number, to dodge Windows path length limits.
|
||||
# Call it header, instead of test, to avoid polluting the 'executable namespace'
|
||||
set(test_name "header_${extension}_${test_index}")
|
||||
|
||||
set(source_file "${CMAKE_CURRENT_SOURCE_DIR}/main.${extension}")
|
||||
|
||||
add_executable(${test_name} "${source_file}")
|
||||
target_compile_definitions(${test_name} PRIVATE HEADER_TO_TEST="${HEADER}")
|
||||
target_include_directories(${test_name}
|
||||
PRIVATE
|
||||
${BUILDTREE_HEADER_BASE}
|
||||
${HEADER_BASE})
|
||||
|
||||
set_target_properties(${test_name} PROPERTIES
|
||||
FOLDER "Header dependency tests")
|
||||
|
||||
target_link_libraries(${test_name}
|
||||
PRIVATE
|
||||
${COMMON_TEST_LIBRARIES}
|
||||
${LIBRARIES_${symbolname}}
|
||||
${LIBRARIES_${libname}})
|
||||
|
||||
add_test(NAME ${test_name}_builds COMMAND ${test_name})
|
||||
add_dependencies(header_dependencies ${test_name})
|
||||
|
||||
math(EXPR test_index "${test_index} + 1")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
|
7
tests/header_dependencies/main.c
Normal file
7
tests/header_dependencies/main.c
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
#include HEADER_TO_TEST
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
return 0;
|
||||
}
|
4
tests/header_dependencies/main.cpp
Normal file
4
tests/header_dependencies/main.cpp
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
#include HEADER_TO_TEST
|
||||
|
||||
int main(int argc, char *argv[]) { return 0; }
|
Loading…
Reference in New Issue
Block a user