Skip to content

Commit

Permalink
feature: target register functionality and coverage
Browse files Browse the repository at this point in the history
- added two cmake functions `ev_register_library_target` and
  `ev_register_module_target` for registering modules and libraries
- all modules and libraries that are registered via those functions can
  be retrieved with `ev_get_targets`
- this functionality is used for adding target specific coverage flags
  (but it can also be used to add other target specific compile options
  and flags)

Signed-off-by: aw <[email protected]>
  • Loading branch information
a-w50 committed Jan 15, 2025
1 parent 3401718 commit e4924b3
Show file tree
Hide file tree
Showing 23 changed files with 104 additions and 18 deletions.
19 changes: 2 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ if(EVEREST_CORE_BUILD_TESTING)
include(CTest)

set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)

evc_include(CodeCoverage)

append_coverage_compiler_flags()
endif()

include(ev-define-dependency)
Expand Down Expand Up @@ -115,7 +111,6 @@ else()
find_package(ryml REQUIRED)
endif()

add_subdirectory(lib)

include(ev-project-bootstrap)

Expand All @@ -126,6 +121,8 @@ if (ISO15118_2_GENERATE_AND_INSTALL_CERTIFICATES)
file(TOUCH config/certs/ca/mf/MF_ROOT_CA.pem)
endif()

add_subdirectory(lib)

# config
# FIXME (aw): this should be optional
add_subdirectory(config)
Expand All @@ -148,18 +145,6 @@ endif()
# testing
if(EVEREST_CORE_BUILD_TESTING)
add_subdirectory(tests)

setup_target_for_coverage_gcovr_html(
NAME ${PROJECT_NAME}_gcovr_coverage
EXECUTABLE test_config
DEPENDENCIES test_config everest
)

setup_target_for_coverage_lcov(
NAME ${PROJECT_NAME}_lcov_coverage
EXECUTABLE test_config
DEPENDENCIES test_config everest
)
else()
message("Not running unit tests")
endif()
Expand Down
1 change: 1 addition & 0 deletions cmake/ev-project-bootstrap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ include(${CMAKE_CURRENT_LIST_DIR}/config-run-script.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/config-run-nodered-script.cmake)

# source generate scripts / setup
include(${CMAKE_CURRENT_LIST_DIR}/ev-targets.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/everest-generate.cmake)
38 changes: 38 additions & 0 deletions cmake/ev-targets.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
include_guard(GLOBAL)

add_custom_target(everest_targets)

set_target_properties(everest_targets
PROPERTIES
LIBRARIES ""
MODULES ""
)

function(_ev_register_target TYPE NAME)
if (NOT TARGET ${NAME})
message(FATAL_ERROR "The supplied name ${NAME} of type ${TYPE} is not a valid target")
endif()

set_property(
TARGET everest_targets
APPEND
PROPERTY ${TYPE} ${NAME}
)
endfunction()

function(ev_register_library_target NAME)
_ev_register_target(LIBRARIES ${NAME})
endfunction()

function(ev_register_module_target NAME)
_ev_register_target(MODULES ${NAME})
endfunction()

function(ev_get_targets NAME TYPE)
get_target_property(tmp everest_targets ${TYPE})
if (NOT tmp STREQUAL "" AND NOT tmp)
message(FATAL_ERROR "There is no target of type ${TYPE} defined")
endif()

set(${NAME} ${tmp} PARENT_SCOPE)
endfunction()
2 changes: 2 additions & 0 deletions cmake/everest-generate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ function (ev_add_cpp_module MODULE_NAME)

add_dependencies(${MODULE_NAME} generate_cpp_files)

ev_register_module_target(${MODULE_NAME})

install(TARGETS ${MODULE_NAME}
DESTINATION "${EVEREST_MODULE_INSTALL_PREFIX}/${MODULE_NAME}"
)
Expand Down
2 changes: 2 additions & 0 deletions lib/staging/can_dpm1000/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ target_sources(can_dpm1000
src/dpm1000.cpp
)

ev_register_library_target(can_dpm1000)

if(BUILD_DEV_TESTS)
add_subdirectory(tests)
endif()
2 changes: 2 additions & 0 deletions lib/staging/evse_security/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ target_link_libraries(evse_security_conversions
everest::evse_security
everest::framework
)

ev_register_library_target(evse_security_conversions)
4 changes: 3 additions & 1 deletion lib/staging/external_energy_limits/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ add_dependencies(external_energy_limits generate_cpp_files)
target_link_libraries(external_energy_limits
PRIVATE
everest::framework
)
)

ev_register_library_target(external_energy_limits)
2 changes: 2 additions & 0 deletions lib/staging/gpio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ target_link_libraries(gpio
PRIVATE
)

