Skip to content

Commit

Permalink
xo-flatstring: build: use streamlined coverage generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rconybea committed Apr 25, 2024
1 parent bd6fa8d commit 39cedaa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 170 deletions.
38 changes: 7 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,49 +1,25 @@
# xo-stringliteral/CMakeLists.txt
# xo-flatstring/CMakeLists.txt

cmake_minimum_required(VERSION 3.25)

project(xo_flatstring VERSION 1.0)
enable_language(CXX)
#enable_language(CXX)

# common XO cmake macros (see proj/xo-cmake)
include(GNUInstallDirs)
include(cmake/xo-bootstrap-macros.cmake)

# ----------------------------------------------------------------
# unit test setup
xo_cxx_toplevel_options2()

# ----------------------------------------------------------------
# unit test + coverage setup
#
enable_testing()

# ----------------------------------------------------------------
# cmake -DCMAKE_BUILD_TYPE=coverage

if (NOT DEFINED PROJECT_CXX_FLAGS_COVERAGE)
# note: for clang would use -fprofile-instr-generate -fcoverage-mapping here instead and also at link time
set(PROJECT_CXX_FLAGS_COVERAGE ${PROJECT_CXX_FLAGS} -ggdb -Og -fprofile-arcs -ftest-coverage
CACHE STRING "coverage c++ compiler flags")
endif()
message("-- PROJECT_CXX_FLAGS_COVERAGE: coverage c++ flags are [${PROJECT_CXX_FLAGS_COVERAGE}]")

add_compile_options("$<$<CONFIG:COVERAGE>:${PROJECT_CXX_FLAGS_COVERAGE}>")
# when -DCMAKE_BUILD_TYPE=coverage, link executables with gcov
link_libraries("$<$<CONFIG:COVERAGE>:gcov>")

find_program(LCOV_EXECUTABLE NAMES lcov)
find_program(GENHTML_EXECUTABLE NAMES genhtml)

# with coverage build:
# 1. invoke instrumented executables for which you want coverage:
# (cd path/to/build && ctest)
# 2. post-process low-level coverage data
# (path/to/build/gen-ccov)
# 3. point browser to generated html data
# file:///path/to/build/ccov/html/index.html
#
configure_file(
${PROJECT_SOURCE_DIR}/cmake/gen-ccov.in
${PROJECT_BINARY_DIR}/gen-ccov)

file(CHMOD ${PROJECT_BINARY_DIR}/gen-ccov PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
xo_toplevel_coverage_config2()

# ----------------------------------------------------------------
# c++ settings
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ $ cmake --install .build
$ cd xo-flatstring
$ cmake --build .build -- docs
```

Must invoke `docs` target explicitly to prepare documentation
When complete, point local browser to `xo-flatstring/.build/docs/sphinx/index.html`

### build with test coverage
Expand All @@ -70,7 +72,12 @@ generate html+text coverage report
$ cmake --build .build-ccov -- ccov
```

browse to `.build-ccov/ccov/html/index.html`
For html test coverage browse to `.build-ccov/ccov/html/index.html`

install documentation only, along with test-coverage report
```
$ cmake --install .build-ccov --component Documentation
```

### LSP support
```
Expand Down
20 changes: 0 additions & 20 deletions cmake/gen-ccov.in

This file was deleted.

114 changes: 0 additions & 114 deletions cmake/lcov-harness

This file was deleted.

14 changes: 10 additions & 4 deletions cmake/xo-bootstrap-macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@
# /usr/local/share/cmake/xo_macros/xo-project-macros.cmake
# ----------------------------------------------------------------

find_program(XO_CMAKE_CONFIG_EXECUTABLE NAMES xo-cmake-config REQUIRED)

if ("${XO_CMAKE_CONFIG_EXECUTABLE}" STREQUAL "XO_CMAKE_CONFIG_EXECUTABLE-NOT_FOUND")
message(FATAL "could not find xo-cmake-config executable")
endif()

if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL prefix))
# default to typical install location for xo-project-macros
set(CMAKE_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/share/cmake)
execute_process(COMMAND ${XO_CMAKE_CONFIG_EXECUTABLE} --cmake-module-path OUTPUT_VARIABLE CMAKE_MODULE_PATH)
endif()

if (NOT XO_SUBMODULE_BUILD)
message("-- GUESSED_CMAKE_CMD=cmake -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DCMAKE_MODULE_PATH=${CMAKE_MODULE_PATH} -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_DOCDIR=${CMAKE_INSTALL_DOCDIR} -B ${CMAKE_BINARY_DIR}")
message("-- CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")
message("-- CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")
message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")
endif()

# needs to have been installed somewhere on CMAKE_MODULE_PATH,
# (e.g. from xo-cmake with the same value for CMAKE_INSTALL_PREFIX)
#
#include(xo_macros/xo-project-macros)
include(xo_macros/xo_cxx) # not using v1 code-coverage; testing cmake-examples impl instead

xo_cxx_bootstrap_message()

0 comments on commit 39cedaa

Please sign in to comment.