From 56c46490b82013a98b112bbf4f862ee151ca80db Mon Sep 17 00:00:00 2001 From: Gianfranco Berardi <54074967+gberardi-pillar@users.noreply.github.com> Date: Wed, 3 Jan 2024 14:01:12 -0600 Subject: [PATCH 1/3] Make test target name unique. Signed-off-by: Gianfranco Berardi <54074967+gberardi-pillar@users.noreply.github.com> --- CMakeLists.txt | 3 ++- README.md | 5 ++--- tests/CMakeLists.txt | 15 +++++++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ce4593..e61f424 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,8 @@ if (EVSE_SECURITY_INSTALL) ) endif() -if(BUILD_TESTING_EVSE_SECURITY) +if(BUILD_TESTING) + include(CTest) add_subdirectory(tests) set(CMAKE_BUILD_TYPE Debug) endif() diff --git a/README.md b/README.md index ef8aca6..1ae0c0e 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,7 @@ GTest is required for building the test cases target. To build the target and ru ```bash mkdir build && cd build -cmake -DBUILD_TESTING_EVSE_SECURITY=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=./dist .. +cmake -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=./dist .. make -j$(nproc) install -cd tests -./tests +make test ``` diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b057386..5faf998 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,10 +1,17 @@ -add_executable(tests tests.cpp) -target_include_directories(tests PUBLIC ${GTEST_INCLUDE_DIRS}) + +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 +) find_package(GTest REQUIRED) -target_link_libraries(tests PRIVATE +target_link_libraries(${TEST_TARGET_NAME} PRIVATE evse_security ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} @@ -14,7 +21,7 @@ if(LIBEVSE_CRYPTO_SUPPLIER_OPENSSL) add_compile_definitions(LIBEVSE_CRYPTO_SUPPLIER_OPENSSL) endif() -add_test(tests tests) +add_test(${TEST_TARGET_NAME} ${TEST_TARGET_NAME}) install( PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/generate_test_certs.sh" From cbdaf388628cf7d4398ab47158695cc9d3a98720 Mon Sep 17 00:00:00 2001 From: Gianfranco Berardi <54074967+gberardi-pillar@users.noreply.github.com> Date: Fri, 5 Jan 2024 14:04:44 -0600 Subject: [PATCH 2/3] Run tests only if current project or explicitly specified. Signed-off-by: Gianfranco Berardi <54074967+gberardi-pillar@users.noreply.github.com> --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e61f424..5cae08d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ if (EVSE_SECURITY_INSTALL) ) endif() -if(BUILD_TESTING) +if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING) include(CTest) add_subdirectory(tests) set(CMAKE_BUILD_TYPE Debug) From 41401db2b5130f413ad9b18615b2c66d8e566858 Mon Sep 17 00:00:00 2001 From: Gianfranco Berardi <54074967+gberardi-pillar@users.noreply.github.com> Date: Mon, 5 Feb 2024 15:59:16 -0600 Subject: [PATCH 3/3] Review fixes. Signed-off-by: Gianfranco Berardi <54074967+gberardi-pillar@users.noreply.github.com> --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cae08d..8fa30b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,8 @@ find_package(everest-cmake 0.1 REQUIRED ) # options +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) option(EVSE_SECURITY_INSTALL "Install the library (shared data might be installed anyway)" ${EVC_MAIN_PROJECT}) # dependencies @@ -53,7 +55,7 @@ if (EVSE_SECURITY_INSTALL) ) endif() -if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING) +if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING) include(CTest) add_subdirectory(tests) set(CMAKE_BUILD_TYPE Debug)