Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linkage of gtest for unit tests #52

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)
Loading