ev_register_library_target(gpio)

2 changes: 2 additions & 0 deletions lib/staging/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ target_link_libraries(everest_staging_helpers

add_dependencies(everest_staging_helpers generate_cpp_files)

ev_register_library_target(everest_staging_helpers)

if (BUILD_TESTING)
add_subdirectory(tests)
endif()
4 changes: 4 additions & 0 deletions lib/staging/ocpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ target_link_libraries(ocpp_evse_security
everest::framework
)

ev_register_library_target(ocpp_evse_security)


# OCPP conversions

Expand Down Expand Up @@ -59,3 +61,5 @@ target_link_libraries(ocpp_conversions
everest::framework
)

ev_register_library_target(ocpp_conversions)

2 changes: 2 additions & 0 deletions lib/staging/slac/fsm/ev/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ target_link_libraries(slac_fsm_ev
slac::slac
fsm::fsm
)

ev_register_library_target(slac_fsm_ev)
2 changes: 2 additions & 0 deletions lib/staging/slac/fsm/evse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ target_link_libraries(slac_fsm_evse
slac::slac
fsm::fsm
)

ev_register_library_target(slac_fsm_evse)
2 changes: 2 additions & 0 deletions lib/staging/slac/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ target_link_libraries(slac_io
PUBLIC
slac::slac
)

ev_register_library_target(slac_io)
2 changes: 2 additions & 0 deletions lib/staging/tls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ target_link_libraries(tls
if(EVEREST_CORE_BUILD_TESTING)
add_subdirectory(tests)
endif()

ev_register_library_target(tls)
2 changes: 2 additions & 0 deletions lib/staging/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ target_include_directories(everest_staging_util
if (BUILD_TESTING)
add_subdirectory(tests)
endif()

ev_register_library_target(everest_staging_helpers)
2 changes: 2 additions & 0 deletions modules/Auth/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ if(EVEREST_ENABLE_COMPILE_WARNINGS)
PRIVATE ${EVEREST_COMPILE_OPTIONS}
)
endif()

ev_register_library_target(auth_handler)
2 changes: 2 additions & 0 deletions modules/MicroMegaWattBSP/umwc_comms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ target_link_libraries(umwc_comms
everest::framework
everest::gpio
)

ev_register_library_target(umwc_comms)
2 changes: 2 additions & 0 deletions modules/PN532TokenProvider/pn532_serial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ add_library(pn532_serial STATIC PN532Serial.cpp)

target_include_directories(pn532_serial PUBLIC "${PROJECT_BINARY_DIR}")
target_link_libraries(pn532_serial PRIVATE Threads::Threads everest::framework)

ev_register_library_target(pn532_serial)
2 changes: 2 additions & 0 deletions modules/PhyVersoBSP/phyverso_gpio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ target_link_libraries(phyverso_gpio
phyverso_config
fmt::fmt
)

ev_register_library_target(phyverso_gpio)
4 changes: 4 additions & 0 deletions modules/PhyVersoBSP/phyverso_mcu_comms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ target_link_libraries(phyverso_config
fmt::fmt
)

ev_register_library_target(phyverso_config)

add_library(phyverso_mcu_comms STATIC)
target_sources(phyverso_mcu_comms
PRIVATE
Expand All @@ -49,3 +51,5 @@ target_link_libraries(phyverso_mcu_comms
everest::framework
phyverso_config
)

ev_register_library_target(phyverso_mcu_comms)
2 changes: 2 additions & 0 deletions modules/YetiDriver/yeti_comms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ target_link_libraries(yeti_comms
everest::framework
everest::gpio
)

ev_register_library_target(yeti_comms)
2 changes: 2 additions & 0 deletions modules/YetiEvDriver/evyeti_comms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ target_link_libraries(evyeti_comms
Pal::Sigslot
everest::framework
)

ev_register_library_target(evyeti_comms)
20 changes: 20 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# enabling coverage related things

evc_include(CodeCoverage)

# add compiler flags to all targets which should be coveraged

foreach(type MODULES LIBRARIES)
ev_get_targets(targets ${type})

foreach(target ${targets})
append_coverage_compiler_flags_to_target(${target})
endforeach()
endforeach()

get_target_property(GENERATED_OUTPUT_DIR generate_cpp_files EVEREST_GENERATED_OUTPUT_DIR)
setup_target_for_coverage_gcovr_html(
NAME ${PROJECT_NAME}_gcovr_coverage
EXCLUDE "${GENERATED_OUTPUT_DIR}/*"
)

add_subdirectory(everest-core_tests)

0 comments on commit e4924b3

Please sign in to comment.