From b3bff0419e9e8d3e361a5ee6d4c29c7a2864f5b2 Mon Sep 17 00:00:00 2001 From: Martin Burian Date: Wed, 1 Jul 2026 14:00:44 +0200 Subject: [PATCH 1/2] Migrate from cmlib to CMake FetchContent (BAF-1717) Replace cmlib dependency resolution with plain CMake + FetchContent, following the pattern already validated for external-server-cpp (BAF-1706) and mission-module (BAF-1715). FLEET_PROTOCOL_BUILD_MODULE_GATEWAY / FLEET_PROTOCOL_BUILD_EXTERNAL_SERVER and all gateway/server build logic are untouched; no source files changed. Validated end-to-end in bringauto/cpp-build-environment for all three flag combinations (gateway-only, external-server-only, both). Co-Authored-By: Claude Sonnet 5 --- CMLibStorage.cmake | 6 - CMakeLists.txt | 19 +--- cmake/Dependencies.cmake | 30 ++--- cmake/FindBAAeron.cmake | 70 ++++++++++++ cmake/FindBAAsyncFunctionExecution.cmake | 52 +++++++++ cmake/FindBABoost.cmake | 52 +++++++++ cmake/FindBACppRestSdk.cmake | 47 ++++++++ cmake/FindBAFleetHttpClient.cmake | 61 ++++++++++ cmake/FindBAFleetProtocolCpp.cmake | 39 +++++++ cmake/FindBAFleetProtocolInterface.cmake | 75 +++++++++++++ cmake/FindBANlohmannJson.cmake | 33 ++++++ cmake/FindBAProtobuf.cmake | 33 ++++++ cmake/FindBAZlib.cmake | 47 ++++++++ cmake/FindCMLIB.cmake | 106 ++++++++++++++++++ .../Findasync-function-execution-shared.cmake | 4 + cmake/Findfleet-http-client-shared.cmake | 4 + ...indfleet-protocol-cxx-helpers-static.cmake | 4 + cmake/Findfleet-protocol-interface.cmake | 4 + 18 files changed, 651 insertions(+), 35 deletions(-) delete mode 100644 CMLibStorage.cmake create mode 100644 cmake/FindBAAeron.cmake create mode 100644 cmake/FindBAAsyncFunctionExecution.cmake create mode 100644 cmake/FindBABoost.cmake create mode 100644 cmake/FindBACppRestSdk.cmake create mode 100644 cmake/FindBAFleetHttpClient.cmake create mode 100644 cmake/FindBAFleetProtocolCpp.cmake create mode 100644 cmake/FindBAFleetProtocolInterface.cmake create mode 100644 cmake/FindBANlohmannJson.cmake create mode 100644 cmake/FindBAProtobuf.cmake create mode 100644 cmake/FindBAZlib.cmake create mode 100644 cmake/FindCMLIB.cmake create mode 100644 cmake/Findasync-function-execution-shared.cmake create mode 100644 cmake/Findfleet-http-client-shared.cmake create mode 100644 cmake/Findfleet-protocol-cxx-helpers-static.cmake create mode 100644 cmake/Findfleet-protocol-interface.cmake diff --git a/CMLibStorage.cmake b/CMLibStorage.cmake deleted file mode 100644 index 68f9a8a..0000000 --- a/CMLibStorage.cmake +++ /dev/null @@ -1,6 +0,0 @@ -FIND_PACKAGE(CMLIB REQUIRED COMPONENTS CMCONF) -CMCONF_INIT_SYSTEM(FLEET_PROTOCOL) - -SET(STORAGE_LIST DEP) - -SET(STORAGE_LIST_DEP "https://github.com/bacpack-system/package-tracker.git") diff --git a/CMakeLists.txt b/CMakeLists.txt index f4ed7c5..c006e41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR) PROJECT(transparent_module CXX) +LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +INCLUDE(GNUInstallDirs) + SET(CMAKE_BUILD_RPATH_USE_ORIGIN ON) SET(CMAKE_INSTALL_RPATH "$ORIGIN") SET(CMAKE_CXX_STANDARD 20) @@ -14,8 +17,6 @@ SET(TRANSPARENT_MODULE_VERSION 1.0.5) OPTION(BRINGAUTO_INSTALL "Configure install" OFF) OPTION(BRINGAUTO_PACKAGE "Configure package creation" OFF) -OPTION(BRINGAUTO_SYSTEM_DEP "System dependencies are used if switched to ON, packager used if OFF" OFF) -OPTION(BRINGAUTO_GET_PACKAGES_ONLY "Only download packages for this project" OFF) OPTION(FLEET_PROTOCOL_BUILD_MODULE_GATEWAY "Build shared library for module gateway " ON) OPTION(FLEET_PROTOCOL_BUILD_EXTERNAL_SERVER "Build shared library for external server " ON) @@ -43,19 +44,7 @@ IF (BRINGAUTO_PACKAGE) ENDIF () ENDIF () -FIND_PACKAGE(CMLIB COMPONENTS CMCONF REQUIRED) -CMCONF_INIT_SYSTEM(FLEET_PROTOCOL) - -FIND_PACKAGE(CMLIB - COMPONENTS CMDEF CMUTIL STORAGE - REQUIRED -) -IF (NOT BRINGAUTO_SYSTEM_DEP) - INCLUDE("cmake/Dependencies.cmake") - IF (BRINGAUTO_GET_PACKAGES_ONLY) - RETURN() - ENDIF () -ENDIF () +INCLUDE("cmake/Dependencies.cmake") FIND_PACKAGE(nlohmann_json 3.10.5 REQUIRED) FIND_PACKAGE(fleet-protocol-interface 2.1.0 REQUIRED) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index c8487bf..ada019e 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -1,15 +1,17 @@ -SET(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE) +find_package(BANlohmannJson REQUIRED) +# fleet-protocol-interface's internal protobuf fetch is a no-op under our +# FindCMLIB.cmake shim (BA_PACKAGE_LIBRARY does nothing) — resolve protobuf::libprotobuf +# ourselves first so FindBAFleetProtocolInterface.cmake's link-libraries fixup has +# a real target to attach to. Same fix BAF-1706 needed in external-server-cpp. +find_package(BAProtobuf REQUIRED) +find_package(BAFleetProtocolInterface REQUIRED) +find_package(BAAeron REQUIRED) +find_package(BAAsyncFunctionExecution REQUIRED) +find_package(BAFleetProtocolCpp REQUIRED) -BA_PACKAGE_LIBRARY(nlohmann-json v3.12.0 NO_DEBUG ON) -BA_PACKAGE_LIBRARY(fleet-protocol-cpp v1.2.0) -BA_PACKAGE_LIBRARY(async-function-execution v1.0.0) -BA_PACKAGE_LIBRARY(aeron v1.48.6) -BA_PACKAGE_LIBRARY(fleet-protocol-interface v2.1.0 NO_DEBUG ON) - -IF (FLEET_PROTOCOL_BUILD_EXTERNAL_SERVER) - BA_PACKAGE_LIBRARY(fleet-http-client-shared v2.0.2) - BA_PACKAGE_LIBRARY(boost v1.86.0) - BA_PACKAGE_LIBRARY(cpprestsdk v2.10.20) - BA_PACKAGE_LIBRARY(zlib v1.3.2) - -ENDIF () +if (FLEET_PROTOCOL_BUILD_EXTERNAL_SERVER) + find_package(BABoost REQUIRED) + find_package(BAZlib REQUIRED) + find_package(BACppRestSdk REQUIRED) + find_package(BAFleetHttpClient REQUIRED) +endif () diff --git a/cmake/FindBAAeron.cmake b/cmake/FindBAAeron.cmake new file mode 100644 index 0000000..a3a5e97 --- /dev/null +++ b/cmake/FindBAAeron.cmake @@ -0,0 +1,70 @@ +include_guard(GLOBAL) + +# Provides: aeron (imported target from aeron cmake package) +# Resolution order: in-scope target → system config package → FetchContent source build. + +if(TARGET aeron) + set(BAAeron_FOUND TRUE) + return() +endif() + +if(aeron_DIR MATCHES "${CMAKE_BINARY_DIR}") + unset(aeron_DIR CACHE) +endif() +find_package(aeron QUIET CONFIG) +if(aeron_FOUND) + message(STATUS "[BA] aeron: found via system package") + set(BAAeron_FOUND TRUE) + return() +endif() + +message(STATUS "[BA] aeron: system package not found, fetching via FetchContent") +include(FetchContent) +set(AERON_BUILD_SAMPLES OFF CACHE BOOL "" FORCE) +set(AERON_TESTS OFF CACHE BOOL "" FORCE) +set(AERON_UNIT_TESTS OFF CACHE BOOL "" FORCE) +set(AERON_SYSTEM_TESTS OFF CACHE BOOL "" FORCE) +set(AERON_INSTALL_TARGETS OFF CACHE BOOL "" FORCE) +# Archive API requires Java for code generation; disable it. +# Driver (C media driver) IS needed — async-function-execution links aeron::aeron_driver. +set(BUILD_AERON_ARCHIVE_API OFF CACHE BOOL "" FORCE) +# OVERRIDE_FIND_PACKAGE: intercepts direct find_package(aeron ...) calls in +# subdirectories so they resolve to this FetchContent copy (name matches case-insensitively). +FetchContent_Declare(aeron + GIT_REPOSITORY https://github.com/aeron-io/aeron.git + GIT_TAG 1.48.6 + GIT_SHALLOW TRUE + OVERRIDE_FIND_PACKAGE) +FetchContent_MakeAvailable(aeron) + +# async-function-execution includes which expects the installed +# header layout (install(DIRECTORY ./ DESTINATION include/aeronmd ...)). +# In a FetchContent build, headers live in aeron-driver/src/main/c/ with no aeronmd/ +# subdirectory. Create a shim include dir containing an aeronmd/ symlink so the header +# resolves without running cmake --install. +set(_aeron_driver_c "${aeron_SOURCE_DIR}/aeron-driver/src/main/c") +set(_aeron_inc_shim "${aeron_BINARY_DIR}/include-shim") +file(MAKE_DIRECTORY "${_aeron_inc_shim}") +if(NOT EXISTS "${_aeron_inc_shim}/aeronmd") + file(CREATE_LINK "${_aeron_driver_c}" "${_aeron_inc_shim}/aeronmd" SYMBOLIC) +endif() +target_include_directories(aeron_driver PUBLIC + "$") +target_include_directories(aeron_driver_static PUBLIC + "$") + +# Install shared aeron libraries so the external-server-cpp binary can find them +# at runtime via its RPATH ($ORIGIN/../lib). AERON_INSTALL_TARGETS=OFF skips +# aeron's own install targets, so we register them explicitly here. +foreach(_aeron_tgt aeron aeron_client_shared aeron_driver) + if(TARGET ${_aeron_tgt}) + get_target_property(_aeron_ttype ${_aeron_tgt} TYPE) + if(_aeron_ttype STREQUAL "SHARED_LIBRARY") + install(TARGETS ${_aeron_tgt} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + endif() +endforeach() +unset(_aeron_tgt) +unset(_aeron_ttype) + +set(BAAeron_FOUND TRUE) diff --git a/cmake/FindBAAsyncFunctionExecution.cmake b/cmake/FindBAAsyncFunctionExecution.cmake new file mode 100644 index 0000000..c312d42 --- /dev/null +++ b/cmake/FindBAAsyncFunctionExecution.cmake @@ -0,0 +1,52 @@ +include_guard(GLOBAL) + +# Provides: async-function-execution-shared::async-function-execution-shared +# Resolution order: in-scope target → system config package → FetchContent source build. +# Note: async-function-execution uses cmlib internally; FindCMLIB.cmake shim handles it. + +if(TARGET async-function-execution-shared::async-function-execution-shared) + set(BAAsyncFunctionExecution_FOUND TRUE) + return() +endif() + +if(async-function-execution-shared_DIR MATCHES "${CMAKE_BINARY_DIR}") + unset(async-function-execution-shared_DIR CACHE) +endif() +find_package(async-function-execution-shared QUIET CONFIG) +if(async-function-execution-shared_FOUND) + message(STATUS "[BA] async-function-execution: found via config package") + set(BAAsyncFunctionExecution_FOUND TRUE) + return() +endif() + +message(STATUS "[BA] async-function-execution: not found locally, fetching via FetchContent") +include(FetchContent) +set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../async-function-execution/CMakeLists.txt") + set(FETCHCONTENT_SOURCE_DIR_ASYNC_FUNCTION_EXECUTION + "${CMAKE_CURRENT_SOURCE_DIR}/../async-function-execution" CACHE PATH "" FORCE) +endif() +FetchContent_Declare(async_function_execution + GIT_REPOSITORY https://github.com/bringauto/async-function-execution.git + GIT_TAG v1.0.0 + GIT_SHALLOW TRUE) +FetchContent_MakeAvailable(async_function_execution) +# CMDEF_ADD_LIBRARY creates async-function-execution-shared; create the namespaced alias. +if(TARGET async-function-execution-shared + AND NOT TARGET async-function-execution-shared::async-function-execution-shared) + add_library(async-function-execution-shared::async-function-execution-shared + ALIAS async-function-execution-shared) +endif() + +# Install the shared library so the binary can find it via RPATH at runtime. +# CMDEF_INSTALL() is a no-op in our shim, so we register the install rule here. +if(TARGET async-function-execution-shared) + get_target_property(_afe_ttype async-function-execution-shared TYPE) + if(_afe_ttype STREQUAL "SHARED_LIBRARY") + install(TARGETS async-function-execution-shared + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + unset(_afe_ttype) +endif() + +set(BAAsyncFunctionExecution_FOUND TRUE) diff --git a/cmake/FindBABoost.cmake b/cmake/FindBABoost.cmake new file mode 100644 index 0000000..0504846 --- /dev/null +++ b/cmake/FindBABoost.cmake @@ -0,0 +1,52 @@ +# CMake 4.x removed FindBoost.cmake (CMP0167) — always use CONFIG mode. +if(POLICY CMP0167) + cmake_policy(SET CMP0167 NEW) +endif() + +# Provides: Boost:: targets matching requested components. +# No include_guard — callers may request different components. +find_package(Boost 1.86 CONFIG QUIET COMPONENTS ${BABoost_FIND_COMPONENTS}) +if(Boost_FOUND) + set(BABoost_FOUND TRUE) + return() +endif() + +message(STATUS "[BA] Boost 1.86 config package not found, fetching via FetchContent") +include(FetchContent) + +# BOOST_INCLUDE_LIBRARIES controls which Boost libraries are built. +# List all components used by the external-server variant's HTTP client stack +# (fleet-http-client-shared -> cpprestsdk) here so that the first +# FetchContent_MakeAvailable call (whichever component triggers it) builds all +# of them — subsequent calls are no-ops and cannot extend the component list. +# OVERRIDE_FIND_PACKAGE (CMake 3.24+) makes the direct FIND_PACKAGE(Boost CONFIG ...) +# call in CMakeLists.txt resolve to this FetchContent version automatically. +set(BOOST_INCLUDE_LIBRARIES + regex date_time atomic random chrono system filesystem thread asio uuid) +set(BOOST_ENABLE_PYTHON OFF) +set(BOOST_ENABLE_MPI OFF) +set(BUILD_SHARED_LIBS OFF) + +FetchContent_Declare(Boost + URL https://github.com/boostorg/boost/releases/download/boost-1.86.0/boost-1.86.0-cmake.tar.gz + DOWNLOAD_EXTRACT_TIMESTAMP TRUE + OVERRIDE_FIND_PACKAGE) +FetchContent_MakeAvailable(Boost) + +# Boost's cmake config does NOT set Boost_LIBRARIES or Boost_INCLUDE_DIR — +# those are FindBoost.cmake (module-mode) variables. The modules' CMakeLists.txt +# explicitly link against Boost:: targets, but set these too in case +# any consumer still expects the module-mode variables. +set(Boost_LIBRARIES + Boost::regex + Boost::date_time + Boost::atomic + Boost::random + Boost::chrono + Boost::system + Boost::filesystem + Boost::thread + Boost::asio + Boost::uuid) +set(Boost_INCLUDE_DIR "") +set(BABoost_FOUND TRUE) diff --git a/cmake/FindBACppRestSdk.cmake b/cmake/FindBACppRestSdk.cmake new file mode 100644 index 0000000..a5318e1 --- /dev/null +++ b/cmake/FindBACppRestSdk.cmake @@ -0,0 +1,47 @@ +include_guard(GLOBAL) + +# Provides: cpprestsdk::cpprest +# Resolution order: in-scope target → system config package → FetchContent source build. +# Uses the BringAuto fork (github.com/bringauto/cpprestsdk) — vanilla cpprestsdk only +# goes up to v2.10.19, so the v2.10.20 tag pinned by the old cmlib Dependencies.cmake +# confirms this is the fork, not upstream Microsoft/cpprestsdk. + +if(TARGET cpprestsdk::cpprest) + set(BACppRestSdk_FOUND TRUE) + return() +endif() + +if(cpprestsdk_DIR MATCHES "${CMAKE_BINARY_DIR}") + unset(cpprestsdk_DIR CACHE) +endif() +find_package(cpprestsdk QUIET CONFIG) +if(cpprestsdk_FOUND) + message(STATUS "[BA] cpprestsdk: found via system package") + set(BACppRestSdk_FOUND TRUE) + return() +endif() + +message(STATUS "[BA] cpprestsdk: not found locally, fetching via FetchContent") +include(FetchContent) +set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) +# The bundled websocketpp fails to compile against GCC 13's stricter parsing of +# template-id destructors; the module only needs plain HTTP polling, not websockets. +set(CPPREST_EXCLUDE_WEBSOCKETS ON CACHE BOOL "" FORCE) +set(WERROR OFF CACHE BOOL "" FORCE) +set(BUILD_SAMPLES OFF CACHE BOOL "" FORCE) +set(BUILD_TESTS OFF CACHE BOOL "" FORCE) +# OVERRIDE_FIND_PACKAGE: FetchContent_Declare's name matches the plain +# FIND_PACKAGE(cpprestsdk ...) call in CMakeLists.txt, so it intercepts it directly. +FetchContent_Declare(cpprestsdk + GIT_REPOSITORY https://github.com/bringauto/cpprestsdk.git + GIT_TAG v2.10.20 + GIT_SHALLOW TRUE + OVERRIDE_FIND_PACKAGE) +FetchContent_MakeAvailable(cpprestsdk) +# cpprestsdk's build tree only defines the raw "cpprest" target — the +# namespaced "cpprestsdk::cpprest" alias normally comes from its install-export, +# which FetchContent bypasses. Create it manually. +if(TARGET cpprest AND NOT TARGET cpprestsdk::cpprest) + add_library(cpprestsdk::cpprest ALIAS cpprest) +endif() +set(BACppRestSdk_FOUND TRUE) diff --git a/cmake/FindBAFleetHttpClient.cmake b/cmake/FindBAFleetHttpClient.cmake new file mode 100644 index 0000000..75cb52e --- /dev/null +++ b/cmake/FindBAFleetHttpClient.cmake @@ -0,0 +1,61 @@ +include_guard(GLOBAL) + +# Provides: fleet-http-client-shared::fleet-http-client-shared +# Resolution order: in-scope target → system config package → FetchContent source build. +# Repo is named "fleet-http-client" but (like the other BringAuto cmlib packages) +# exports a CMake target "fleet-http-client-shared" via CMDEF_ADD_LIBRARY +# (LIBRARY_GROUP "fleet-http-client" + TYPE SHARED). It uses cmlib internally, +# so FindCMLIB.cmake must be on CMAKE_MODULE_PATH before this fetch, and it needs +# cpprestsdk/Boost/ZLIB findable already — declare those first in Dependencies.cmake. + +if(TARGET fleet-http-client-shared::fleet-http-client-shared) + set(BAFleetHttpClient_FOUND TRUE) + return() +endif() + +if(fleet-http-client-shared_DIR MATCHES "${CMAKE_BINARY_DIR}") + unset(fleet-http-client-shared_DIR CACHE) +endif() +find_package(fleet-http-client-shared QUIET CONFIG) +if(fleet-http-client-shared_FOUND) + message(STATUS "[BA] fleet-http-client: found via config package") + set(BAFleetHttpClient_FOUND TRUE) + return() +endif() + +message(STATUS "[BA] fleet-http-client: not found locally, fetching via FetchContent") +include(FetchContent) +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../fleet-http-client/CMakeLists.txt") + set(FETCHCONTENT_SOURCE_DIR_FLEET_HTTP_CLIENT_SHARED + "${CMAKE_CURRENT_SOURCE_DIR}/../fleet-http-client" CACHE PATH "" FORCE) +endif() +FetchContent_Declare(fleet_http_client_shared + GIT_REPOSITORY https://github.com/bringauto/fleet-http-client.git + GIT_TAG v2.0.2 + GIT_SHALLOW TRUE) +FetchContent_MakeAvailable(fleet_http_client_shared) +# CMDEF_ADD_LIBRARY creates the unnamespaced fleet-http-client-shared target. +# The module's own CMakeLists.txt later calls TARGET_LINK_LIBRARIES a second +# time on the *namespaced* target to bolt on Boost/ZLIB (its "obsolete +# cpprestsdk cmake export package" workaround) — an ALIAS can't receive that +# (CMake forbids target_link_libraries on ALIAS targets), so forward via an +# IMPORTED INTERFACE library instead, which can. +if(TARGET fleet-http-client-shared + AND NOT TARGET fleet-http-client-shared::fleet-http-client-shared) + add_library(fleet-http-client-shared::fleet-http-client-shared INTERFACE IMPORTED) + target_link_libraries(fleet-http-client-shared::fleet-http-client-shared + INTERFACE fleet-http-client-shared) +endif() + +# Install the shared library so consumers can find it via RPATH at runtime. +# CMDEF_INSTALL() is a no-op in our shim, so register the install rule here. +if(TARGET fleet-http-client-shared) + get_target_property(_fhc_ttype fleet-http-client-shared TYPE) + if(_fhc_ttype STREQUAL "SHARED_LIBRARY") + install(TARGETS fleet-http-client-shared + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + unset(_fhc_ttype) +endif() + +set(BAFleetHttpClient_FOUND TRUE) diff --git a/cmake/FindBAFleetProtocolCpp.cmake b/cmake/FindBAFleetProtocolCpp.cmake new file mode 100644 index 0000000..52f49e4 --- /dev/null +++ b/cmake/FindBAFleetProtocolCpp.cmake @@ -0,0 +1,39 @@ +include_guard(GLOBAL) + +# Provides: fleet-protocol-cxx-helpers-static::fleet-protocol-cxx-helpers-static +# Resolution order: in-scope target → system config package → FetchContent source build. +# Note: fleet-protocol-cpp uses cmlib internally; FindCMLIB.cmake shim handles it. + +if(TARGET fleet-protocol-cxx-helpers-static::fleet-protocol-cxx-helpers-static) + set(BAFleetProtocolCpp_FOUND TRUE) + return() +endif() + +if(fleet-protocol-cxx-helpers-static_DIR MATCHES "${CMAKE_BINARY_DIR}") + unset(fleet-protocol-cxx-helpers-static_DIR CACHE) +endif() +find_package(fleet-protocol-cxx-helpers-static QUIET CONFIG) +if(fleet-protocol-cxx-helpers-static_FOUND) + message(STATUS "[BA] fleet-protocol-cpp: found via config package") + set(BAFleetProtocolCpp_FOUND TRUE) + return() +endif() + +message(STATUS "[BA] fleet-protocol-cpp: not found locally, fetching via FetchContent") +include(FetchContent) +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../fleet-protocol-cpp/CMakeLists.txt") + set(FETCHCONTENT_SOURCE_DIR_FLEET_PROTOCOL_CPP + "${CMAKE_CURRENT_SOURCE_DIR}/../fleet-protocol-cpp" CACHE PATH "" FORCE) +endif() +FetchContent_Declare(fleet_protocol_cpp + GIT_REPOSITORY https://github.com/bringauto/fleet-protocol-cpp.git + GIT_TAG v1.2.0 + GIT_SHALLOW TRUE) +FetchContent_MakeAvailable(fleet_protocol_cpp) +# CMDEF_ADD_LIBRARY creates fleet-protocol-cxx-helpers-static; create the namespaced alias. +if(TARGET fleet-protocol-cxx-helpers-static + AND NOT TARGET fleet-protocol-cxx-helpers-static::fleet-protocol-cxx-helpers-static) + add_library(fleet-protocol-cxx-helpers-static::fleet-protocol-cxx-helpers-static + ALIAS fleet-protocol-cxx-helpers-static) +endif() +set(BAFleetProtocolCpp_FOUND TRUE) diff --git a/cmake/FindBAFleetProtocolInterface.cmake b/cmake/FindBAFleetProtocolInterface.cmake new file mode 100644 index 0000000..46dc506 --- /dev/null +++ b/cmake/FindBAFleetProtocolInterface.cmake @@ -0,0 +1,75 @@ +include_guard(GLOBAL) + +# Provides: fleet-protocol-interface::{common-headers-interface, +# module-maintainer-external-server-interface, protobuf-cpp-interface} +# Resolution order: in-scope target → system config package → FetchContent source build. +# Note: fleet-protocol uses cmlib internally; FindCMLIB.cmake shim handles it. + +if(TARGET fleet-protocol-interface::common-headers-interface) + set(BAFleetProtocolInterface_FOUND TRUE) + return() +endif() + +if(fleet-protocol-interface_DIR MATCHES "${CMAKE_BINARY_DIR}") + unset(fleet-protocol-interface_DIR CACHE) +endif() +find_package(fleet-protocol-interface QUIET CONFIG) +if(fleet-protocol-interface_FOUND) + message(STATUS "[BA] fleet-protocol-interface: found via config package") + set(BAFleetProtocolInterface_FOUND TRUE) + return() +endif() + +message(STATUS "[BA] fleet-protocol-interface: not found locally, fetching via FetchContent") +include(FetchContent) +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../fleet-protocol/CMakeLists.txt") + set(FETCHCONTENT_SOURCE_DIR_FLEET_PROTOCOL_INTERFACE + "${CMAKE_CURRENT_SOURCE_DIR}/../fleet-protocol" CACHE PATH "" FORCE) +endif() +FetchContent_Declare(fleet_protocol_interface + GIT_REPOSITORY https://github.com/bringauto/fleet-protocol.git + GIT_TAG v2.1.0 + GIT_SHALLOW TRUE) +FetchContent_MakeAvailable(fleet_protocol_interface) +# fleet-protocol's protobuf CMakeLists.txt omits LINK_LIBRARIES from CMDEF_ADD_LIBRARY, +# so protobuf headers are not on the compile path for ExternalProtocol.pb.cc. +# Inject the link dependency explicitly so protobuf::libprotobuf's include dirs propagate. +if(TARGET protobuf-cpp-interface AND TARGET protobuf::libprotobuf) + target_link_libraries(protobuf-cpp-interface PUBLIC protobuf::libprotobuf) +endif() +# When cmlib installs fleet-protocol, every sub-library's headers land under one +# shared install prefix's include/, so common-headers-interface alone ends up +# exposing every header regardless of which specific interface a consumer linked. +# FetchContent keeps each sub-library's include dir separate (its own build tree), +# so replicate the merged layout by adding every sub-library's include dir to +# common-headers-interface directly — consumers that only link common-headers-interface +# (e.g. a module's own source files needing module_manager.h) still find everything. +if(TARGET common-headers-interface) + foreach(_fp_extra_inc + lib/module_gateway/include + lib/internal_client/include + lib/module_maintainer/module_gateway/include + lib/module_maintainer/external_server/include) + if(EXISTS "${fleet_protocol_interface_SOURCE_DIR}/${_fp_extra_inc}") + target_include_directories(common-headers-interface INTERFACE + "$") + endif() + endforeach() + unset(_fp_extra_inc) +endif() +# CMDEF_ADD_LIBRARY creates unnamespaced targets; create fleet-protocol-interface:: aliases +# so that downstream cmake find_package consumers can use the expected namespaced form. +foreach(_fp_iface_target + common-headers-interface + internal-client-interface + module-gateway-interface + module-maintainer-module-gateway-interface + module-maintainer-external-server-interface + protobuf-cpp-interface) + if(TARGET ${_fp_iface_target} + AND NOT TARGET fleet-protocol-interface::${_fp_iface_target}) + add_library(fleet-protocol-interface::${_fp_iface_target} + ALIAS ${_fp_iface_target}) + endif() +endforeach() +set(BAFleetProtocolInterface_FOUND TRUE) diff --git a/cmake/FindBANlohmannJson.cmake b/cmake/FindBANlohmannJson.cmake new file mode 100644 index 0000000..3b909a0 --- /dev/null +++ b/cmake/FindBANlohmannJson.cmake @@ -0,0 +1,33 @@ +include_guard(GLOBAL) + +# Provides: nlohmann_json::nlohmann_json +# Resolution order: in-scope target → system config package → FetchContent source build. + +if(TARGET nlohmann_json::nlohmann_json) + set(BANlohmannJson_FOUND TRUE) + return() +endif() + +if(nlohmann_json_DIR MATCHES "${CMAKE_BINARY_DIR}") + unset(nlohmann_json_DIR CACHE) +endif() +find_package(nlohmann_json 3.10.5 QUIET CONFIG) +if(nlohmann_json_FOUND) + message(STATUS "[BA] nlohmann_json: found via system package") + set(BANlohmannJson_FOUND TRUE) + return() +endif() + +message(STATUS "[BA] nlohmann_json: not found locally, fetching via FetchContent") +include(FetchContent) +set(JSON_BuildTests OFF CACHE BOOL "" FORCE) +set(JSON_Install ON CACHE BOOL "" FORCE) +# OVERRIDE_FIND_PACKAGE: FetchContent_Declare's name matches the plain +# FIND_PACKAGE(nlohmann_json ...) call in CMakeLists.txt, so it intercepts it directly. +FetchContent_Declare(nlohmann_json + GIT_REPOSITORY https://github.com/nlohmann/json.git + GIT_TAG v3.12.0 + GIT_SHALLOW TRUE + OVERRIDE_FIND_PACKAGE) +FetchContent_MakeAvailable(nlohmann_json) +set(BANlohmannJson_FOUND TRUE) diff --git a/cmake/FindBAProtobuf.cmake b/cmake/FindBAProtobuf.cmake new file mode 100644 index 0000000..343ebf8 --- /dev/null +++ b/cmake/FindBAProtobuf.cmake @@ -0,0 +1,33 @@ +include_guard(GLOBAL) + +# Provides: protobuf::libprotobuf +# Resolution order: in-scope target → system config package → FetchContent source build. + +if(TARGET protobuf::libprotobuf) + set(BAProtobuf_FOUND TRUE) + return() +endif() + +if(Protobuf_DIR MATCHES "${CMAKE_BINARY_DIR}") + unset(Protobuf_DIR CACHE) +endif() +find_package(Protobuf QUIET) +if(Protobuf_FOUND) + message(STATUS "[BA] Protobuf: found via system package") + set(BAProtobuf_FOUND TRUE) + return() +endif() + +message(STATUS "[BA] Protobuf: system package not found, fetching via FetchContent") +include(FetchContent) +set(protobuf_BUILD_TESTS OFF CACHE BOOL "" FORCE) +set(protobuf_INSTALL OFF CACHE BOOL "" FORCE) +# OVERRIDE_FIND_PACKAGE: "protobuf" matches "Protobuf" case-insensitively, so +# subsequent find_package(Protobuf ...) calls in subdirectories resolve here. +FetchContent_Declare(protobuf + GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git + GIT_TAG v3.21.12 + GIT_SHALLOW TRUE + OVERRIDE_FIND_PACKAGE) +FetchContent_MakeAvailable(protobuf) +set(BAProtobuf_FOUND TRUE) diff --git a/cmake/FindBAZlib.cmake b/cmake/FindBAZlib.cmake new file mode 100644 index 0000000..99a5624 --- /dev/null +++ b/cmake/FindBAZlib.cmake @@ -0,0 +1,47 @@ +include_guard(GLOBAL) + +# Provides: ZLIB::ZLIB +# Resolution order: in-scope target → system package → FetchContent source build. +# The bringauto/cpp-build-environment image has no libz-dev, so this normally +# falls through to FetchContent (upstream zlib has a v1.3.2 tag, matching the +# old cmlib pin). + +if(TARGET ZLIB::ZLIB) + set(BAZlib_FOUND TRUE) + return() +endif() + +find_package(ZLIB QUIET) +if(ZLIB_FOUND) + message(STATUS "[BA] zlib: found via system package") + set(BAZlib_FOUND TRUE) + return() +endif() + +message(STATUS "[BA] zlib: system package not found, fetching via FetchContent") +include(FetchContent) +set(ZLIB_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) +FetchContent_Declare(zlib + GIT_REPOSITORY https://github.com/madler/zlib.git + GIT_TAG v1.3.2 + GIT_SHALLOW TRUE + OVERRIDE_FIND_PACKAGE) +FetchContent_MakeAvailable(zlib) + +# zlib's CMakeLists.txt creates unnamespaced "zlib"/"zlibstatic" targets, not +# the ZLIB::ZLIB imported target that FindZLIB.cmake (module mode) normally +# provides. Alias the static target since BUILD_SHARED_LIBS is forced OFF. +if(NOT TARGET ZLIB::ZLIB) + if(TARGET zlibstatic) + add_library(ZLIB::ZLIB ALIAS zlibstatic) + elseif(TARGET zlib) + add_library(ZLIB::ZLIB ALIAS zlib) + endif() +endif() +if(TARGET zlibstatic) + target_include_directories(zlibstatic PUBLIC + "$" + "$") +endif() + +set(BAZlib_FOUND TRUE) diff --git a/cmake/FindCMLIB.cmake b/cmake/FindCMLIB.cmake new file mode 100644 index 0000000..7c1deb9 --- /dev/null +++ b/cmake/FindCMLIB.cmake @@ -0,0 +1,106 @@ +# Compatibility shim replacing cmlib for BringAuto deps fetched via FetchContent. +# Satisfies: FIND_PACKAGE(CMLIB COMPONENTS CMDEF CMUTIL STORAGE REQUIRED) +# Provides: CMDEF_ADD_LIBRARY, CMDEF_ADD_EXECUTABLE, CMDEF_COMPILE_DEFINITIONS, +# CMDEF_INSTALL, CMDEF_PACKAGE, BA_PACKAGE_LIBRARY, BA_PACKAGE_DEPS_IMPORTED, +# CMCONF_INIT_SYSTEM + +set(CMLIB_FOUND TRUE) +foreach(_comp ${CMLIB_FIND_COMPONENTS}) + set(CMLIB_${_comp}_FOUND TRUE) +endforeach() + +# Variable referenced in RPATH settings by BringAuto CMakeLists files. +set(CMDEF_LIBRARY_INSTALL_DIR "lib") + +if(NOT COMMAND CMDEF_ADD_LIBRARY) + macro(CMDEF_ADD_LIBRARY) + cmake_parse_arguments(_cmdef_al "" + "LIBRARY_GROUP;TYPE;VERSION;SOURCE_BASE_DIRECTORY" + "SOURCES;INCLUDE_DIRECTORIES;INSTALL_INCLUDE_DIRECTORIES;COMPILE_DEFINITIONS;LINK_LIBRARIES" + ${ARGN}) + string(TOLOWER "${_cmdef_al_TYPE}" _cmdef_type_lower) + set(_cmdef_target "${_cmdef_al_LIBRARY_GROUP}-${_cmdef_type_lower}") + # cmake forbids compiled source files on INTERFACE libraries. When TYPE is + # INTERFACE but SOURCES are provided (e.g. fleet-protocol protobuf target), + # create a STATIC library under the same name so sources are compiled. + if("${_cmdef_al_TYPE}" STREQUAL "INTERFACE" AND _cmdef_al_SOURCES) + add_library(${_cmdef_target} STATIC ${_cmdef_al_SOURCES}) + set(_cmdef_al_prop_scope PUBLIC) + elseif("${_cmdef_al_TYPE}" STREQUAL "INTERFACE") + add_library(${_cmdef_target} INTERFACE) + set(_cmdef_al_prop_scope INTERFACE) + else() + add_library(${_cmdef_target} ${_cmdef_al_TYPE} ${_cmdef_al_SOURCES}) + set(_cmdef_al_prop_scope PUBLIC) + endif() + if(_cmdef_al_INCLUDE_DIRECTORIES) + target_include_directories(${_cmdef_target} ${_cmdef_al_prop_scope} ${_cmdef_al_INCLUDE_DIRECTORIES}) + endif() + if(_cmdef_al_COMPILE_DEFINITIONS) + target_compile_definitions(${_cmdef_target} ${_cmdef_al_prop_scope} ${_cmdef_al_COMPILE_DEFINITIONS}) + endif() + if(_cmdef_al_LINK_LIBRARIES) + target_link_libraries(${_cmdef_target} ${_cmdef_al_prop_scope} ${_cmdef_al_LINK_LIBRARIES}) + endif() + endmacro() +endif() + +if(NOT COMMAND CMDEF_ADD_EXECUTABLE) + macro(CMDEF_ADD_EXECUTABLE) + cmake_parse_arguments(_cmdef_ae "" "TARGET;VERSION" "SOURCES" ${ARGN}) + add_executable(${_cmdef_ae_TARGET} ${_cmdef_ae_SOURCES}) + endmacro() +endif() + +if(NOT COMMAND CMDEF_COMPILE_DEFINITIONS) + # First arg is scope (ALL/PUBLIC/PRIVATE), rest are definitions. + macro(CMDEF_COMPILE_DEFINITIONS _cmdef_scope) + foreach(_cmdef_def ${ARGN}) + add_compile_definitions(${_cmdef_def}) + endforeach() + endmacro() +endif() + +if(NOT COMMAND CMDEF_INSTALL) + # Unlike fetched third-party deps (which get their own manual install() rules + # in cmake/FindBA*.cmake), the module's own gateway/external-server .so is + # ONLY installed through this macro — a no-op here would make + # -DBRINGAUTO_INSTALL=ON silently produce an empty install tree for the + # actual deliverable. Do a real install (harmless no-op on INTERFACE + # libraries, which have no artifacts to copy). + macro(CMDEF_INSTALL) + cmake_parse_arguments(_cmdef_inst "" "TARGET;NAMESPACE" "" ${ARGN}) + if(_cmdef_inst_TARGET AND TARGET ${_cmdef_inst_TARGET}) + install(TARGETS ${_cmdef_inst_TARGET} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + unset(_cmdef_inst_TARGET) + unset(_cmdef_inst_NAMESPACE) + endmacro() +endif() + +if(NOT COMMAND CMDEF_PACKAGE) + macro(CMDEF_PACKAGE) + # no-op in FetchContent context + endmacro() +endif() + +if(NOT COMMAND BA_PACKAGE_LIBRARY) + macro(BA_PACKAGE_LIBRARY) + # no-op — parent project provides all packages via FindBA*.cmake + endmacro() +endif() + +if(NOT COMMAND BA_PACKAGE_DEPS_IMPORTED) + macro(BA_PACKAGE_DEPS_IMPORTED) + # no-op + endmacro() +endif() + +if(NOT COMMAND CMCONF_INIT_SYSTEM) + macro(CMCONF_INIT_SYSTEM) + # no-op + endmacro() +endif() diff --git a/cmake/Findasync-function-execution-shared.cmake b/cmake/Findasync-function-execution-shared.cmake new file mode 100644 index 0000000..4ac3341 --- /dev/null +++ b/cmake/Findasync-function-execution-shared.cmake @@ -0,0 +1,4 @@ +# Shim: forward direct find_package(async-function-execution-shared) calls to +# the BA FetchContent wrapper. cmake picks this up via CMAKE_MODULE_PATH. +find_package(BAAsyncFunctionExecution REQUIRED) +set(async-function-execution-shared_FOUND TRUE) diff --git a/cmake/Findfleet-http-client-shared.cmake b/cmake/Findfleet-http-client-shared.cmake new file mode 100644 index 0000000..6e83cbc --- /dev/null +++ b/cmake/Findfleet-http-client-shared.cmake @@ -0,0 +1,4 @@ +# Shim: forward direct find_package(fleet-http-client-shared) calls to the BA +# FetchContent wrapper. cmake picks this up via CMAKE_MODULE_PATH. +find_package(BAFleetHttpClient REQUIRED) +set(fleet-http-client-shared_FOUND TRUE) diff --git a/cmake/Findfleet-protocol-cxx-helpers-static.cmake b/cmake/Findfleet-protocol-cxx-helpers-static.cmake new file mode 100644 index 0000000..37eb336 --- /dev/null +++ b/cmake/Findfleet-protocol-cxx-helpers-static.cmake @@ -0,0 +1,4 @@ +# Shim: forward direct find_package(fleet-protocol-cxx-helpers-static) calls to +# the BA FetchContent wrapper. cmake picks this up via CMAKE_MODULE_PATH. +find_package(BAFleetProtocolCpp REQUIRED) +set(fleet-protocol-cxx-helpers-static_FOUND TRUE) diff --git a/cmake/Findfleet-protocol-interface.cmake b/cmake/Findfleet-protocol-interface.cmake new file mode 100644 index 0000000..6f2f7b4 --- /dev/null +++ b/cmake/Findfleet-protocol-interface.cmake @@ -0,0 +1,4 @@ +# Shim: forward direct find_package(fleet-protocol-interface) calls to the BA +# FetchContent wrapper. cmake picks this up via CMAKE_MODULE_PATH. +find_package(BAFleetProtocolInterface REQUIRED) +set(fleet-protocol-interface_FOUND TRUE) From 17c490a1c0513440373148b73c2a2fa1dc3d5fee Mon Sep 17 00:00:00 2001 From: Martin Burian Date: Tue, 7 Jul 2026 13:41:51 +0200 Subject: [PATCH 2/2] Fix cmake migration: restore CMLIB shim load, propagate package version - CMakeLists.txt dropped FIND_PACKAGE(CMLIB ...) during the FetchContent migration, so cmake/FindCMLIB.cmake was never loaded and CMDEF_ADD_LIBRARY/ CMDEF_INSTALL were undefined -> configure failed immediately. - CMDEF_PACKAGE shim was a no-op and silently dropped VERSION, so cpack always produced 0.1.1 instead of the real module version. --- CMakeLists.txt | 1 + cmake/FindCMLIB.cmake | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c006e41..073cd7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR) PROJECT(transparent_module CXX) LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +FIND_PACKAGE(CMLIB COMPONENTS CMDEF CMUTIL STORAGE REQUIRED) INCLUDE(GNUInstallDirs) SET(CMAKE_BUILD_RPATH_USE_ORIGIN ON) diff --git a/cmake/FindCMLIB.cmake b/cmake/FindCMLIB.cmake index 7c1deb9..0059ef5 100644 --- a/cmake/FindCMLIB.cmake +++ b/cmake/FindCMLIB.cmake @@ -83,7 +83,10 @@ endif() if(NOT COMMAND CMDEF_PACKAGE) macro(CMDEF_PACKAGE) - # no-op in FetchContent context + cmake_parse_arguments(_cmdef_pkg "" "MAIN_TARGET;VERSION" "" ${ARGN}) + if(_cmdef_pkg_VERSION) + set(CPACK_PACKAGE_VERSION "${_cmdef_pkg_VERSION}") + endif() endmacro() endif()