2015-02-13 19:00:14 +01:00
|
|
|
if (BUILD_TESTS)
|
|
|
|
file(GLOB hdrs "*.h")
|
|
|
|
file(GLOB srcs "*.cpp")
|
2023-01-26 22:13:07 +01:00
|
|
|
list(APPEND testrunner_SOURCES ${hdrs} ${srcs} $<TARGET_OBJECTS:cli_objs>)
|
|
|
|
if (NOT BUILD_CORE_DLL)
|
|
|
|
list(APPEND testrunner_SOURCES $<TARGET_OBJECTS:cppcheck-core> $<TARGET_OBJECTS:simplecpp_objs>)
|
|
|
|
if(USE_BUNDLED_TINYXML2)
|
|
|
|
list(APPEND testrunner_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
|
|
|
|
endif()
|
2020-11-22 08:57:07 +01:00
|
|
|
endif()
|
2015-02-13 19:00:14 +01:00
|
|
|
|
2020-11-22 08:57:07 +01:00
|
|
|
add_executable(testrunner ${testrunner_SOURCES})
|
2021-10-30 09:08:07 +02:00
|
|
|
target_include_directories(testrunner PRIVATE ${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/cli/)
|
|
|
|
if(USE_BUNDLED_TINYXML2)
|
|
|
|
target_include_directories(testrunner PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2)
|
2022-09-06 18:30:59 +02:00
|
|
|
else()
|
|
|
|
target_include_directories(testrunner SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
|
2021-10-30 09:08:07 +02:00
|
|
|
endif()
|
|
|
|
target_include_directories(testrunner PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
|
2015-11-26 20:25:09 +01:00
|
|
|
if (HAVE_RULES)
|
2020-05-27 05:15:46 +02:00
|
|
|
target_link_libraries(testrunner ${PCRE_LIBRARY})
|
|
|
|
endif()
|
2020-11-02 20:16:15 +01:00
|
|
|
if (WIN32 AND NOT BORLAND)
|
2021-03-29 17:04:42 +02:00
|
|
|
if(NOT MINGW)
|
|
|
|
target_link_libraries(testrunner Shlwapi.lib)
|
|
|
|
else()
|
|
|
|
target_link_libraries(testrunner shlwapi)
|
|
|
|
endif()
|
2020-11-02 20:16:15 +01:00
|
|
|
endif()
|
2020-11-22 08:57:07 +01:00
|
|
|
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
|
2022-03-15 21:17:03 +01:00
|
|
|
target_link_libraries(testrunner ${tinyxml2_LIBRARIES})
|
2020-11-22 08:57:07 +01:00
|
|
|
endif()
|
2022-07-08 16:42:57 +02:00
|
|
|
target_link_libraries(testrunner ${CMAKE_THREAD_LIBS_INIT})
|
2023-01-26 22:13:07 +01:00
|
|
|
if (BUILD_CORE_DLL)
|
|
|
|
target_compile_definitions(testrunner PRIVATE CPPCHECKLIB_IMPORT SIMPLECPP_IMPORT)
|
|
|
|
target_link_libraries(testrunner cppcheck-core)
|
|
|
|
endif()
|
2015-02-13 19:00:14 +01:00
|
|
|
|
2020-09-23 07:51:21 +02:00
|
|
|
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
|
2020-06-16 19:55:15 +02:00
|
|
|
target_precompile_headers(testrunner PRIVATE precompiled.h)
|
|
|
|
endif()
|
|
|
|
|
2015-02-13 19:00:14 +01:00
|
|
|
add_dependencies(testrunner copy_cfg)
|
2021-08-12 20:17:51 +02:00
|
|
|
add_dependencies(testrunner copy_addons)
|
2023-01-26 22:05:40 +01:00
|
|
|
add_dependencies(testrunner copy_platforms)
|
2022-07-09 23:21:11 +02:00
|
|
|
add_dependencies(testrunner run-dmake)
|
2015-11-26 21:01:07 +01:00
|
|
|
|
2020-11-02 20:16:15 +01:00
|
|
|
if (LIBXML2_XMLLINT_EXECUTABLE)
|
2022-06-02 22:26:01 +02:00
|
|
|
# TODO: run the CMake implementation of the tests
|
2020-11-02 20:16:15 +01:00
|
|
|
# TODO: get rid of the copy
|
|
|
|
add_custom_target(checkcfg ${CMAKE_COMMAND} -E copy $<TARGET_FILE:cppcheck> ${CMAKE_SOURCE_DIR}
|
|
|
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/cfg/runtests.sh
|
2022-04-20 17:27:12 +02:00
|
|
|
DEPENDS cppcheck validateCFG)
|
2020-11-02 20:16:15 +01:00
|
|
|
endif()
|
2020-02-13 16:27:06 +01:00
|
|
|
|
2020-11-02 20:16:15 +01:00
|
|
|
if (REGISTER_TESTS)
|
2022-06-02 22:26:01 +02:00
|
|
|
# CMP0064 requires 3.4
|
|
|
|
# CMAKE_MATCH_<n> usage for if (MATCHES) requires 3.9
|
|
|
|
cmake_minimum_required(VERSION 3.9)
|
2020-11-02 20:16:15 +01:00
|
|
|
cmake_policy(SET CMP0064 NEW)
|
|
|
|
cmake_policy(SET CMP0057 NEW)
|
|
|
|
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
include(ProcessorCount)
|
|
|
|
ProcessorCount(N)
|
|
|
|
set(CTEST_PARALLEL_LEVEL ${N} CACHE STRING "CTest parallel level")
|
2021-07-08 21:21:35 +02:00
|
|
|
set(CTEST_TIMEOUT 90 CACHE STRING "CTest timeout")
|
|
|
|
add_custom_target(check ${CMAKE_CTEST_COMMAND} --output-on-failure -j ${CTEST_PARALLEL_LEVEL} -C ${CMAKE_CFG_INTDIR} --timeout ${CTEST_TIMEOUT}
|
2020-11-02 20:16:15 +01:00
|
|
|
DEPENDS testrunner cppcheck)
|
|
|
|
|
|
|
|
set(SKIP_TESTS "" CACHE STRING "A list of tests to skip")
|
|
|
|
|
|
|
|
function(add_fixture NAME)
|
|
|
|
if (${NAME} IN_LIST SKIP_TESTS)
|
|
|
|
elseif(TEST ${NAME})
|
|
|
|
else()
|
2022-09-24 11:59:13 +02:00
|
|
|
add_test(NAME ${NAME} COMMAND testrunner ${NAME} WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
2020-11-02 20:16:15 +01:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
foreach(SRC ${srcs})
|
2022-06-02 22:26:01 +02:00
|
|
|
file(STRINGS ${SRC} FIXTURE_LINE REGEX "^REGISTER_TEST\\([a-zA-z0-9]+\\)$")
|
|
|
|
foreach(_fixture_line ${FIXTURE_LINE})
|
|
|
|
if(_fixture_line MATCHES "^REGISTER_TEST\\(([a-zA-z0-9]+)\\)$")
|
|
|
|
add_fixture(${CMAKE_MATCH_1})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2020-11-02 20:16:15 +01:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
function(add_cfg CFG_TEST)
|
|
|
|
set(oneValueArgs PLATFORM NAME)
|
2023-02-24 21:37:56 +01:00
|
|
|
set(multiValueArgs ADD_LIBRARY)
|
2020-11-02 20:16:15 +01:00
|
|
|
|
|
|
|
cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
2023-02-24 21:37:56 +01:00
|
|
|
get_filename_component(LIBRARY ${CFG_TEST} NAME_WE)
|
|
|
|
# TODO: get rid of this
|
|
|
|
if(PARSE_ADD_LIBRARY)
|
|
|
|
string(REPLACE ";" "," ADD_LIBRARY "${PARSE_ADD_LIBRARY}")
|
|
|
|
set(LIBRARY "${ADD_LIBRARY},${LIBRARY}")
|
2020-02-13 16:27:06 +01:00
|
|
|
endif()
|
2020-11-02 20:16:15 +01:00
|
|
|
set(PLATFORM unix64)
|
|
|
|
if(PARSE_PLATFORM)
|
|
|
|
set(PLATFORM ${PARSE_PLATFORM})
|
|
|
|
endif()
|
|
|
|
if(PARSE_NAME)
|
|
|
|
set(TEST_NAME ${PARSE_NAME})
|
|
|
|
else()
|
|
|
|
string(MAKE_C_IDENTIFIER ${CFG_TEST} TEST_NAME)
|
|
|
|
endif()
|
2022-06-19 19:26:49 +02:00
|
|
|
if ("cfg-${TEST_NAME}" IN_LIST SKIP_TESTS)
|
2020-11-02 20:16:15 +01:00
|
|
|
else()
|
2023-03-09 20:04:20 +01:00
|
|
|
# TODO: remove missingInclude disabling when it no longer is implied by --enable=information
|
2020-11-02 20:16:15 +01:00
|
|
|
# TODO: add syntax check
|
|
|
|
add_test(NAME cfg-${TEST_NAME}
|
|
|
|
COMMAND $<TARGET_FILE:cppcheck>
|
|
|
|
--check-library
|
|
|
|
--platform=${PLATFORM}
|
|
|
|
--library=${LIBRARY}
|
2023-02-24 21:37:56 +01:00
|
|
|
--enable=style,information
|
|
|
|
--inconclusive
|
|
|
|
--force
|
2020-11-02 20:16:15 +01:00
|
|
|
--error-exitcode=1
|
2023-03-09 20:04:20 +01:00
|
|
|
--disable=missingInclude
|
2020-11-02 20:16:15 +01:00
|
|
|
--inline-suppr
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/cfg/${CFG_TEST}
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2023-02-24 21:37:56 +01:00
|
|
|
# TODO: glob this
|
|
|
|
add_cfg(boost.cpp)
|
2022-06-02 22:26:01 +02:00
|
|
|
add_cfg(bsd.c)
|
|
|
|
add_cfg(cairo.c)
|
2023-02-24 21:37:56 +01:00
|
|
|
add_cfg(cppunit.cpp)
|
|
|
|
# TODO: posix needs to specified first or it has a different mmap() config
|
|
|
|
# TODO: get rid of posix dependency
|
|
|
|
add_cfg(gnu.c ADD_LIBRARY posix)
|
|
|
|
add_cfg(googletest.cpp)
|
|
|
|
add_cfg(gtk.c)
|
|
|
|
add_cfg(kde.cpp)
|
2022-06-02 22:26:01 +02:00
|
|
|
add_cfg(libcurl.c)
|
|
|
|
add_cfg(libsigc++.cpp)
|
|
|
|
add_cfg(lua.c)
|
|
|
|
add_cfg(opencv2.cpp)
|
|
|
|
add_cfg(openmp.c)
|
|
|
|
add_cfg(openssl.c)
|
|
|
|
add_cfg(posix.c)
|
|
|
|
add_cfg(python.c)
|
2023-02-24 21:37:56 +01:00
|
|
|
add_cfg(qt.cpp)
|
|
|
|
add_cfg(sqlite3.c)
|
|
|
|
add_cfg(std.c)
|
|
|
|
add_cfg(std.cpp)
|
|
|
|
add_cfg(windows.cpp NAME windows32A PLATFORM win32A)
|
|
|
|
add_cfg(windows.cpp NAME windows32W PLATFORM win32W)
|
|
|
|
add_cfg(windows.cpp NAME windows64 PLATFORM win64)
|
|
|
|
add_cfg(wxwidgets.cpp)
|
2020-11-02 20:16:15 +01:00
|
|
|
|
2022-09-24 11:59:13 +02:00
|
|
|
function(fixture_cost NAME COST)
|
|
|
|
if(TEST ${NAME})
|
|
|
|
set_tests_properties(${NAME} PROPERTIES COST ${COST})
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2020-11-02 20:16:15 +01:00
|
|
|
# Set cost of the more expensive tests to help improve parallel scheduling
|
|
|
|
# of tests
|
|
|
|
fixture_cost(TestIO 20)
|
|
|
|
fixture_cost(cfg-std_c 8)
|
|
|
|
fixture_cost(TestThreadExecutor 5)
|
2020-12-31 09:34:53 +01:00
|
|
|
fixture_cost(TestLeakAutoVarRecursiveCountLimit 4)
|
2020-11-02 20:16:15 +01:00
|
|
|
fixture_cost(TestTokenizer 4)
|
|
|
|
endif()
|
2015-02-13 19:00:14 +01:00
|
|
|
endif()
|