Skip to content

Commit

Permalink
Fix linkage of gtest for unit tests (#52)
Browse files Browse the repository at this point in the history
* Build unit tests and their dependencies conditionally

This follows the established best practices from everest.github.io

* Fix gtest dependency linkage
* Remove unnecessary find_package(date)
* Bump version to 0.4.3

---------

Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass authored Feb 23, 2024
1 parent 34a7683 commit 703018b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14)

project(everest-evse_security VERSION 0.4.2
project(everest-evse_security VERSION 0.4.3
DESCRIPTION "Implementation of EVSE related security operations"
LANGUAGES CXX C
)
Expand All @@ -15,6 +15,10 @@ option(BUILD_TESTING "Build unit tests, used if standalone project" OFF)
option(EVSE_SECURITY_INSTALL "Install the library (shared data might be installed anyway)" ${EVC_MAIN_PROJECT})
option(USING_TPM2 "Include code for using OpenSSL 3 and the tpm2 provider" OFF)

if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING)
set(LIBEVSE_SECURITY_BUILD_TESTING ON)
endif()

if(USING_TPM2)
# OpenSSL property string when using the default provider
set(PROPQUERY_DEFAULT "provider!=tpm2")
Expand All @@ -39,7 +43,6 @@ option(LIBEVSE_CRYPTO_SUPPLIER_OPENSSL "Default OpenSSL cryptography supplier" O

# dependencies
find_package(OpenSSL REQUIRED)
find_package(date)

add_subdirectory(lib)

Expand All @@ -66,7 +69,7 @@ if (EVSE_SECURITY_INSTALL)
)
endif()

if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING)
if(LIBEVSE_SECURITY_BUILD_TESTING)
include(CTest)
add_subdirectory(tests)
set(CMAKE_BUILD_TYPE Debug)
Expand Down
2 changes: 1 addition & 1 deletion dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ 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: "BUILD_TESTING OR BUILD_TESTING_EVSE_SECURITY"
cmake_condition: "LIBEVSE_SECURITY_BUILD_TESTING"
8 changes: 2 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
set(TEST_TARGET_NAME ${PROJECT_NAME}_tests)
add_executable(${TEST_TARGET_NAME})

target_include_directories(${TEST_TARGET_NAME} PUBLIC ${GTEST_INCLUDE_DIRS})

target_sources(${TEST_TARGET_NAME} PRIVATE
tests.cpp
openssl_supplier_test.cpp
)

find_package(GTest REQUIRED)
find_package(OpenSSL REQUIRED)

target_link_libraries(${TEST_TARGET_NAME} PRIVATE
evse_security
${GTEST_LIBRARIES}
${GTEST_MAIN_LIBRARIES}
GTest::gtest_main
)

if(USING_TPM2)
Expand Down Expand Up @@ -73,4 +69,4 @@ install(
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/openssl-pki.conf"
DESTINATION "${CMAKE_BINARY_DIR}/tests"
)
)

0 comments on commit 703018b

Please sign in to comment.