diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e915ef..85ce458 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,60 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR) PROJECT(fleet-protocol C CXX) +SET(FLEET_PROTOCOL_VERSION 2.0.0) +SET(FLEET_PROTOCOL_NAMESPACE "fleet-protocol-interface::") + +OPTION(BRINGAUTO_PACKAGE "Package creation" OFF) +OPTION(BRINGAUTO_INSTALL "Enable install" OFF) +OPTION(BRINGAUTO_SAMPLES "Enable build of sample app, not used in project" OFF) + +IF(BRINGAUTO_PACKAGE) + IF(NOT BRINGAUTO_INSTALL) + SET(BRINGAUTO_INSTALL ON CACHE BOOL "Forced install due to BRINGAUTO_PACKAGE=ON" FORCE) + MESSAGE(WARNING "BRINGAUTO_INSTALL is switched to on because of BRINGAUTO_PACKAGE=ON") + ENDIF() +ENDIF() + +FIND_PACKAGE(CMLIB + COMPONENTS CMDEF CMUTIL + REQUIRED +) + IF(BRINGAUTO_SAMPLES) ADD_SUBDIRECTORY("${CMAKE_CURRENT_SOURCE_DIR}/examples") ENDIF() ADD_SUBDIRECTORY("${CMAKE_CURRENT_SOURCE_DIR}/lib") ADD_SUBDIRECTORY("${CMAKE_CURRENT_SOURCE_DIR}/protobuf") + +CMDEF_ADD_LIBRARY( + LIBRARY_GROUP fleet-protocol + TYPE INTERFACE + VERSION ${FLEET_PROTOCOL_VERSION} +) +TARGET_LINK_LIBRARIES(fleet-protocol-interface INTERFACE + common-headers-interface + internal-client-interface + module-gateway-interface + module-maintainer-external-server-interface + module-maintainer-module-gateway-interface + protobuf-cpp-interface +) + + +IF (BRINGAUTO_INSTALL) + CMDEF_INSTALL( + TARGET fleet-protocol-interface + NAMESPACE ${FLEET_PROTOCOL_NAMESPACE} + ) + +ENDIF () + +IF (BRINGAUTO_PACKAGE) + CMDEF_PACKAGE( + MAIN_TARGET fleet-protocol-interface + VERSION ${FLEET_PROTOCOL_VERSION} + ) + SET(CPACK_GENERATOR ZIP) + SET(CPACK_PACKAGE_CONTACT "BringAuto s.r.o. ") + INCLUDE(CPack) +ENDIF() \ No newline at end of file diff --git a/README.md b/README.md index 9c5df39..6377bbb 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,27 @@ -# Fleet protocol +# Fleet Protocol -Fleet protocol is a communication protocol developed by BringAuto to allow simple and reliable communication between multiple devices and cloud infrastructure. +Fleet Protocol is a communication protocol developed by BringAuto to allow simple and reliable communication between +multiple devices and cloud infrastructure. **Complete protocol documentation will be released soon**. Protocol consists of three parts: + * internal client - specific part of device that communicates with module gateway * module gateway: - - internal server - communicates with internal client - - aggregator - aggregates status messages - - external client - communicates with external server + - internal server - communicates with internal client + - aggregator - aggregates status messages + - external client - communicates with external server * external server - communicates with server infrastructure that gives user the ability to control devices +## Communication protocol -# Communication protocol - -We use [ProtoBuf] library for message format (version [Protobuf version]) and serialization/deserialization - protocol specification +We use [ProtoBuf] library for message format (version [Protobuf version]) and serialization/deserialization - protocol +specification can be found in protobuff folder. Each message must be prefixed with four bytes long (uint32_t data type) header which holds -information about size of the ProtoBuf message. +information about size of the ProtoBuf message. To read more about the system architecture look at Fleet Protocol v2 documentation: + - [Summary] - [Fleet Protocol Requirements] - [Internal Client] @@ -32,7 +35,7 @@ To read more about the system architecture look at Fleet Protocol v2 documentati - [HTTP API] - [HTTP API Wait Mechanism] -## Protocol messages +### Protocol messages Messages are described by ProtoBuff v3. @@ -40,31 +43,96 @@ If the message filed is not mandatory then it's marked as OPTIONAL by "OPTIONAL" as the last comment in documentation for the given field. Optional fields has defaults as described in [ProtoBuf] v3 doc. -# Repo structure -## Examples +## Repo structure + +### Examples + Samples of fleet-protocol features usage. Use CMake option `BRINGAUTO_SAMPLES=ON` to configure them. -## Lib +### Lib + Header files of interfaces -## Protobuf +### Protobuf + Protobuf compiled and non-compiled files +## Usage + +### Requirements + +- [CMlib](https://github.com/cmakelib/cmakelib) + +### Installation + +To install the library, first configure the project with CMake option BRINGAUTO_INSTALL=ON and BRINGAUTO_PACKAGE=ON and then install it. + +```bash +mkdir _build && cd _build +cmake -DBRINGAUTO_INSTALL=ON -DBRINGAUTO_PACKAGE=ON .. +make install +``` + +### Package + +To create a package, configure the project with CMake option BRINGAUTO_PACKAGE=ON and then create it using `cpack`. + +```bash +mkdir _build && cd _build +cmake -DBRINGAUTO_INSTALL=ON -DBRINGAUTO_PACKAGE=ON .. +cpack +``` + +### Using library in CMake projects + +Once the library is installed, it can be used in other projects by adding the following lines to the `CMakeLists.txt` +file: + +```cmake +FIND_PACKAGE(fleet-protocol-interface REQUIRED) +TARGET_LINK_LIBRARIES( PUBLIC fleet-protocol-interface::fleet-protocol-interface) +``` + +This will link all interfaces. If you want to link only specific interface, use the interfaces from the list below: + +* fleet-protocol-interface::common-headers-interface +* fleet-protocol-interface::internal-client-interface +* fleet-protocol-interface::module-gateway-interface +* fleet-protocol-interface::module-maintainer-external-server-interface +* fleet-protocol-interface::module-maintainer-module-gateway-interface +* fleet-protocol-interface::protobuf-cpp-interface + +> Note that `protobuf-cpp-interface` also needs `protobuf::libprotobuf` to be linked to the target + [BringAutoDaemon.proto]: ./BringAutoDaemon.proto + [ProtoBuf]: https://developers.google.com/protocol-buffers + [Protobuf version]: https://github.com/protocolbuffers/protobuf/releases/tag/v3.21.12 + [Summary]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/summary + [Fleet Protocol Requirements]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/protocol-requirements + [Internal Client]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/internal-client + [Module Gateway]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/module-gateway + [External Server]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/external-server + [Modules]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/modules + [Message Structure]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/message-structure -[Internal Client design]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/internal-client-design + +[Internal Client design]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/internal-client-design + [Module Gateway design]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/module-gateway-design + [External Server design]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/external-server-design + [HTTP API]: https://ref.bringautofleet.com/r/protocol/http-api/1.0.0/http-api + [HTTP API Wait Mechanism]: https://ref.bringautofleet.com/r/protocol/http-api/1.0.0/wait-mechanism diff --git a/protobuf/CMLibStorage.cmake b/examples/protobuf_parsing_example/CMLibStorage.cmake similarity index 100% rename from protobuf/CMLibStorage.cmake rename to examples/protobuf_parsing_example/CMLibStorage.cmake diff --git a/examples/protobuf_parsing_example/CMakeLists.txt b/examples/protobuf_parsing_example/CMakeLists.txt index d0ee08d..43e4750 100644 --- a/examples/protobuf_parsing_example/CMakeLists.txt +++ b/examples/protobuf_parsing_example/CMakeLists.txt @@ -3,13 +3,19 @@ PROJECT(fleet-protocol CXX) SET(CMAKE_CXX_STANDARD 20) -SET(CMAKE_BUILD_RPATH_USE_ORIGIN ON) +FIND_PACKAGE(CMLIB REQUIRED COMPONENTS CMDEF STORAGE) +IF (NOT BRINGAUTO_SYSTEM_DEP) + INCLUDE(cmake/Dependencies.cmake) +ENDIF () -FILE(GLOB_RECURSE source_files "source/*" "lib/protobuf/*") -ADD_LIBRARY(parsing_example_lib STATIC ${source_files}) -TARGET_INCLUDE_DIRECTORIES(parsing_example_lib PUBLIC "include/" "lib/protobuf/") -TARGET_LINK_LIBRARIES(parsing_example_lib PUBLIC ${PROJECT_NAME}::protobuf_cpp) +SET(CMAKE_BUILD_RPATH_USE_ORIGIN ON) +FIND_PACKAGE(Protobuf 3.21.12 REQUIRED) -ADD_EXECUTABLE(protobuf_parser main.cpp) -TARGET_LINK_LIBRARIES(protobuf_parser parsing_example_lib) \ No newline at end of file +FILE(GLOB_RECURSE source_files "source/*") +FILE(GLOB_RECURSE protobuf_files "lib/protobuf/*") +CMDEF_ADD_EXECUTABLE(TARGET protobuf-parser + SOURCES main.cpp ${source_files} ${protobuf_files} + INCLUDE_DIRECTORIES "include/" "lib/protobuf/" + VERSION 1.0.0) +TARGET_LINK_LIBRARIES(protobuf-parser PUBLIC protobuf::libprotobuf protobuf-cpp-interface) \ No newline at end of file diff --git a/protobuf/cmake/Dependencies.cmake b/examples/protobuf_parsing_example/cmake/Dependencies.cmake similarity index 100% rename from protobuf/cmake/Dependencies.cmake rename to examples/protobuf_parsing_example/cmake/Dependencies.cmake diff --git a/lib/common_headers/CMakeLists.txt b/lib/common_headers/CMakeLists.txt index 6957f35..bda1d8e 100644 --- a/lib/common_headers/CMakeLists.txt +++ b/lib/common_headers/CMakeLists.txt @@ -1,12 +1,15 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR) -PROJECT(fleet-protocol-common-headers C CXX) +PROJECT(fleet-protocol C CXX) -ADD_LIBRARY(common_headers INTERFACE) -TARGET_INCLUDE_DIRECTORIES(common_headers INTERFACE "$" - "$") +CMDEF_ADD_LIBRARY( + LIBRARY_GROUP common-headers + TYPE INTERFACE + VERSION ${FLEET_PROTOCOL_VERSION} + INCLUDE_DIRECTORIES include/ + INSTALL_INCLUDE_DIRECTORIES include/ +) -FILE(GLOB_RECURSE include_files include/*) -TARGET_SOURCES(common_headers INTERFACE - FILE_SET common_headers TYPE HEADERS FILES ${include_files} BASE_DIRS include) - -ADD_LIBRARY(fleet-protocol::common_headers ALIAS common_headers) +CMDEF_INSTALL( + TARGET common-headers-interface + NAMESPACE ${FLEET_PROTOCOL_NAMESPACE} +) diff --git a/lib/common_headers/include/device_management.h b/lib/common_headers/include/fleet_protocol/common_headers/device_management.h similarity index 95% rename from lib/common_headers/include/device_management.h rename to lib/common_headers/include/fleet_protocol/common_headers/device_management.h index ec8ae4f..b441e8d 100644 --- a/lib/common_headers/include/device_management.h +++ b/lib/common_headers/include/fleet_protocol/common_headers/device_management.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #ifdef __cplusplus extern "C" { diff --git a/lib/common_headers/include/general_error_codes.h b/lib/common_headers/include/fleet_protocol/common_headers/general_error_codes.h similarity index 100% rename from lib/common_headers/include/general_error_codes.h rename to lib/common_headers/include/fleet_protocol/common_headers/general_error_codes.h diff --git a/lib/common_headers/include/memory_management.h b/lib/common_headers/include/fleet_protocol/common_headers/memory_management.h similarity index 100% rename from lib/common_headers/include/memory_management.h rename to lib/common_headers/include/fleet_protocol/common_headers/memory_management.h diff --git a/lib/internal_client/CMakeLists.txt b/lib/internal_client/CMakeLists.txt index 273890b..10c6f65 100644 --- a/lib/internal_client/CMakeLists.txt +++ b/lib/internal_client/CMakeLists.txt @@ -1,14 +1,17 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR) -PROJECT(fleet-protocol-internal-client C CXX) +PROJECT(fleet-protocol C CXX) -ADD_LIBRARY(internal_client_interface INTERFACE) -TARGET_INCLUDE_DIRECTORIES(internal_client_interface INTERFACE "$" - "$") -TARGET_LINK_LIBRARIES(internal_client_interface INTERFACE fleet-protocol::common_headers) +CMDEF_ADD_LIBRARY( + LIBRARY_GROUP internal-client + TYPE INTERFACE + VERSION ${FLEET_PROTOCOL_VERSION} + INCLUDE_DIRECTORIES include/ + INSTALL_INCLUDE_DIRECTORIES include/ +) +TARGET_LINK_LIBRARIES(internal-client-interface INTERFACE common-headers-interface) -FILE(GLOB_RECURSE include_files include/*) -TARGET_SOURCES(internal_client_interface INTERFACE - FILE_SET internal_client_interface TYPE HEADERS FILES ${include_files} BASE_DIRS include) - -ADD_LIBRARY(fleet-protocol::internal_client_interface ALIAS internal_client_interface) +CMDEF_INSTALL( + TARGET internal-client-interface + NAMESPACE ${FLEET_PROTOCOL_NAMESPACE} +) diff --git a/lib/internal_client/include/ic_error_codes.h b/lib/internal_client/include/fleet_protocol/internal_client/error_codes.h similarity index 95% rename from lib/internal_client/include/ic_error_codes.h rename to lib/internal_client/include/fleet_protocol/internal_client/error_codes.h index c8c8af7..87a3e3d 100644 --- a/lib/internal_client/include/ic_error_codes.h +++ b/lib/internal_client/include/fleet_protocol/internal_client/error_codes.h @@ -1,6 +1,6 @@ #pragma once -#include +#include /** * @brief Specific error codes for internal_client */ diff --git a/lib/internal_client/include/internal_client.h b/lib/internal_client/include/fleet_protocol/internal_client/internal_client.h similarity index 95% rename from lib/internal_client/include/internal_client.h rename to lib/internal_client/include/fleet_protocol/internal_client/internal_client.h index 5c7c34d..8240fa8 100644 --- a/lib/internal_client/include/internal_client.h +++ b/lib/internal_client/include/fleet_protocol/internal_client/internal_client.h @@ -4,10 +4,10 @@ extern "C" { #endif -#include -#include -#include -#include +#include +#include +#include +#include /** * @section internal_client diff --git a/lib/module_gateway/CMakeLists.txt b/lib/module_gateway/CMakeLists.txt index 776af8b..672450b 100644 --- a/lib/module_gateway/CMakeLists.txt +++ b/lib/module_gateway/CMakeLists.txt @@ -1,12 +1,15 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR) PROJECT(fleet-protocol C CXX) -ADD_LIBRARY(module_gateway INTERFACE) -TARGET_INCLUDE_DIRECTORIES(module_gateway INTERFACE include/) -TARGET_LINK_LIBRARIES(module_gateway INTERFACE ${PROJECT_NAME}::common_headers) - -FILE(GLOB_RECURSE include_files include/*) -TARGET_SOURCES(module_gateway INTERFACE - FILE_SET module_gateway TYPE HEADERS FILES ${include_files} BASE_DIRS include) - -ADD_LIBRARY(${PROJECT_NAME}::module_gateway ALIAS module_gateway ) +CMDEF_ADD_LIBRARY( + LIBRARY_GROUP module-gateway + TYPE INTERFACE + VERSION ${FLEET_PROTOCOL_VERSION} + INCLUDE_DIRECTORIES include/ + INSTALL_INCLUDE_DIRECTORIES include/ +) +TARGET_LINK_LIBRARIES(module-gateway-interface INTERFACE common-headers-interface) +CMDEF_INSTALL( + TARGET module-gateway-interface + NAMESPACE ${FLEET_PROTOCOL_NAMESPACE} +) diff --git a/lib/module_gateway/include/command_manager.h b/lib/module_gateway/include/fleet_protocol/module_gateway/command_manager.h similarity index 90% rename from lib/module_gateway/include/command_manager.h rename to lib/module_gateway/include/fleet_protocol/module_gateway/command_manager.h index 788cdec..7bebb7e 100644 --- a/lib/module_gateway/include/command_manager.h +++ b/lib/module_gateway/include/fleet_protocol/module_gateway/command_manager.h @@ -4,9 +4,9 @@ extern "C" { #endif -#include -#include -#include +#include +#include +#include /** * @section module_gateway diff --git a/lib/module_gateway/include/error_aggregator.h b/lib/module_gateway/include/fleet_protocol/module_gateway/error_aggregator.h similarity index 95% rename from lib/module_gateway/include/error_aggregator.h rename to lib/module_gateway/include/fleet_protocol/module_gateway/error_aggregator.h index e3b044a..0aefda7 100644 --- a/lib/module_gateway/include/error_aggregator.h +++ b/lib/module_gateway/include/fleet_protocol/module_gateway/error_aggregator.h @@ -4,9 +4,9 @@ extern "C" { #endif -#include -#include -#include +#include +#include +#include /** * @section module_gateway diff --git a/lib/module_gateway/include/mg_error_codes.h b/lib/module_gateway/include/fleet_protocol/module_gateway/error_codes.h similarity index 79% rename from lib/module_gateway/include/mg_error_codes.h rename to lib/module_gateway/include/fleet_protocol/module_gateway/error_codes.h index 3d9990c..7afb0cd 100644 --- a/lib/module_gateway/include/mg_error_codes.h +++ b/lib/module_gateway/include/fleet_protocol/module_gateway/error_codes.h @@ -1,6 +1,6 @@ #pragma once -#include +#include enum mg_error_codes { DEVICE_NOT_SUPPORTED = RESERVED -1, diff --git a/lib/module_gateway/include/status_aggregator.h b/lib/module_gateway/include/fleet_protocol/module_gateway/status_aggregator.h similarity index 97% rename from lib/module_gateway/include/status_aggregator.h rename to lib/module_gateway/include/fleet_protocol/module_gateway/status_aggregator.h index f131602..75f8cc1 100644 --- a/lib/module_gateway/include/status_aggregator.h +++ b/lib/module_gateway/include/fleet_protocol/module_gateway/status_aggregator.h @@ -4,9 +4,9 @@ extern "C" { #endif -#include -#include -#include +#include +#include +#include /** * @section module_gateway diff --git a/lib/module_maintainer/external_server/CMakeLists.txt b/lib/module_maintainer/external_server/CMakeLists.txt index c2e3279..a103bd5 100644 --- a/lib/module_maintainer/external_server/CMakeLists.txt +++ b/lib/module_maintainer/external_server/CMakeLists.txt @@ -1,12 +1,15 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR) PROJECT(fleet-protocol C CXX) -ADD_LIBRARY(external_server INTERFACE) -TARGET_INCLUDE_DIRECTORIES(external_server INTERFACE include/) -TARGET_LINK_LIBRARIES(external_server INTERFACE ${PROJECT_NAME}::common_headers) - -FILE(GLOB_RECURSE include_files include/*) -TARGET_SOURCES(external_server INTERFACE - FILE_SET external_server TYPE HEADERS FILES ${include_files} BASE_DIRS include) - -ADD_LIBRARY(${PROJECT_NAME}::module_maintainer::external_server ALIAS external_server ) +CMDEF_ADD_LIBRARY( + LIBRARY_GROUP module-maintainer-external-server + TYPE INTERFACE + VERSION ${FLEET_PROTOCOL_VERSION} + INCLUDE_DIRECTORIES include/ + INSTALL_INCLUDE_DIRECTORIES include/ +) +TARGET_LINK_LIBRARIES(module-maintainer-external-server-interface INTERFACE common-headers-interface) +CMDEF_INSTALL( + TARGET module-maintainer-external-server-interface + NAMESPACE ${FLEET_PROTOCOL_NAMESPACE} +) diff --git a/lib/module_maintainer/external_server/include/external_server_interface.h b/lib/module_maintainer/external_server/include/fleet_protocol/module_maintainer/external_server/external_server_interface.h similarity index 95% rename from lib/module_maintainer/external_server/include/external_server_interface.h rename to lib/module_maintainer/external_server/include/fleet_protocol/module_maintainer/external_server/external_server_interface.h index ee53ec4..f2cfdf4 100644 --- a/lib/module_maintainer/external_server/include/external_server_interface.h +++ b/lib/module_maintainer/external_server/include/fleet_protocol/module_maintainer/external_server/external_server_interface.h @@ -4,11 +4,11 @@ extern "C" { #endif -#include -#include -#include +#include +#include +#include -#include +#include /** * @file external_server_interface.h diff --git a/lib/module_maintainer/external_server/include/external_server_structures.h b/lib/module_maintainer/external_server/include/fleet_protocol/module_maintainer/external_server/external_server_structures.h similarity index 79% rename from lib/module_maintainer/external_server/include/external_server_structures.h rename to lib/module_maintainer/external_server/include/fleet_protocol/module_maintainer/external_server/external_server_structures.h index 513ef57..27b442d 100644 --- a/lib/module_maintainer/external_server/include/external_server_structures.h +++ b/lib/module_maintainer/external_server/include/fleet_protocol/module_maintainer/external_server/external_server_structures.h @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include +#include /** * @brief Specific error codes for external server interface diff --git a/lib/module_maintainer/module_gateway/CMakeLists.txt b/lib/module_maintainer/module_gateway/CMakeLists.txt index 15f72dd..c44acfd 100644 --- a/lib/module_maintainer/module_gateway/CMakeLists.txt +++ b/lib/module_maintainer/module_gateway/CMakeLists.txt @@ -1,11 +1,15 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR) PROJECT(fleet-protocol C CXX) -ADD_LIBRARY(module_gateway_maintainer INTERFACE) -ADD_LIBRARY(${PROJECT_NAME}::module_maintainer::module_gateway ALIAS module_gateway_maintainer ) -TARGET_INCLUDE_DIRECTORIES(module_gateway_maintainer INTERFACE include/) -TARGET_LINK_LIBRARIES(module_gateway_maintainer INTERFACE ${PROJECT_NAME}::common_headers) - -FILE(GLOB_RECURSE include_files include/*) -TARGET_SOURCES(module_gateway_maintainer INTERFACE - FILE_SET module_gateway_maintainer TYPE HEADERS FILES ${include_files} BASE_DIRS include) +CMDEF_ADD_LIBRARY( + LIBRARY_GROUP module-maintainer-module-gateway + TYPE INTERFACE + VERSION ${FLEET_PROTOCOL_VERSION} + INCLUDE_DIRECTORIES include/ + INSTALL_INCLUDE_DIRECTORIES include/ +) +TARGET_LINK_LIBRARIES(module-maintainer-module-gateway-interface INTERFACE common-headers-interface) +CMDEF_INSTALL( + TARGET module-maintainer-module-gateway-interface + NAMESPACE ${FLEET_PROTOCOL_NAMESPACE} +) diff --git a/lib/module_maintainer/module_gateway/include/module_manager.h b/lib/module_maintainer/module_gateway/include/fleet_protocol/module_maintainer/module_gateway/module_manager.h similarity index 97% rename from lib/module_maintainer/module_gateway/include/module_manager.h rename to lib/module_maintainer/module_gateway/include/fleet_protocol/module_maintainer/module_gateway/module_manager.h index 40b67cf..04164f2 100644 --- a/lib/module_maintainer/module_gateway/include/module_manager.h +++ b/lib/module_maintainer/module_gateway/include/fleet_protocol/module_maintainer/module_gateway/module_manager.h @@ -4,8 +4,8 @@ extern "C" { #endif -#include -#include +#include +#include /** * @file diff --git a/protobuf/CMakeLists.txt b/protobuf/CMakeLists.txt index a98d8d9..7241673 100644 --- a/protobuf/CMakeLists.txt +++ b/protobuf/CMakeLists.txt @@ -1,17 +1,21 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR) PROJECT(fleet-protocol CXX) -FIND_PACKAGE(CMLIB REQUIRED COMPONENTS CMDEF STORAGE) -IF (NOT BRINGAUTO_SYSTEM_DEP) - INCLUDE(cmake/Dependencies.cmake) -ENDIF () - SET(Protobuf_USE_STATIC_LIBS ON) -FIND_PACKAGE(Protobuf 3.21.12) -FILE(GLOB_RECURSE protobuf_cpp_files "compiled/cpp/*") -ADD_LIBRARY(protobuf_cpp STATIC ${protobuf_cpp_files}) -TARGET_INCLUDE_DIRECTORIES(protobuf_cpp PUBLIC "compiled/cpp/") -TARGET_LINK_LIBRARIES(protobuf_cpp PUBLIC protobuf::libprotobuf) +FILE(GLOB_RECURSE source_files "compiled/cpp/source/*.cc") + +CMDEF_ADD_LIBRARY( + LIBRARY_GROUP protobuf-cpp + TYPE INTERFACE + VERSION ${FLEET_PROTOCOL_VERSION} + SOURCES ${source_files} + SOURCE_BASE_DIRECTORY compiled/cpp/source/ + INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/compiled/cpp/include/" + INSTALL_INCLUDE_DIRECTORIES "compiled/cpp/include/" +) -ADD_LIBRARY(fleet-protocol::protobuf_cpp ALIAS protobuf_cpp ) +CMDEF_INSTALL( + TARGET protobuf-cpp-interface + NAMESPACE ${FLEET_PROTOCOL_NAMESPACE} +) diff --git a/protobuf/README.md b/protobuf/README.md index 45020ad..cf2ba9c 100644 --- a/protobuf/README.md +++ b/protobuf/README.md @@ -1,41 +1,54 @@ # Protobuf + Using Protobuf version 21.12 -## Link -CMakeLists in this directory adds two static library `protobuf_cpp` +## Usage + +CMakeLists in this directory adds library `protobuf-cpp-interface`. +To use this library, it is necessary to link `libprotobuf` library. + +Usage example is in [examples/protobuf_parsing_example](examples/protobuf_parsing_example). -To link it, use the following statements in CMakeLists.txt: +To link the library, use the following CMake commands in your CMakeLists.txt file. -```angular2html -TARGET_LINK_LIBRARIES( PUBLIC ${PROJECT_NAME}::protobuf_cpp) +```cmake +FIND_PACKAGE(Protobuf 3.21.12 REQUIRED) +TARGET_LINK_LIBRARIES( PUBLIC protobuf::libprotobuf protobuf-cpp-interface) ``` ## Compilation + Compile to all languages: + ``` find protobuf/definition -name "*.proto" -exec protoc -I=protobuf/definition --cpp_out=compiled/cpp --csharp_out=compiled/cs --python_out=compiled/python --go_out=compiled/go/ --go_opt=paths=source_relative {} + ``` + To compile files to a specific language only, use the specific `*_out` options in command. Note that protoc doesn't support double asterisks (**), so it should be used with `find`. **C++** + ``` find protobuf/definition -name "*.proto" -exec protoc -I=./definition --cpp_out=./compiled/cpp {} + ``` **C#** + ``` find protobuf/definition -name "*.proto" -exec protoc -I=./definition --csharp_out=./compiled/cpp {} + ``` **Python** + ``` find protobuf/definition -name "*.proto" -exec protoc -I=./definition --python_out=./compiled/cpp {} + ``` -**GO** +**GO** protoc-gen-go needs to be installed! + ``` find protobuf/definition -name "*.proto" -exec protoc -I=./definition --go_out=./compiled/go --go_opt=paths=source_relative {} + ``` diff --git a/protobuf/compiled/cpp/ExternalProtocol.pb.h b/protobuf/compiled/cpp/include/ExternalProtocol.pb.h similarity index 100% rename from protobuf/compiled/cpp/ExternalProtocol.pb.h rename to protobuf/compiled/cpp/include/ExternalProtocol.pb.h diff --git a/protobuf/compiled/cpp/InternalProtocol.pb.h b/protobuf/compiled/cpp/include/InternalProtocol.pb.h similarity index 100% rename from protobuf/compiled/cpp/InternalProtocol.pb.h rename to protobuf/compiled/cpp/include/InternalProtocol.pb.h diff --git a/protobuf/compiled/cpp/ExternalProtocol.pb.cc b/protobuf/compiled/cpp/source/ExternalProtocol.pb.cc similarity index 100% rename from protobuf/compiled/cpp/ExternalProtocol.pb.cc rename to protobuf/compiled/cpp/source/ExternalProtocol.pb.cc diff --git a/protobuf/compiled/cpp/InternalProtocol.pb.cc b/protobuf/compiled/cpp/source/InternalProtocol.pb.cc similarity index 100% rename from protobuf/compiled/cpp/InternalProtocol.pb.cc rename to protobuf/compiled/cpp/source/InternalProtocol.pb.cc