From b129c99f4a492d392a97cf4671418b3dc97e26b1 Mon Sep 17 00:00:00 2001 From: Kai-Uwe Hermann Date: Thu, 22 Feb 2024 20:29:32 +0100 Subject: [PATCH] Make gtest source dependency conditional on building testing Properly check if Auth unit tests are supposed to be build Fix linkage of gtest Signed-off-by: Kai-Uwe Hermann --- CMakeLists.txt | 5 ++++- dependencies.yaml | 8 +++++++- modules/Auth/CMakeLists.txt | 2 +- modules/Auth/tests/CMakeLists.txt | 6 +----- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a85bcf930..5ee4c37b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,9 @@ option(ISO15118_2_GENERATE_AND_INSTALL_CERTIFICATES "Automatically generate and option(EVEREST_ENABLE_RUN_SCRIPT_GENERATION "Enables the generation of run scripts (convenience scripts for starting available configurations)" ON) 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(EVEREST_CORE_BUILD_TESTING ON) +endif() # This is a flag for building development tests, but not necessarily to run them, for expample in case # tests requires hardware. option(BUILD_DEV_TESTS "Build dev tests" OFF) @@ -121,7 +124,7 @@ if(DOXYGEN_FOUND) endif() # testing -if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING) +if(EVEREST_CORE_BUILD_TESTING) include(CTest) enable_testing() set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE) diff --git a/dependencies.yaml b/dependencies.yaml index 9d7c2720c..a8a53a076 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -74,10 +74,16 @@ ext-mbedtls: everest-utils: git: https://github.com/EVerest/everest-utils.git git_tag: v0.2.0 - cmake_condition: "BUILD_TESTING" + cmake_condition: "EVEREST_CORE_BUILD_TESTING" # evse-security, since this is a direct dependency of libocpp it will get overwritten by the version set there # setting it here can be misleading since it does not affect the version being used libevse-security: git: https://github.com/EVerest/libevse-security.git git_tag: 69410a8 cmake_condition: "EVEREST_DEPENDENCY_ENABLED_LIBEVSE_SECURITY" +# unit testing +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: "EVEREST_CORE_BUILD_TESTING" diff --git a/modules/Auth/CMakeLists.txt b/modules/Auth/CMakeLists.txt index 3f02d1298..e58ba83e7 100644 --- a/modules/Auth/CMakeLists.txt +++ b/modules/Auth/CMakeLists.txt @@ -32,7 +32,7 @@ target_sources(${MODULE_NAME} # ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1 # insert other things like install cmds etc here -if(BUILD_TESTING) +if(EVEREST_CORE_BUILD_TESTING) add_subdirectory(tests) endif() # ev@c55432ab-152c-45a9-9d2e-7281d50c69c3:v1 diff --git a/modules/Auth/tests/CMakeLists.txt b/modules/Auth/tests/CMakeLists.txt index d6581c16d..83f4b32a2 100644 --- a/modules/Auth/tests/CMakeLists.txt +++ b/modules/Auth/tests/CMakeLists.txt @@ -8,17 +8,13 @@ set(INCLUDE_DIR get_target_property(GENERATED_INCLUDE_DIR generate_cpp_files EVEREST_GENERATED_INCLUDE_DIR) target_include_directories(auth_tests PUBLIC - ${GTEST_INCLUDE_DIRS} ${INCLUDE_DIR} ${GENERATED_INCLUDE_DIR} ) -find_package(GTest REQUIRED) - target_link_libraries(auth_tests PRIVATE - ${GTEST_LIBRARIES} - ${GTEST_MAIN_LIBRARIES} GTest::gmock + GTest::gtest_main everest::timer ${CMAKE_DL_LIBS} everest::log