diff --git a/.conan/profiles/linux_aarch64_debug b/.conan/profiles/linux_aarch64_debug index 0af01184..a64bb8f5 100644 --- a/.conan/profiles/linux_aarch64_debug +++ b/.conan/profiles/linux_aarch64_debug @@ -5,3 +5,9 @@ compiler=gcc compiler.version=11 compiler.libcxx=libstdc++11 build_type=Debug + +[env] +CONAN_CMAKE_FIND_ROOT_PATH=/usr/bin/aarch64-linux-gnu +CONAN_CMAKE_SYSROOT=/usr/bin/aarch64-linux-gnu +CC=/usr/bin/aarch64-linux-gnu-gcc +CXX=/usr/bin/aarch64-linux-gnu-g++ diff --git a/.conan/profiles/linux_aarch64_release b/.conan/profiles/linux_aarch64_release index 0cc37f38..d960db94 100644 --- a/.conan/profiles/linux_aarch64_release +++ b/.conan/profiles/linux_aarch64_release @@ -5,3 +5,9 @@ compiler=gcc compiler.version=11 compiler.libcxx=libstdc++11 build_type=Release + +[env] +CONAN_CMAKE_FIND_ROOT_PATH=/usr/bin/aarch64-linux-gnu +CONAN_CMAKE_SYSROOT=/usr/bin/aarch64-linux-gnu +CC=/usr/bin/aarch64-linux-gnu-gcc +CXX=/usr/bin/aarch64-linux-gnu-g++ diff --git a/.conan/profiles/linux_x86_64_debug b/.conan/profiles/linux_x86_64_debug index 50797d4c..c6616e2e 100644 --- a/.conan/profiles/linux_x86_64_debug +++ b/.conan/profiles/linux_x86_64_debug @@ -5,3 +5,9 @@ compiler=gcc compiler.version=11 compiler.libcxx=libstdc++11 build_type=Debug + +[env] +CONAN_CMAKE_FIND_ROOT_PATH=/usr/bin/x86_64-linux-gnu +CONAN_CMAKE_SYSROOT=/usr/bin/x86_64-linux-gnu +CC=/usr/bin/x86_64-linux-gnu-gcc +CXX=/usr/bin/x86_64-linux-gnu-g++ diff --git a/.conan/profiles/linux_x86_64_release b/.conan/profiles/linux_x86_64_release index c823b204..04817f32 100644 --- a/.conan/profiles/linux_x86_64_release +++ b/.conan/profiles/linux_x86_64_release @@ -5,3 +5,9 @@ compiler=gcc compiler.version=11 compiler.libcxx=libstdc++11 build_type=Release + +[env] +CONAN_CMAKE_FIND_ROOT_PATH=/usr/bin/x86_64-linux-gnu +CONAN_CMAKE_SYSROOT=/usr/bin/x86_64-linux-gnu +CC=/usr/bin/x86_64-linux-gnu-gcc +CXX=/usr/bin/x86_64-linux-gnu-g++ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc4c580d..ffd70126 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,10 +34,9 @@ jobs: name: Check Conan package strategy: matrix: - host: ["linux_x86_64"] + host: ["linux_x86_64", "linux_aarch64"] fail-fast: false - steps: - name: Checkout repository uses: actions/checkout@v4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dcd7bc4..d2c28988 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,9 @@ cmake_minimum_required(VERSION 3.16) -set(SDK_STANDALONE ON CACHE BOOL "Build the SDK in standalone mode.") +# set the project name +project(VehicleAppCppSdk CXX) + set(SDK_BUILD_TESTS ON CACHE BOOL "Build the SDK tests.") set(SDK_BUILD_EXAMPLES ON CACHE BOOL "Build the SDK examples.") @@ -26,36 +28,21 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/sdk/include ) -if(SDK_STANDALONE) - # set the project name - project(VehicleAppCppSdk CXX) - - if(STATIC_BUILD) - set(BUILD_SHARED_LIBS OFF) - set(CMAKE_EXE_LINKER_FLAGS "-static") - endif() - - set(BUILD_EXAMPLES CACHE BOOL true) - set(BUILD_TESTS CACHE BOOL true) - find_program(CCACHE_FOUND ccache) +if(STATIC_BUILD) + set(BUILD_SHARED_LIBS OFF) + set(CMAKE_EXE_LINKER_FLAGS "-static") +endif() - if(CCACHE_FOUND) - message("Found ccache installation") - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) - endif() +set(BUILD_EXAMPLES CACHE BOOL true) +set(BUILD_TESTS CACHE BOOL true) - # use conan for dependency management - set(CONAN_BUILD_INFO_FILE ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +find_program(CCACHE_FOUND ccache) - if(NOT EXISTS ${CONAN_BUILD_INFO_FILE}) - message(FATAL_ERROR "Conan build info file missing. Did you run install_dependencies.sh first?") - return() - else() - include(${CONAN_BUILD_INFO_FILE}) - conan_basic_setup(TARGETS) - endif() -endif(SDK_STANDALONE) +if(CCACHE_FOUND) + message("Found ccache installation") + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) +endif() if(SDK_BUILD_TESTS) enable_testing() diff --git a/README.md b/README.md index a5005c51..d7e68cb5 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ The Vehicle App SDK for C++ allows to create `Vehicle Apps` from the [Velocitas * 📁 `include` - the headers which need to be included by users of the SDK * 📁 `src` - contains the source code for the SDK from which the SDK library is built * 📁 `test` - contains the unit test code for the SDK +* 📁 `test_package` - test package for Conan package tests/verification ## Prerequisites diff --git a/build.sh b/build.sh index 5245fc12..264be696 100755 --- a/build.sh +++ b/build.sh @@ -126,20 +126,6 @@ if [ "${GEN_COVERAGE}" == "ON" ]; then CMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} --coverage" fi -mkdir -p build && cd build - -# Expose the PATH of the build-time requirements from Conan to CMake - this is NOT handled by -# any of Conan's CMake generators at the moment, hence we parse the conanbuildinfo.txt which -# is generated and holds these paths. This allows us to always use the protoc and grpc cpp plugin -# of the build system. -BUILD_TOOLS_PATH="" -CONAN_BUILD_TOOLS_PATHS=$(sed '/^PATH=/!d;s/PATH=//g;s/,/\n/g' ./conanbuildinfo.txt | tr -d '[]'\" ) -while read -r p; do - if [[ ! -z "${p// }" ]]; then - BUILD_TOOLS_PATH="$BUILD_TOOLS_PATH;$p" - fi -done < <(echo "$CONAN_BUILD_TOOLS_PATHS") - XCOMPILE_TOOLCHAIN_FILE="" if [[ "${BUILD_ARCH}" != "${HOST_ARCH}" ]]; then echo "Setting up cross compilation toolchain..." @@ -147,16 +133,21 @@ if [[ "${BUILD_ARCH}" != "${HOST_ARCH}" ]]; then fi # Configure CMake and build the project. -cmake --no-warn-unused-cli \ - -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE \ - -DCMAKE_BUILD_TYPE:STRING=${BUILD_VARIANT} \ - -DSTATIC_BUILD:BOOL=${STATIC_BUILD} \ - -DSDK_BUILD_EXAMPLES=${SDK_BUILD_EXAMPLES} \ - -S.. \ - -B../build \ - -G Ninja \ - -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" \ - -DBUILD_TOOLS_PATH:STRING="${BUILD_TOOLS_PATH}" \ - ${XCOMPILE_TOOLCHAIN_FILE} .. -cmake --build . --config ${BUILD_VARIANT} --target ${BUILD_TARGET} -- -cd .. +#cmake --no-warn-unused-cli \ +# -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE \ +# -DCMAKE_BUILD_TYPE:STRING=${BUILD_VARIANT} \ +# -DSTATIC_BUILD:BOOL=${STATIC_BUILD} \ +# -DSDK_BUILD_EXAMPLES=${SDK_BUILD_EXAMPLES} \ +# -S.. \ +# -B../build \ +# -G Ninja \ +# -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" \ +# -DBUILD_TOOLS_PATH:STRING="${BUILD_TOOLS_PATH}" \ +# ${XCOMPILE_TOOLCHAIN_FILE} .. +#cmake --build . --config ${BUILD_VARIANT} --target ${BUILD_TARGET} -- +#cd .. + +conan build \ + -if ./build \ + -bf ./build \ + . diff --git a/conanfile.py b/conanfile.py index 135a9d7d..9e3303a7 100644 --- a/conanfile.py +++ b/conanfile.py @@ -13,14 +13,9 @@ # SPDX-License-Identifier: Apache-2.0 from conans import ConanFile, tools -from conan.tools.cmake import cmake_layout, CMakeToolchain, CMake -import subprocess +from conan.tools.cmake import cmake_layout, CMake import os import re -import subprocess - -from conan.tools.cmake import cmake_layout -from conans import ConanFile, tools @@ -44,27 +39,23 @@ class VehicleAppCppSdkConan(ConanFile): ("libcurl/8.1.2"), ("nlohmann_json/3.11.2"), ("openssl/1.1.1u"), - ("paho-mqtt-c/1.3.9"), + ("paho-mqtt-c/1.3.13"), ("paho-mqtt-cpp/1.2.0"), ("zlib/1.3"), ] - generators = "cmake" + generators = "CMakeToolchain", "CMakeDeps" author = "Robert Bosch GmbH" # Binary configuration settings = "os", "compiler", "build_type", "arch" options = {"shared": [True, False], "examples": [True, False]} - default_options = {"shared": False, "examples": False} + default_options = {"shared": False, "examples": True} exports = "version.txt" # Sources are located in the same place as this recipe, copy them to the recipe exports_sources = ".scripts/common.sh", "build.sh", "install_dependencies.sh", "CMakeLists.txt", "sdk/*", "examples/*", "conanfile.py", ".conan/profiles/*", "version.txt" - options = {"shared": [True, False]} - - default_options = {"shared": True} - def set_version(self): try: git = tools.Git(folder=".") @@ -88,17 +79,17 @@ def set_version(self): def config_options(self): - if self.settings.os == "Linux": + if self.settings.os == "Windows": del self.options.fPIC def layout(self): - cmake_layout(self, src_folder="sdk") + cmake_layout(self) def build(self): cmake = CMake(self) cmake.configure(variables={ - "STATIC_BUILD:BOOL":not self.options["shared"], - "SDK_BUILD_EXAMPLES:BOOL":self.options["examples"] + "STATIC_BUILD:BOOL": "ON" if not self.options.shared else "OFF", + "SDK_BUILD_EXAMPLES:BOOL": "ON" if self.options.examples else "OFF" }) cmake.build() diff --git a/install_dependencies.sh b/install_dependencies.sh index 8f355072..2a317f77 100755 --- a/install_dependencies.sh +++ b/install_dependencies.sh @@ -90,32 +90,10 @@ echo "Build arch ${BUILD_ARCH}" echo "Host arch ${HOST_ARCH}" echo "Building deps ${WHICH_DEPS_TO_BUILD}" -mkdir -p build - -XCOMPILE_PROFILE="" - -if [[ "${BUILD_ARCH}" != "${HOST_ARCH}" ]]; then - echo "Setting up cross compilation toolchain..." - - toolchain=/usr/bin/${HOST_ARCH}-linux-gnu - target_host=${HOST_ARCH}-linux-gnu - cc_compiler=gcc - cxx_compiler=g++ - - export CONAN_CMAKE_FIND_ROOT_PATH=$toolchain - export CONAN_CMAKE_SYSROOT=$toolchain - export CC=$target_host-$cc_compiler - export CXX=$target_host-$cxx_compiler - - XCOMPILE_PROFILE="-pr:b .conan/profiles/linux_${BUILD_ARCH}_${BUILD_VARIANT}" -fi - -# Enable Conan revision handling to enable pinning googleapis recipe revision (see conanfile.py) -export CONAN_REVISIONS_ENABLED=1 - conan install \ + -pr:b .conan/profiles/linux_${BUILD_ARCH}_${BUILD_VARIANT} \ -pr:h .conan/profiles/linux_${HOST_ARCH}_${BUILD_VARIANT} \ - ${XCOMPILE_PROFILE} \ --build "${WHICH_DEPS_TO_BUILD}" \ -of ./build \ - -if ./build . + -if ./build \ + . diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index 13cd3b52..e2291d68 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -12,6 +12,8 @@ # # SPDX-License-Identifier: Apache-2.0 +cmake_minimum_required(VERSION 3.16) + add_subdirectory(proto) add_subdirectory(src) diff --git a/sdk/proto/CMakeLists.txt b/sdk/proto/CMakeLists.txt index b83477ce..0f27c1d0 100644 --- a/sdk/proto/CMakeLists.txt +++ b/sdk/proto/CMakeLists.txt @@ -12,14 +12,14 @@ # # SPDX-License-Identifier: Apache-2.0 +cmake_minimum_required(VERSION 3.16) + file(GLOB_RECURSE PROTO_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.proto) find_program(_gRPC_PROTOBUF_PROTOC_EXECUTABLE protoc REQUIRED - PATHS ${BUILD_TOOLS_PATH} - NO_DEFAULT_PATH) + PATHS ${BUILD_TOOLS_PATH}) find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin REQUIRED - PATHS ${BUILD_TOOLS_PATH} - NO_DEFAULT_PATH) + PATHS ${BUILD_TOOLS_PATH}) set(_gRPC_PROTO_GENS_DIR ${CMAKE_BINARY_DIR}/gens) set(_gRPC_PROTO_SRCS_DIR ${CMAKE_CURRENT_SOURCE_DIR}) @@ -47,11 +47,11 @@ foreach(FILE ${PROTO_FILES}) ${OUTPUT_FILE_PATH_GRPC_MOCK_HDR} ) - set(GENERATE_GRPC_SOURCES FALSE) + set(GENERATE_GRPC_SOURCES OFF) foreach(OUTPUT_FILE ${OUTPUT_FILES}) if(NOT EXISTS ${OUTPUT_FILE}) - set(GENERATE_GRPC_SOURCES TRUE) + set(GENERATE_GRPC_SOURCES ON) message("File does not exist: " ${OUTPUT_FILE}) else() # message("File already exists: " ${OUTPUT_FILE}) @@ -88,6 +88,13 @@ add_library(${TARGET_NAME} STATIC ${PROTO_SRCS} ) +find_package(grpc REQUIRED) +find_package(protobuf REQUIRED) + target_link_libraries(${TARGET_NAME} - CONAN_PKG::grpc + gRPC::grpc + gRPC::grpc++ + protobuf::protobuf ) + +set_property(TARGET ${TARGET_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/sdk/src/CMakeLists.txt b/sdk/src/CMakeLists.txt index 6b5a8ed7..adc25615 100644 --- a/sdk/src/CMakeLists.txt +++ b/sdk/src/CMakeLists.txt @@ -12,8 +12,14 @@ # # SPDX-License-Identifier: Apache-2.0 +cmake_minimum_required(VERSION 3.16) + set(TARGET_NAME "vehicle-app-sdk") +if(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + add_library(${TARGET_NAME} sdk/VehicleApp.cpp sdk/Model.cpp @@ -50,11 +56,17 @@ add_dependencies(${TARGET_NAME} vehicle-app-sdk-generated-grpc ) +find_package(gRPC REQUIRED) +find_package(cpr REQUIRED) +find_package(fmt REQUIRED) +find_package(PahoMqttCpp REQUIRED) +find_package(nlohmann_json REQUIRED) + target_link_libraries(${TARGET_NAME} - CONAN_PKG::grpc - CONAN_PKG::cpr - CONAN_PKG::fmt - CONAN_PKG::paho-mqtt-cpp - CONAN_PKG::nlohmann_json + gRPC::grpc + cpr::cpr + fmt::fmt + PahoMqttCpp::paho-mqttpp3-static + nlohmann_json::nlohmann_json vehicle-app-sdk-generated-grpc ) \ No newline at end of file