From 77902ad892f8d2901be7e624d335819501d9abb8 Mon Sep 17 00:00:00 2001 From: Olivier BICHLER <olivier.bichler@cea.fr> Date: Mon, 4 Sep 2023 14:48:03 +0200 Subject: [PATCH] Added missing coverage in CMake --- .gitlab/ci/build.gitlab-ci.yml | 2 +- CMakeLists.txt | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.gitlab/ci/build.gitlab-ci.yml b/.gitlab/ci/build.gitlab-ci.yml index b98ef919..d274189c 100644 --- a/.gitlab/ci/build.gitlab-ci.yml +++ b/.gitlab/ci/build.gitlab-ci.yml @@ -14,7 +14,7 @@ build:ubuntu_cpp: - export CMAKE_PREFIX_PATH=../install_cpp - mkdir -p build_cpp - cd build_cpp - - cmake -DCMAKE_INSTALL_PREFIX:PATH=../install_cpp -DCMAKE_BUILD_TYPE=Debug -DWERROR=ON .. + - cmake -DCMAKE_INSTALL_PREFIX:PATH=../install_cpp -DCMAKE_BUILD_TYPE=Debug -DWERROR=ON -DCOVERAGE=ON .. - make -j4 all install artifacts: diff --git a/CMakeLists.txt b/CMakeLists.txt index d973a04e..2ee0634f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,17 @@ include(PybindModuleCreation) # Define options option(PYBIND "python binding" ON) option(WERROR "Warning as error" OFF) +option(TEST "Enable tests" ON) +option(COVERAGE "Enable coverage" OFF) + +############################################## +# Import utils CMakeLists +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") +include(PybindModuleCreation) + +if(CMAKE_COMPILER_IS_GNUCXX AND COVERAGE) + Include(CodeCoverage) +endif() ############################################## # Find system dependencies @@ -79,6 +90,10 @@ else() /W4>) endif() +if(CMAKE_COMPILER_IS_GNUCXX AND COVERAGE) + append_coverage_compiler_flags() +endif() + ############################################## # Installation instructions @@ -129,6 +144,7 @@ export(EXPORT ${project}-targets ############################################## ## Add test -enable_testing() -add_subdirectory(unit_tests) - +if(TEST) + enable_testing() + add_subdirectory(unit_tests) +endif() -- GitLab