diff --git a/CMakeLists.txt b/CMakeLists.txt index 72b0d16..00d6405 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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("$<$:${PROJECT_CXX_FLAGS_COVERAGE}>") -# when -DCMAKE_BUILD_TYPE=coverage, link executables with gcov -link_libraries("$<$: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 diff --git a/README.md b/README.md index 344cead..20bc516 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` diff --git a/cmake/gen-ccov.in b/cmake/gen-ccov.in deleted file mode 100644 index e335aed..0000000 --- a/cmake/gen-ccov.in +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -srcdir=@PROJECT_SOURCE_DIR@ -builddir=@PROJECT_BINARY_DIR@ -lcov=@LCOV_EXECUTABLE@ -genhtml=@GENHTML_EXECUTABLE@ - -if [[ $lcov == "LCOV_EXECUTABLE-NOTFOUND" ]]; then - echo "gen-ccov: lcov executable not found" - exit 1 -fi - -if [[ $genhtml == "GENHTML_EXECUTABLE-NOTFOUND" ]]; then - echo "gen-ccov: genhtml executable not found" - exit 1 -fi - -mkdir $builddir/ccov - -$srcdir/cmake/lcov-harness $srcdir $builddir $builddir/ccov/out $lcov $genhtml diff --git a/cmake/lcov-harness b/cmake/lcov-harness deleted file mode 100755 index 27ac8be..0000000 --- a/cmake/lcov-harness +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env bash - -srcdir=$1 -builddir=$2 -outputstem=$3 -lcov=$4 -genhtml=$5 - -if [[ -z "${srcdir}" ]]; then - echo "lcov-harness: expected non-empty srcdir" - exit 1 -fi - -if [[ -z ${builddir} ]]; then - echo "lcov-harness: expected non-empty builddir" - exit 1 -fi - -if [[ -z ${outputstem} ]]; then - echo "lcov-harness: expected non-empty outputstem" - exit 1 -fi - -if [[ -z ${lcov} ]]; then - echo "lcov-harness: exepcted non-empty lcov" - exit 1 -fi - -if [[ -z ${genhtml} ]]; then - echo "lcov-harness: expected non-empty genhtml" - exit 1 -fi - -# directory stems for location of {.gcda, gcno} coverage information, -# -# if we have source tree: -# -# ${srcdir} -# +- foo -# | \- foo.cpp -# \- bar -# \- quux -# +- quux.cpp -# \- quux_main.cpp -# -# then we expect build tree: -# -# ${builddir} -# +- foo -# | \- CMakeFiles -# | \- foo_target.dir -# | +- foo.cpp.gcda -# | \- foo.cpp.gcno -# +- bar -# \- quux -# \- CMakeFiles -# \- target4quux.dir -# +- quux.cpp.gcda -# +- quux.cpp.gcno -# +- quux_main.cpp.gcda -# \- quux_main.cpp.gcno -# -# in which case will have cmd_body: -# -# ${primarydirs} -# ./foo/CMakeFiles/foo_target.dir -# ./bar/quux/CMakeFiles/target4quux.dir -# -# here foo_target, quux_target are whatever build is using for corresponding cmake target names. -# -# We want to invoke lcov like: -# -# lcov --capture \ -# --output ${builddir}/ccov \ -# --exclude /utest/ \ -# --base-directory ${srcdir}/foo --directory ${builddir}/foo/CMakeFiles/foo_target.dir \ -# --base-directory ${srcdir}/bar/quux --directory ${builddir}/bar/quux/CMakeFiles/target4quux.dir -# -primarydirs=$(cd ${builddir} && find -name '*.gcno' \ - | xargs --replace=xx dirname xx \ - | uniq \ - | sed -e 's:^\./::') - -#echo "primarydirs=${primarydirs}" - -cmd="${lcov} --output ${outputstem}.info --capture --ignore-errors source" - -for bdir in ${primarydirs}; do - sdir=$(dirname $(dirname ${bdir})) - - cmd="${cmd} --base-directory ${srcdir}/${sdir} --directory ${builddir}/${bdir}" -done - -#echo cmd=${cmd} - -set -x - -# capture -${cmd} - -# keep only files with paths under source tree -# (don't want coverage for external libraries such as libstdc++ etc) -${lcov} --extract ${outputstem}.info "${srcdir}/*" --output ${outputstem}2.info - -# remove unit test dirs -# (we're interested in coverage of our installed code, not of the unit tests that exercise it) -${lcov} --remove ${outputstem}2.info '*/utest/*' --output ${outputstem}3.info - -# generate .html tree -mkdir -p ${builddir}/ccov/html -${genhtml} --ignore-errors source --show-details --prefix ${srcdir} --output-directory ${builddir}/ccov/html ${outputstem}3.info - -# also send report to stdout -${lcov} --list ${outputstem}3.info diff --git a/cmake/xo-bootstrap-macros.cmake b/cmake/xo-bootstrap-macros.cmake index 1542d35..b45fa40 100644 --- a/cmake/xo-bootstrap-macros.cmake +++ b/cmake/xo-bootstrap-macros.cmake @@ -9,15 +9,19 @@ # /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, @@ -25,3 +29,5 @@ endif() # #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()