Skip to content

Commit

Permalink
Make gtest source dependency conditional on building testing
Browse files Browse the repository at this point in the history
Properly check if Auth unit tests are supposed to be build

Fix linkage of gtest

Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass committed Feb 22, 2024
1 parent 6064b26 commit b129c99
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion modules/Auth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions modules/Auth/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b129c99

Please sign in to comment.