From 323008a1b02366c0282fabd50b0d8ba428059d49 Mon Sep 17 00:00:00 2001 From: Folkert van Heusden Date: Sun, 6 Apr 2025 18:45:50 +0200 Subject: [PATCH] Code-coverage target in cmake. --- CMakeLists.txt | 76 ++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 82a363e..5f04df0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,10 +16,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) include(FindPkgConfig) -if (NOT WIN32) - -add_executable( - kek +set(APP_SOURCES breakpoint.cpp breakpoint_and.cpp breakpoint_memory.cpp @@ -57,58 +54,43 @@ add_executable( utils.cpp ) +if (NOT WIN32) +add_executable( + kek + ${APP_SOURCES} +) + +add_executable( + kek-codecoverage + ${APP_SOURCES} +) + +target_compile_options(kek-codecoverage PRIVATE -fprofile-arcs -ftest-coverage) +target_link_options(kek-codecoverage PRIVATE -fprofile-arcs -ftest-coverage) + pkg_check_modules(NCURSES REQUIRED ncurses) target_link_libraries(kek ${NCURSES_LIBRARIES}) target_include_directories(kek PUBLIC ${NCURSES_INCLUDE_DIRS}) target_compile_options(kek PUBLIC ${NCURSES_CFLAGS_OTHER}) +target_link_libraries(kek-codecoverage ${NCURSES_LIBRARIES}) +target_include_directories(kek-codecoverage PUBLIC ${NCURSES_INCLUDE_DIRS}) +target_compile_options(kek-codecoverage PUBLIC ${NCURSES_CFLAGS_OTHER}) pkg_check_modules(PANEL REQUIRED panel) target_link_libraries(kek ${PANEL_LIBRARIES}) target_include_directories(kek PUBLIC ${PANEL_INCLUDE_DIRS}) target_compile_options(kek PUBLIC ${PANEL_CFLAGS_OTHER}) - +target_link_libraries(kek-codecoverage ${PANEL_LIBRARIES}) +target_include_directories(kek-codecoverage PUBLIC ${PANEL_INCLUDE_DIRS}) +target_compile_options(kek-codecoverage PUBLIC ${PANEL_CFLAGS_OTHER}) endif (NOT WIN32) if (WIN32) - add_executable( kek-win32 - breakpoint.cpp - breakpoint_and.cpp - breakpoint_memory.cpp - breakpoint_or.cpp - breakpoint_parser.cpp - breakpoint_register.cpp - bus.cpp - comm.cpp - comm_posix_tty.cpp - comm_tcp_socket_client.cpp - comm_tcp_socket_server.cpp - console.cpp - console_posix.cpp - cpu.cpp - dc11.cpp - debugger.cpp - device.cpp - disk_backend.cpp - disk_backend_file.cpp - disk_backend_nbd.cpp - error.cpp - kw11-l.cpp - loaders.cpp - log.cpp - main.cpp - memory.cpp - mmu.cpp - rk05.cpp - rl02.cpp - rp06.cpp - tm-11.cpp - tty.cpp - utils.cpp + ${APP_SOURCES} win32.cpp ) - endif (WIN32) include(CheckIPOSupported) @@ -124,6 +106,7 @@ set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) if (NOT WIN32) target_link_libraries(kek Threads::Threads) +target_link_libraries(kek-codecoverage Threads::Threads) else () target_link_libraries(kek-win32 Threads::Threads) @@ -132,7 +115,20 @@ endif () add_subdirectory(arduinojson) target_link_libraries(kek ArduinoJson) +target_link_libraries(kek-codecoverage ArduinoJson) if (WIN32) target_link_libraries(kek-win32 ArduinoJson) endif () + +add_custom_target(coverage + COMMAND ${CMAKE_COMMAND} -E remove_directory coverage + COMMAND ${CMAKE_COMMAND} -E make_directory coverage + COMMAND lcov --capture --directory . --output-file coverage.info + COMMAND genhtml coverage.info --output-directory coverage + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} +) +add_custom_target(coverage_reset + COMMAND lcov --directory . --zerocounters + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} +)