Skip to content

Commit

Permalink
Use as prefix and adapt test target names
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Heinrich <[email protected]>
  • Loading branch information
andistorm committed Feb 5, 2024
1 parent 1dcc00e commit ba76ca1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ find_package(everest-cmake 0.1 REQUIRED
)

# options
option(LIBOCPP_BUILD_TESTING "Run unit tests" OFF)
option(CMAKE_RUN_CLANG_TIDY "Run clang-tidy" OFF)
option(LIBOCPP_BUILD_EXAMPLES "Build charge_point and central_system binaries." OFF)
option(LIBOCPP_INSTALL "Install the library (shared data might be installed anyway)" ${EVC_MAIN_PROJECT})
option(${PROJECT_NAME}_BUILD_EXAMPLES "Build charge_point and central_system binaries." OFF)
option(${PROJECT_NAME}_INSTALL "Install the library (shared data might be installed anyway)" ${EVC_MAIN_PROJECT})
option(${PROJECT_NAME}_BUILD_TESTING "Build unit tests, used if included as dependency" ON)
option(BUILD_TESTING "Build unit tests, used if standalone project" ON)

# dependencies
find_package(Boost COMPONENTS program_options regex system thread REQUIRED)
Expand All @@ -25,7 +26,7 @@ if(NOT DISABLE_EDM)
evc_setup_edm()

# In EDM mode, we can't install exports (because the dependencies usually do not install their exports)
set(LIBOCPP_INSTALL OFF)
set(${PROJECT_NAME}_INSTALL OFF)

# FIXME (aw): websocketpp doesn't play well with EDM/CPM
add_library(websocketpp::websocketpp INTERFACE IMPORTED)
Expand All @@ -51,7 +52,7 @@ add_subdirectory(config)


# packaging
if (LIBOCPP_INSTALL)
if (${PROJECT_NAME}_INSTALL)
install(
TARGETS ocpp
EXPORT ocpp-targets
Expand Down Expand Up @@ -103,7 +104,7 @@ if(CMAKE_RUN_CLANG_TIDY)
-export-fixes=clang-tidy-fixes.yaml)
endif()

if(BUILD_TESTING_LIBOCPP)
if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING)
add_subdirectory(tests)
endif()

Expand Down
28 changes: 14 additions & 14 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
add_definitions(-D_SQL_INIT_FILE="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP/init.sql")
add_executable(database_tests database_tests.cpp)
add_executable(${PROJECT_NAME}_database_tests database_tests.cpp)

target_include_directories(database_tests PUBLIC ${GTEST_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME}_database_tests PUBLIC ${GTEST_INCLUDE_DIRS})

find_package(GTest REQUIRED)

target_link_libraries(database_tests PRIVATE
target_link_libraries(${PROJECT_NAME}_database_tests PRIVATE
ocpp
date::date
nlohmann_json::nlohmann_json
Expand All @@ -16,40 +16,40 @@ target_link_libraries(database_tests PRIVATE
)


add_test(database_tests database_tests)
add_test(${PROJECT_NAME}_database_tests ${PROJECT_NAME}_database_tests)

add_executable(libocpp_unit_tests
add_executable(${PROJECT_NAME}_unit_tests
lib/ocpp/v201/test_component_state_manager.cpp)

add_custom_command(TARGET libocpp_unit_tests POST_BUILD
add_custom_command(TARGET ${PROJECT_NAME}__unit_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/unittest_device_model.db ${CMAKE_CURRENT_BINARY_DIR}/resources/unittest_device_model.db
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/unittest_device_model_missing_required.db ${CMAKE_CURRENT_BINARY_DIR}/resources/unittest_device_model_missing_required.db
)

add_test(libocpp_unit_tests libocpp_unit_tests)
add_test(${PROJECT_NAME}_unit_tests ${PROJECT_NAME}_unit_tests)

target_include_directories(libocpp_unit_tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${GTEST_INCLUDE_DIRS})
target_link_libraries(libocpp_unit_tests PRIVATE
target_include_directories(${PROJECT_NAME}_unit_tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${GTEST_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}_unit_tests PRIVATE
ocpp
GTest::gmock_main
${GTEST_LIBRARIES}
${GTEST_MAIN_LIBRARIES}
)
target_sources(libocpp_unit_tests PRIVATE
target_sources(${PROJECT_NAME}_unit_tests PRIVATE
comparators.cpp)

add_subdirectory(lib/ocpp/v201)
add_subdirectory(lib/ocpp/common)


add_executable(utils_tests utils_tests.cpp)
add_executable(${PROJECT_NAME}_utils_tests utils_tests.cpp)

target_include_directories(utils_tests PUBLIC ${GTEST_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME}_utils_tests PUBLIC ${GTEST_INCLUDE_DIRS})

target_link_libraries(utils_tests PRIVATE
target_link_libraries(${PROJECT_NAME}_utils_tests PRIVATE
ocpp
${GTEST_LIBRARIES}
${GTEST_MAIN_LIBRARIES}
)

add_test(utils_tests utils_tests)
add_test(${PROJECT_NAME}_utils_tests ${PROJECT_NAME}_utils_tests)

0 comments on commit ba76ca1

Please sign in to comment.