Skip to content

Commit

Permalink
Add an example on how to build libocpp with FetchContent instead of EDM
Browse files Browse the repository at this point in the history
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
  • Loading branch information
hikinggrass committed Aug 21, 2023
1 parent 76f5741 commit adca4bb
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*vscode
workspace.yaml
CMakeLists.txt.user
!doc/build-with-fetchcontent
50 changes: 28 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@ Libocpp can be used for the communication of one charging station and multiple E
Libocpp provides a complete implementation of OCPP 1.6. The implementation of OCPP 2.0.1 is currently under development.

## Table of contents
- [Feature Support](#feature-support)
- [Feature Profile Support OCPP 1.6](#feature-profile-support-ocpp-16)
- [Support for OCPP 2.0.1](#support-for-ocpp-201)
- [CSMS Compatibility](#csms-compatibility)
- [CSMS Compatibility OCPP 1.6](#csms-compatibility-ocpp-16)
- [CSMS Compatibility OCPP 2.0.1](#csms-compatibility-ocpp-201)
- [Integration with EVerest](#integration-with-everest)
- [Run OCPP1.6 with EVerest](#run-ocpp16-with-everest)
- [Run OCPP2.0.1 with EVerest](#run-ocpp201-with-everest)
- [Integrate this library with your Charging Station Implementation for OCPP1.6](#integrate-this-library-with-your-charging-station-implementation-for-ocpp16)
- [Overview of the required callbacks and events and what libocpp expects to happen](#overview-of-the-required-callbacks-and-events-and-what-libocpp-expects-to-happen)
- [ChargePoint() constructor](#chargepoint-constructor)
- [registering callbacks](#registering-callbacks)
- [Functions that need to be triggered from the outside after new information is availble (on\_... functions in the charge point API)](#functions-that-need-to-be-triggered-from-the-outside-after-new-information-is-availble-on_-functions-in-the-charge-point-api)
- [The following functions are triggered depending on different so called "Session Events" from the EvseManager](#the-following-functions-are-triggered-depending-on-different-so-called-session-events-from-the-evsemanager)
- [Authorization](#authorization)
- [Integrate this library with your Charging Station Implementation for OCPP2.0.1](#integrate-this-library-with-your-charging-station-implementation-for-ocpp201)
- [Register event callbacks and on\_handlers](#register-event-callbacks-and-on_handlers)
- [Initialize the database](#initialize-the-database)
- [Install libocpp](#install-libocpp)
- [Quickstart for OCPP 1.6](#quickstart-for-ocpp-16)
- [Building the doxygen documentation](#building-the-doxygen-documentation)
- [C++ implementation of OCPP](#c-implementation-of-ocpp)
- [Table of contents](#table-of-contents)
- [Feature Support](#feature-support)
- [Feature Profile Support OCPP 1.6](#feature-profile-support-ocpp-16)
- [Support for OCPP 2.0.1](#support-for-ocpp-201)
- [CSMS Compatibility](#csms-compatibility)
- [CSMS Compatibility OCPP 1.6](#csms-compatibility-ocpp-16)
- [CSMS Compatibility OCPP 2.0.1](#csms-compatibility-ocpp-201)
- [Integration with EVerest](#integration-with-everest)
- [Run OCPP1.6 with EVerest](#run-ocpp16-with-everest)
- [Run OCPP2.0.1 with EVerest](#run-ocpp201-with-everest)
- [Integrate this library with your Charging Station Implementation for OCPP1.6](#integrate-this-library-with-your-charging-station-implementation-for-ocpp16)
- [Overview of the required callbacks and events and what libocpp expects to happen](#overview-of-the-required-callbacks-and-events-and-what-libocpp-expects-to-happen)
- [ChargePoint() constructor](#chargepoint-constructor)
- [registering callbacks](#registering-callbacks)
- [Functions that need to be triggered from the outside after new information is availble (on\_... functions in the charge point API)](#functions-that-need-to-be-triggered-from-the-outside-after-new-information-is-availble-on_-functions-in-the-charge-point-api)
- [The following functions are triggered depending on different so called "Session Events" from the EvseManager](#the-following-functions-are-triggered-depending-on-different-so-called-session-events-from-the-evsemanager)
- [Authorization](#authorization)
- [Integrate this library with your Charging Station Implementation for OCPP2.0.1](#integrate-this-library-with-your-charging-station-implementation-for-ocpp201)
- [Register event callbacks and on\_handlers](#register-event-callbacks-and-on_handlers)
- [Initialize the database](#initialize-the-database)
- [Install libocpp](#install-libocpp)
- [Quickstart for OCPP 1.6](#quickstart-for-ocpp-16)
- [Building the doxygen documentation](#building-the-doxygen-documentation)
- [Unit testing](#unit-testing)
- [Building with FetchContent instead of EDM](#building-with-fetchcontent-instead-of-edm)

## Feature Support

Expand Down Expand Up @@ -499,3 +503,5 @@ Run the unit tests
cmake .. -DBUILD_TESTING=ON
```

## Building with FetchContent instead of EDM
In [doc/build-with-fetchcontent](doc/build-with-fetchcontent) you can find an example how to build libocpp with FetchContent instead of EDM.
187 changes: 187 additions & 0 deletions doc/build-with-fetchcontent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
cmake_minimum_required(VERSION 3.14)

project(builder
VERSION 0.1
DESCRIPTION "A example builder for libocpp and libtimer"
LANGUAGES CXX
)

set(JSON_BUILD_TESTS OFF CACHE INTERNAL "Build JSON tests")
set(JSON_MultipleHeaders ON CACHE INTERNAL "Build JSON multi header config")
set(BUILD_TESTS OFF CACHE INTERNAL "Build tests")
set(BUILD_EXAMPLES OFF CACHE INTERNAL "Build examples")
set(BUILD_TZ_LIB ON CACHE INTERNAL "")
set(HAS_REMOTE_API 0 CACHE INTERNAL "")
set(USE_AUTOLOAD 0 CACHE INTERNAL "")
set(USE_SYSTEM_TZ_DB ON CACHE INTERNAL "")

macro(find_date_library)
message(STATUS "Using FetchContent for date library")
set(EXTERNAL_DATE_NAME date)
set(EXTERNAL_DATE_URL https://github.com/HowardHinnant/date.git)
set(EXTERNAL_DATE_TAG v3.0.1)

FetchContent_Declare(
${EXTERNAL_DATE_NAME}
GIT_REPOSITORY ${EXTERNAL_DATE_URL}
GIT_TAG ${EXTERNAL_DATE_TAG}
)

FetchContent_MakeAvailable(${EXTERNAL_DATE_NAME})
endmacro()

macro(find_everest_cmake)
message(STATUS "Using FetchContent for everest-cmake")
set(EXTERNAL_EVEREST_CMAKE_NAME everest-cmake)
set(EXTERNAL_EVEREST_CMAKE_URL https://github.com/EVerest/everest-cmake.git)
set(EXTERNAL_EVEREST_CMAKE_TAG v0.1.0)

message(STATUS "Fetching everest cmake")
FetchContent_Declare(
${EXTERNAL_EVEREST_CMAKE_NAME}
GIT_REPOSITORY ${EXTERNAL_EVEREST_CMAKE_URL}
GIT_TAG ${EXTERNAL_EVEREST_CMAKE_TAG}
)

FetchContent_MakeAvailable(${EXTERNAL_EVEREST_CMAKE_NAME})

# Add the cmake directory to the module path
# this is needed because some submodules (everest-timer and everest-log) still need to find the cmake module using "find_package"
set(${EXTERNAL_EVEREST_CMAKE_NAME}_DIR ${CMAKE_BINARY_DIR}/_deps/${EXTERNAL_EVEREST_CMAKE_NAME}-src)
_find_package(everest-cmake REQUIRED PATHS ${everest-cmake_DIR})
endmacro()

macro(find_nlohmann_json)
message(STATUS "Using FetchContent for nlohmann_json library")
set(EXTERNAL_JSON_NAME nlohmann_json)
set(EXTERNAL_JSON_URL https://github.com/nlohmann/json.git)
set(EXTERNAL_JSON_TAG v3.10.5)

FetchContent_Declare(
${EXTERNAL_JSON_NAME}
GIT_REPOSITORY ${EXTERNAL_JSON_URL}
GIT_TAG ${EXTERNAL_JSON_TAG}
)

FetchContent_MakeAvailable(${EXTERNAL_JSON_NAME})
endmacro()

macro(find_nlohmann_json_schema_validator)
message(STATUS "Using FetchContent for nlohmann_json_schema library")
set(EXTERNAL_JSON_SCHEMA_NAME nlohmann_json_schema_validator)
set(EXTERNAL_JSON_SCHEMA_URL https://github.com/pboettch/json-schema-validator)
set(EXTERNAL_JSON_SCHEMA_TAG 2.1.0)

FetchContent_Declare(
${EXTERNAL_JSON_SCHEMA_NAME}
GIT_REPOSITORY ${EXTERNAL_JSON_SCHEMA_URL}
GIT_TAG ${EXTERNAL_JSON_SCHEMA_TAG}
)

FetchContent_MakeAvailable(${EXTERNAL_JSON_SCHEMA_NAME})
endmacro()

macro(find_websocketpp)
message(STATUS "Using FetchContent for websocketpp library")
set(EXTERNAL_WEBSOCKET_NAME websocketpp)
set(EXTERNAL_WEBSOCKET_URL https://github.com/zaphoyd/websocketpp.git)
set(EXTERNAL_WEBSOCKET_TAG 0.8.2)

FetchContent_Declare(
${EXTERNAL_WEBSOCKET_NAME}
GIT_REPOSITORY ${EXTERNAL_WEBSOCKET_URL}
GIT_TAG ${EXTERNAL_WEBSOCKET_TAG}
)

FetchContent_MakeAvailable(${EXTERNAL_WEBSOCKET_NAME})
add_library(websocketpp::websocketpp INTERFACE IMPORTED)
set_target_properties(websocketpp::websocketpp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${websocketpp_SOURCE_DIR}")
endmacro()

macro(find_fsm)
message(STATUS "Using FetchContent for fsm library")
set(EXTERNAL_FSM_NAME fsm)
set(EXTERNAL_FSM_URL https://github.com/EVerest/libfsm.git)
set(EXTERNAL_FSM_TAG v0.2.0)

FetchContent_Declare(
${EXTERNAL_FSM_NAME}
GIT_REPOSITORY ${EXTERNAL_FSM_URL}
GIT_TAG ${EXTERNAL_FSM_TAG}
)

FetchContent_MakeAvailable(${EXTERNAL_FSM_NAME})
endmacro()

macro(find_everest_timer)
message(STATUS "Using FetchContent for everest-timer library")
set(EXTERNAL_EVEREST_TIMER_NAME everest-timer)
set(EXTERNAL_EVEREST_TIMER_URL https://github.com/EVerest/libtimer.git)
set(EXTERNAL_EVEREST_TIMER_TAG v0.1.1)

FetchContent_Declare(
${EXTERNAL_EVEREST_TIMER_NAME}
GIT_REPOSITORY ${EXTERNAL_EVEREST_TIMER_URL}
GIT_TAG ${EXTERNAL_EVEREST_TIMER_TAG}
)

FetchContent_MakeAvailable(${EXTERNAL_EVEREST_TIMER_NAME})
endmacro()

macro(find_everest_log)
message(STATUS "Using FetchContent for everest-log library")
set(EXTERNAL_EVEREST_LOG_NAME everest-log)
set(EXTERNAL_EVEREST_LOG_URL https://github.com/EVerest/liblog.git)
set(EXTERNAL_EVEREST_LOG_TAG v0.1.0)

FetchContent_Declare(
${EXTERNAL_EVEREST_LOG_NAME}
GIT_REPOSITORY ${EXTERNAL_EVEREST_LOG_URL}
GIT_TAG ${EXTERNAL_EVEREST_LOG_TAG}
)

FetchContent_MakeAvailable(${EXTERNAL_EVEREST_LOG_NAME})
endmacro()

macro(find_package PACKAGE_NAME)
message(STATUS "FIND PACKAGE ${PACKAGE_NAME}")

if("${PACKAGE_NAME}" STREQUAL "date")
find_date_library()
elseif("${PACKAGE_NAME}" STREQUAL "everest-cmake")
find_everest_cmake()
elseif("${PACKAGE_NAME}" STREQUAL "nlohmann_json")
find_nlohmann_json()
elseif("${PACKAGE_NAME}" STREQUAL "nlohmann_json_schema_validator")
find_nlohmann_json_schema_validator()
elseif("${PACKAGE_NAME}" STREQUAL "websocketpp")
find_websocketpp()
elseif("${PACKAGE_NAME}" STREQUAL "fsm")
find_fsm()
elseif("${PACKAGE_NAME}" STREQUAL "everest-timer")
find_everest_timer()
elseif("${PACKAGE_NAME}" STREQUAL "everest-log")
find_everest_log()
else()
message(STATUS "Using regular findpackage for ${PACKAGE_NAME}")
_find_package(${ARGV})
endif()
endmacro()

include(FetchContent)

set(EXTERNAL_OCPP_NAME libocpp)
set(EXTERNAL_OCPP_URL https://github.com/EVerest/libocpp.git)
set(EXTERNAL_OCPP_TAG main)
set(DISABLE_EDM ON CACHE INTERNAL "")
set(LIBOCPP16_BUILD_EXAMPLES ON CACHE INTERNAL "")

# Fetch libocpp
FetchContent_Declare(
${EXTERNAL_OCPP_NAME}
GIT_REPOSITORY ${EXTERNAL_OCPP_URL}
GIT_TAG ${EXTERNAL_OCPP_TAG}
)

# Find the libocpp package
FetchContent_MakeAvailable(${EXTERNAL_OCPP_NAME})

0 comments on commit adca4bb

Please sign in to comment.