From 9e414f3825dfb9d8772ea055b01a053d188d3c65 Mon Sep 17 00:00:00 2001 From: Kai Hermann Date: Fri, 23 Feb 2024 12:08:11 +0100 Subject: [PATCH] Unit testing best practices (#18) * Use cmake_condition for gtest * Update liblog dependency * Bump version to 0.3.1 --------- Signed-off-by: Kai-Uwe Hermann --- CMakeLists.txt | 10 ++++++---- dependencies.yaml | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06b516a..0991b61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.11) project(modbus - VERSION 0.3 + VERSION 0.3.1 ) find_package(everest-cmake 0.1 REQUIRED @@ -13,7 +13,9 @@ option(BUILD_EXAMPLES "Build example programs" OFF) option(MODBUS_INSTALL "Install the library (shared data might be installed anyway)" ${EVC_MAIN_PROJECT}) option(${PROJECT_NAME}_BUILD_TESTING "Build unit tests, used if included as dependency" OFF) option(BUILD_TESTING "Build unit tests, used if standalone project" OFF) - +if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING) + set(LIBMODBUS_BUILD_TESTING ON) +endif() # dependencies if (NOT DISABLE_EDM) evc_setup_edm() @@ -23,7 +25,7 @@ if (NOT DISABLE_EDM) else() find_package(everest-log REQUIRED) - if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING) + if(LIBMODBUS_BUILD_TESTING) find_package(GTest REQUIRED) endif() endif() @@ -79,7 +81,7 @@ if (BUILD_EXAMPLES) add_subdirectory(${PROJECT_SOURCE_DIR}/lib/connection/examples) endif() -if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING) +if(LIBMODBUS_BUILD_TESTING) include(CTest) enable_testing() add_subdirectory(${PROJECT_SOURCE_DIR}/tests) diff --git a/dependencies.yaml b/dependencies.yaml index 11b2fbc..369210d 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -1,10 +1,11 @@ --- liblog: git: https://github.com/EVerest/liblog.git - git_tag: v0.1.0 + git_tag: v0.2.1 options: ["BUILD_EXAMPLES OFF"] gtest: # GoogleTest now follows the Abseil Live at Head philosophy. We recommend updating to the latest commit in the main branch as often as possible. git: https://github.com/google/googletest.git git_tag: release-1.12.1 + cmake_condition: "LIBMODBUS_BUILD_TESTING"