From bc6a394108a4e6e7f56f19f409be47ac07420290 Mon Sep 17 00:00:00 2001 From: Andrew Messing Date: Fri, 23 Feb 2024 10:02:23 -0500 Subject: [PATCH 1/8] Added CD GHA --- .devcontainer/Dockerfile.amd64 | 27 ++++++++ .devcontainer/Dockerfile.arm64 | 29 ++++++++ .github/workflows/cd.yml | 121 +++++++++++++++++++++++++++++++++ cpp/CMakeLists.txt | 2 +- docs/cpp/quickstart.md | 6 ++ 5 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/Dockerfile.amd64 create mode 100644 .devcontainer/Dockerfile.arm64 create mode 100644 .github/workflows/cd.yml diff --git a/.devcontainer/Dockerfile.amd64 b/.devcontainer/Dockerfile.amd64 new file mode 100644 index 0000000..2fd89e0 --- /dev/null +++ b/.devcontainer/Dockerfile.amd64 @@ -0,0 +1,27 @@ +FROM ubuntu:22.04 + +RUN apt-get update --fix-missing &&\ + apt-get install -y --no-install-recommends build-essential ca-certificates git g++ pkg-config python3 curl ninja-build tar zip unzip zlib1g-dev libssl-dev wget &&\ + apt-get autoclean &&\ + apt-get autoremove &&\ + apt-get clean &&\ + rm -rf /var/lib/apt/lists/* + +RUN update-ca-certificates + +RUN wget https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3.tar.gz &&\ + tar -xzf cmake-3.28.3.tar.gz &&\ + cd cmake-3.28.3 &&\ + ./configure &&\ + make install &&\ + cd .. &&\ + rm cmake-3.28.3.tar.gz &&\ + rm -r cmake-3.28.3 + +RUN git clone https://github.com/microsoft/vcpkg &&\ + cd vcpkg &&\ + git checkout 3b213864579b6fa686e38715508f7cd41a50900f &&\ + ./bootstrap-vcpkg.sh -disableMetrics &&\ + ./vcpkg install grpc:x64-linux &&\ + ./vcpkg install eigen3:x64-linux &&\ + ./vcpkg install cli11:x64-linux diff --git a/.devcontainer/Dockerfile.arm64 b/.devcontainer/Dockerfile.arm64 new file mode 100644 index 0000000..7f32e6e --- /dev/null +++ b/.devcontainer/Dockerfile.arm64 @@ -0,0 +1,29 @@ +FROM arm64v8/ubuntu:22.04 +SHELL ["/bin/bash", "-c"] + +RUN apt-get update --fix-missing &&\ + apt-get install -y --no-install-recommends build-essential ca-certificates cmake git g++ pkg-config python3 curl ninja-build tar zip unzip zlib1g-dev libssl-dev wget &&\ + apt-get autoclean &&\ + apt-get autoremove &&\ + apt-get clean &&\ + rm -rf /var/lib/apt/lists/* + +RUN update-ca-certificates + +RUN wget https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3.tar.gz &&\ + tar -xzf cmake-3.28.3.tar.gz &&\ + cd cmake-3.28.3 &&\ + ./configure &&\ + make install &&\ + cd .. &&\ + rm cmake-3.28.3.tar.gz &&\ + rm -r cmake-3.28.3 + +RUN git clone https://github.com/microsoft/vcpkg &&\ + cd vcpkg &&\ + git checkout 3b213864579b6fa686e38715508f7cd41a50900f &&\ + export VCPKG_FORCE_SYSTEM_BINARIES=arm &&\ + ./bootstrap-vcpkg.sh -disableMetrics &&\ + ./vcpkg install grpc:arm64-linux &&\ + ./vcpkg install eigen3:arm64-linux &&\ + ./vcpkg install cli11:arm64-linux diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..4ba2429 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,121 @@ +# Commented out due to speed of runners. Uncomment when we get the better ones. + +# # This workflow automatically releases binaries upon tagging. +# name: spot-cpp-sdk CD + +# on: +# push: +# tags: +# - '*' + +# concurrency: +# group: ${{ github.workflow }}-${{ github.ref }} +# cancel-in-progress: true + +# env: +# REGISTRY: ghcr.io +# # github.repository as / +# IMAGE_NAME: bdaiinstitute/spot_cpp_sdk_builder + +# jobs: + # build-docker-image: + # permissions: + # contents: read + # packages: write + # # This is used to complete the identity challenge + # # with sigstore/fulcio when running outside of PRs. + # id-token: write + # strategy: + # fail-fast: false + # matrix: + # config: + # - { arch: "amd64" } + # - { arch: "arm64" } + # name: Build docker image for ${{ matrix.config.arch }} + # runs-on: ubuntu-latest + # steps: + # - name: Checkout repository + # uses: actions/checkout@v4 + + # - name: Set up QEMU # as virtualization is necessary to build container images + # uses: docker/setup-qemu-action@v3 + + # - name: Setup Docker buildx # to workaround: https://github.com/docker/build-push-action/issues/461 + # uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + # - name: Log into registry ${{ env.REGISTRY }} + # uses: docker/login-action@v3 # https://github.com/docker/login-action + # with: + # registry: ${{ env.REGISTRY }} + # username: ${{ github.actor }} + # password: ${{ secrets.GITHUB_TOKEN }} + + # # Extract metadata (tags, labels) for Docker + # # https://github.com/docker/metadata-action + # - name: Extract Docker metadata + # id: meta + # uses: docker/metadata-action@v5 + # with: + # images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}_${{ matrix.config.arch }} + + # - name: Build and push + # uses: docker/build-push-action@v5 # https://github.com/docker/build-push-action + # id: build + # with: + # context: . + # file: .devcontainer/Dockerfile.${{ matrix.config.arch }} + # tags: ${{ steps.meta.outputs.tags }} + # labels: ${{ steps.meta.outputs.labels }} + # cache-from: type=gha + # cache-to: type=gha,mode=max + # push: true + + # build-artifacts: + # strategy: + # fail-fast: false + # matrix: + # config: + # - { arch: "amd64" } + # - { arch: "arm64" } + # name: Build spot-cpp-sdk for ${{ matrix.config.arch }} + # # needs: build-docker-image + # runs-on: ubuntu-latest + # container: + # # env cannot be used here... + # image: ghcr.io/bdaiinstitute/spot_cpp_sdk_builder_${{ matrix.config.arch }}:latest + # steps: + # - name: Checkout repository + # uses: actions/checkout@v4 + + # - name: Build spot-sdk-cpp + # run: | + # cd spot-sdk-cpp/cpp + # mkdir build + # cd build + # cmake ../ -DCMAKE_TOOLCHAIN_FILE=/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=TRUE -DBUILD_CHOREOGRAPHY_LIBS=ON + # make -j2 install package + + # - name: Upload ${{ matrix.config.arch }} artifact + # uses: actions/upload-artifact@v4 + # with: + # name: ${{ matrix.config.arch }}-artifact + # path: '*.deb' + # retention-days: 1 + + # bundle-debians: + # name: Release artifacts + # runs-on: ubuntu-latest + # needs: build-artifacts + # steps: + # - name: Download artifacts + # uses: actions/download-artifact@v4 + # with: + # pattern: '*-artifact' + # merge-multiple: true + + # - name: Release to GitHub + # uses: softprops/action-gh-release@v1 + # with: + # name: Release ${{ github.ref_name }} + # files: '*.deb' + \ No newline at end of file diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 68fac18..9c63857 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -44,7 +44,7 @@ file(GLOB_RECURSE bosdyn_protos_files CONFIGURE_DEPENDS if (bosdyn_protos_files) add_library(bosdyn_api_obj OBJECT ${bosdyn_protos_files}) set_property(TARGET bosdyn_api_obj PROPERTY POSITION_INDEPENDENT_CODE 1) - target_link_libraries(bosdyn_api_obj PUBLIC ${PROTOBUF_LIBRARIES} gRPC::grpc gRPC::grpc++) + target_link_libraries(bosdyn_api_obj PUBLIC protobuf::libprotobuf gRPC::grpc gRPC::grpc++) target_include_directories(bosdyn_api_obj PUBLIC $ $ diff --git a/docs/cpp/quickstart.md b/docs/cpp/quickstart.md index 82fc654..5cf016c 100644 --- a/docs/cpp/quickstart.md +++ b/docs/cpp/quickstart.md @@ -154,6 +154,12 @@ make -j6 install The `make` command generates a lot of deprecation warnings during the compiling of the classes generated from the protobuf definitions. This is expected as the protobuf definitions contain `deprecated` flags for fields that will not be supported in future versions of the SDK. +Build the SDK and generate a debian package using the `make` command below: + +``` +make -j6 install package +``` + **On Windows:** - Open the `sln` file in the build folder in Microsoft Visual Studio. From 9a661601cea451635595bb836e4eff5fd7a46893 Mon Sep 17 00:00:00 2001 From: Andrew Messing Date: Thu, 10 Oct 2024 18:19:39 +0000 Subject: [PATCH 2/8] Working towards depending on apt packages --- .devcontainer/Dockerfile.amd64 | 48 ++-- .devcontainer/Dockerfile.amd64_vcpkg | 27 +++ .devcontainer/build.sh | 2 + .devcontainer/entrypoint.sh | 9 + cpp/.gitignore | 1 + cpp/CMakeLists.txt | 13 +- cpp/cmake/FindgRPC.cmake | 320 +++++++++++++++++++++++++++ 7 files changed, 395 insertions(+), 25 deletions(-) create mode 100644 .devcontainer/Dockerfile.amd64_vcpkg create mode 100755 .devcontainer/build.sh create mode 100755 .devcontainer/entrypoint.sh create mode 100644 cpp/.gitignore create mode 100644 cpp/cmake/FindgRPC.cmake diff --git a/.devcontainer/Dockerfile.amd64 b/.devcontainer/Dockerfile.amd64 index 2fd89e0..659b7c7 100644 --- a/.devcontainer/Dockerfile.amd64 +++ b/.devcontainer/Dockerfile.amd64 @@ -1,27 +1,31 @@ FROM ubuntu:22.04 -RUN apt-get update --fix-missing &&\ - apt-get install -y --no-install-recommends build-essential ca-certificates git g++ pkg-config python3 curl ninja-build tar zip unzip zlib1g-dev libssl-dev wget &&\ - apt-get autoclean &&\ - apt-get autoremove &&\ - apt-get clean &&\ - rm -rf /var/lib/apt/lists/* +RUN apt-get update --fix-missing \ + && apt-get install -y --no-install-recommends \ + build-essential \ + ca-certificates \ + cmake \ + git \ + libeigen3-dev \ + libgrpc++-dev \ + libprotobuf-dev \ + g++ \ + pkg-config \ + protobuf-compiler \ + python3 \ + curl \ + ninja-build \ + tar \ + zip \ + unzip \ + zlib1g-dev \ + libssl-dev \ + wget \ + && apt-get autoclean \ + && apt-get autoremove \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* RUN update-ca-certificates -RUN wget https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3.tar.gz &&\ - tar -xzf cmake-3.28.3.tar.gz &&\ - cd cmake-3.28.3 &&\ - ./configure &&\ - make install &&\ - cd .. &&\ - rm cmake-3.28.3.tar.gz &&\ - rm -r cmake-3.28.3 - -RUN git clone https://github.com/microsoft/vcpkg &&\ - cd vcpkg &&\ - git checkout 3b213864579b6fa686e38715508f7cd41a50900f &&\ - ./bootstrap-vcpkg.sh -disableMetrics &&\ - ./vcpkg install grpc:x64-linux &&\ - ./vcpkg install eigen3:x64-linux &&\ - ./vcpkg install cli11:x64-linux +COPY entrypoint.sh . diff --git a/.devcontainer/Dockerfile.amd64_vcpkg b/.devcontainer/Dockerfile.amd64_vcpkg new file mode 100644 index 0000000..2fd89e0 --- /dev/null +++ b/.devcontainer/Dockerfile.amd64_vcpkg @@ -0,0 +1,27 @@ +FROM ubuntu:22.04 + +RUN apt-get update --fix-missing &&\ + apt-get install -y --no-install-recommends build-essential ca-certificates git g++ pkg-config python3 curl ninja-build tar zip unzip zlib1g-dev libssl-dev wget &&\ + apt-get autoclean &&\ + apt-get autoremove &&\ + apt-get clean &&\ + rm -rf /var/lib/apt/lists/* + +RUN update-ca-certificates + +RUN wget https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3.tar.gz &&\ + tar -xzf cmake-3.28.3.tar.gz &&\ + cd cmake-3.28.3 &&\ + ./configure &&\ + make install &&\ + cd .. &&\ + rm cmake-3.28.3.tar.gz &&\ + rm -r cmake-3.28.3 + +RUN git clone https://github.com/microsoft/vcpkg &&\ + cd vcpkg &&\ + git checkout 3b213864579b6fa686e38715508f7cd41a50900f &&\ + ./bootstrap-vcpkg.sh -disableMetrics &&\ + ./vcpkg install grpc:x64-linux &&\ + ./vcpkg install eigen3:x64-linux &&\ + ./vcpkg install cli11:x64-linux diff --git a/.devcontainer/build.sh b/.devcontainer/build.sh new file mode 100755 index 0000000..84264e9 --- /dev/null +++ b/.devcontainer/build.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +docker run -v ~/spot-cpp-sdk:/spot-cpp-sdk spot_builder /entrypoint.sh diff --git a/.devcontainer/entrypoint.sh b/.devcontainer/entrypoint.sh new file mode 100755 index 0000000..8c193c6 --- /dev/null +++ b/.devcontainer/entrypoint.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +cd /spot-cpp-sdk/cpp +if [ -d build ]; then + rm -r build +fi +mkdir build +cd build +cmake .. -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=TRUE -DBUILD_CHOREOGRAPHY_LIBS=ON +make -j8 install package diff --git a/cpp/.gitignore b/cpp/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/cpp/.gitignore @@ -0,0 +1 @@ +build diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index bfb3a9d..d5c332f 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -7,13 +7,15 @@ # This file is autogenerated. cmake_minimum_required (VERSION 3.10.2) -project (bosdyn VERSION 4.0.3) +project (bosdyn VERSION 4.1.0) + +# Add cmake modules +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") # Dependencies: -find_package(protobuf REQUIRED) +find_package(Protobuf REQUIRED) find_package(Eigen3 REQUIRED) find_package(gRPC REQUIRED) -find_package(CLI11 REQUIRED) find_package(Threads REQUIRED) get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION) include_directories(SYSTEM $) @@ -24,6 +26,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS true) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE) option(BUILD_SHARED_LIBS "Build using shared libraries" ON) option(BUILD_CHOREOGRAPHY_LIBS "Boolean to control whether choreography proto libraries are built" ON) +option(BUILD_EXAMPLES "Boolean to control whether examples are built" OFF) IF (NOT UNIX) SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Build using shared libraries" FORCE) @@ -194,6 +197,9 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bosdyn ### EXAMPLE EXECUTABLES ### +if(BUILD_EXAMPLES) +find_package(CLI11 REQUIRED) + link_directories( ${PROTOBUF_LIB_DIR} ) @@ -260,6 +266,7 @@ write_basic_package_version_file("${VERSION_FILE}" VERSION ${PACKAGE_VERSION} COMPATIBILITY AnyNewerVersion ) +endif() # This defines the instructions to generate a relocatable targets file at install time set(PROJECT_CONFIG_PATH "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") diff --git a/cpp/cmake/FindgRPC.cmake b/cpp/cmake/FindgRPC.cmake new file mode 100644 index 0000000..aa77980 --- /dev/null +++ b/cpp/cmake/FindgRPC.cmake @@ -0,0 +1,320 @@ +# ~~~ +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ~~~ + +#[=======================================================================[.rst: +FindgRPC +-------- + +Locate and configure the ``gRPC`` library. + +The following variables can be set and are optional: + +``gRPC_DEBUG`` + Show debug messages. +``gRPC_USE_STATIC_LIBS`` + Set to ON to force the use of the static libraries. + Default is OFF. + +Defines the following variables: + +``gRPC_FOUND`` + Found the gRPC library +``gRPC_VERSION`` + Version of package found. + +The following ``IMPORTED`` targets are also defined: + +``gRPC::grpc++`` + The gRPC C++ library. +``gRPC::grpc`` + The gRPC C core library. +``gRPC::cpp_plugin`` + The C++ plugin for the Protobuf protoc compiler. + +The following cache variables are also available to set or use: + +Example: + +.. code-block:: cmake + + find_package(gRPC REQUIRED) + add_executable(bar bar.cc) + target_link_libraries(bar PRIVATE gRPC::grpc++) + +#]=======================================================================] + +if (gRPC_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "gRPC_USE_STATIC_LIBS = ${gRPC_USE_STATIC_LIBS}" + " gRPC_FOUND = ${gRPC_FOUND}") +endif () + +# gRPC always requires Thread support. +find_package(Threads REQUIRED) + +# Load the module to find protobuf with proper targets. Do not use +# `find_package()` because we (have to) install this module in non-standard +# locations. +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") +find_package(Protobuf CONFIG QUIET) +if (NOT Protobuf_FOUND) + find_package(Protobuf) +endif () + +# The gRPC::grpc_cpp_plugin target is sometimes defined, but without a +# IMPORTED_LOCATION +function (_grpc_fix_grpc_cpp_plugin_target) + # The target may already exist, do not create it again if it does. + if (NOT TARGET gRPC::grpc_cpp_plugin) + add_executable(gRPC::grpc_cpp_plugin IMPORTED) + endif () + get_target_property(_gRPC_CPP_PLUGIN_EXECUTABLE gRPC::grpc_cpp_plugin + IMPORTED_LOCATION) + if (gRPC_DEBUG) + message( + STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "LOCATION=${_gRPC_CPP_PLUGIN_EXECUTABLE}") + endif () + # Even if the target exists, gRPC CMake support files do not define the + # executable for the imported target (at least they do not in v1.19.1), so + # we need to define it ourselves. + if (NOT _gRPC_CPP_PLUGIN_EXECUTABLE) + find_program(_gRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin + DOC "The gRPC C++ plugin for protoc") + mark_as_advanced(_gRPC_CPP_PLUGIN_EXECUTABLE) + if (_gRPC_CPP_PLUGIN_EXECUTABLE) + set_property( + TARGET gRPC::grpc_cpp_plugin + PROPERTY IMPORTED_LOCATION ${_gRPC_CPP_PLUGIN_EXECUTABLE}) + else () + set(gRPC_FOUND "grpc_cpp_plugin-NOTFOUND") + endif () + endif () +endfunction () + +# First try to use the `gRPCConfig.cmake` or `grpc-config.cmake` file if it was +# installed. This is common on systems (or package managers) where gRPC was +# compiled and installed with `CMake`. + +find_package(gRPC NO_MODULE QUIET) + +if (gRPC_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "NO_MODULE result gRPC_FOUND = ${gRPC_FOUND}") +endif () + +if (gRPC_FOUND) + _grpc_fix_grpc_cpp_plugin_target() + return() +endif () + +include(SelectLibraryConfigurations) + +# Internal function: search for normal library as well as a debug one if the +# debug one is specified also include debug/optimized keywords in *_LIBRARIES +# variable +function (_gRPC_find_library name filename) + if (${name}_LIBRARY) + # Use result recorded by a previous call. + return() + else () + find_library(${name}_LIBRARY_RELEASE NAMES ${filename}) + mark_as_advanced(${name}_LIBRARY_RELEASE) + + find_library(${name}_LIBRARY_DEBUG NAMES ${filename}d ${filename}) + mark_as_advanced(${name}_LIBRARY_DEBUG) + + select_library_configurations(${name}) + + if (gRPC_DEBUG) + message( + STATUS + "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "${name} ${filename} RELEASE=${${name}_LIBRARY}" + " DEBUG=${${name}_LIBRARY_DEBUG} DEFAULT=${${name}_LIBRARY}" + ) + endif () + + set(${name}_LIBRARY + "${${name}_LIBRARY}" + PARENT_SCOPE) + endif () +endfunction () + +# +# Main +# + +# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES +if (_gRPC_USE_STATIC_LIBS) + set(_gRPC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + if (WIN32) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + else () + set(CMAKE_FIND_LIBRARY_SUFFIXES .a) + endif () +endif () + +_grpc_find_library(_gRPC_grpc grpc) +_grpc_find_library(_gRPC_grpc++ grpc++) + +if (NOT _gRPC_INCLUDE_DIR) + find_path(_gRPC_INCLUDE_DIR grpcpp/grpcpp.h) + mark_as_advanced(_gRPC_INCLUDE_DIR) +endif () + +if (gRPC_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + " _gRPC_grpc_LIBRARY = ${_gRPC_grpc_LIBRARY}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + " _gRPC_grpc++_LIBRARY = ${_gRPC_grpc++_LIBRARY}") + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + " _gRPC_INCLUDE_DIR = ${_gRPC_INCLUDE_DIR}") +endif () + +if (_gRPC_grpc_LIBRARY) + if (NOT TARGET gRPC::grpc) + add_library(gRPC::grpc UNKNOWN IMPORTED) + set_target_properties( + gRPC::grpc PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${_gRPC_INCLUDE_DIR}") + if (EXISTS "${_gRPC_grpc_LIBRARY}") + set_target_properties(gRPC::grpc PROPERTIES IMPORTED_LOCATION + "${_gRPC_grpc_LIBRARY}") + endif () + if (EXISTS "${_gRPC_grpc_LIBRARY_RELEASE}") + set_property( + TARGET gRPC::grpc + APPEND + PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties( + gRPC::grpc PROPERTIES IMPORTED_LOCATION_RELEASE + "${_gRPC_grpc_LIBRARY_RELEASE}") + endif () + if (EXISTS "${_gRPC_grpc_LIBRARY_DEBUG}") + set_property( + TARGET gRPC::grpc + APPEND + PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties( + gRPC::grpc PROPERTIES IMPORTED_LOCATION_DEBUG + "${_gRPC_grpc_LIBRARY_DEBUG}") + endif () + set_property( + TARGET gRPC::grpc + APPEND + PROPERTY INTERFACE_LINK_LIBRARIES protobuf::libprotobuf + Threads::Threads) + endif () +endif () + +if (_gRPC_grpc++_LIBRARY) + if (NOT TARGET gRPC::grpc++) + add_library(gRPC::grpc++ UNKNOWN IMPORTED) + set_target_properties( + gRPC::grpc++ PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${_gRPC++_INCLUDE_DIR}") + if (EXISTS "${_gRPC_grpc++_LIBRARY}") + set_target_properties( + gRPC::grpc++ PROPERTIES IMPORTED_LOCATION + "${_gRPC_grpc++_LIBRARY}") + endif () + if (EXISTS "${_gRPC_grpc++_LIBRARY_RELEASE}") + set_property( + TARGET gRPC::grpc++ + APPEND + PROPERTY IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties( + gRPC::grpc++ PROPERTIES IMPORTED_LOCATION_RELEASE + "${_gRPC_grpc++_LIBRARY_RELEASE}") + endif () + if (EXISTS "${_gRPC_grpc++_LIBRARY_DEBUG}") + set_property( + TARGET gRPC::grpc++ + APPEND + PROPERTY IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties( + gRPC::grpc++ PROPERTIES IMPORTED_LOCATION_DEBUG + "${_gRPC_grpc++_LIBRARY_DEBUG}") + endif () + set_property( + TARGET gRPC::grpc++ + APPEND + PROPERTY INTERFACE_LINK_LIBRARIES gRPC::grpc protobuf::libprotobuf + Threads::Threads) + # gRPC++ requires C++14. It does not yet define the compile features, so + # we define the feature ourselves. + set_property( + TARGET gRPC::grpc++ + APPEND + PROPERTY INTERFACE_COMPILE_FEATURES cxx_std_14) + endif () +endif () + +# Restore original find library prefixes +if (_gRPC_USE_STATIC_LIBS) + set(CMAKE_FIND_LIBRARY_PREFIXES "${_gRPC_ORIG_FIND_LIBRARY_PREFIXES}") +endif () + +file( + WRITE "${CMAKE_BINARY_DIR}/get_gRPC_version.cc" + [====[ +#include +#include +int main() { + std::cout << grpc::Version(); // no newline to simplify CMake module + return 0; +} + ]====]) + +try_run( + _gRPC_GET_VERSION_STATUS + _gRPC_GET_VERSION_COMPILE_STATUS + "${CMAKE_BINARY_DIR}" + "${CMAKE_BINARY_DIR}/get_gRPC_version.cc" + LINK_LIBRARIES + gRPC::grpc++ + gRPC::grpc + COMPILE_OUTPUT_VARIABLE _gRPC_GET_VERSION_COMPILE_OUTPUT + RUN_OUTPUT_VARIABLE gRPC_VERSION) + +file(REMOVE "${CMAKE_BINARY_DIR}/get_gRPC_version.cc") + +_grpc_fix_grpc_cpp_plugin_target() + +if (gRPC_DEBUG) + foreach ( + _var + _gRPC_CPP_PLUGIN_EXECUTABLE + _gRPC_VERSION_RAW + _gRPC_GET_VERSION_STATUS + _gRPC_GET_VERSION_COMPILE_STATUS + _gRPC_GET_VERSION_COMPILE_OUTPUT + _gRPC_grpc_LIBRARY + _gRPC_grpc++_LIBRARY + _gRPC_INCLUDE_DIR) + message( + STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "${_var} = ${${_var}}") + endforeach () + unset(_var) +endif () + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + gRPC + REQUIRED_VARS _gRPC_grpc_LIBRARY _gRPC_INCLUDE_DIR + VERSION_VAR gRPC_VERSION) From 4c38caf636a34a9ba5bdb1580da123bb5624e61a Mon Sep 17 00:00:00 2001 From: Andrew Messing Date: Thu, 10 Oct 2024 19:27:36 +0000 Subject: [PATCH 3/8] Updates --- .devcontainer/Dockerfile.amd64 | 1 + .devcontainer/entrypoint.sh | 2 +- cpp/CMakeLists.txt | 13 ++++++++++--- cpp/cmake/{ => Modules}/FindgRPC.cmake | 0 4 files changed, 12 insertions(+), 4 deletions(-) rename cpp/cmake/{ => Modules}/FindgRPC.cmake (100%) diff --git a/.devcontainer/Dockerfile.amd64 b/.devcontainer/Dockerfile.amd64 index 659b7c7..1939010 100644 --- a/.devcontainer/Dockerfile.amd64 +++ b/.devcontainer/Dockerfile.amd64 @@ -12,6 +12,7 @@ RUN apt-get update --fix-missing \ g++ \ pkg-config \ protobuf-compiler \ + protobuf-compiler-grpc \ python3 \ curl \ ninja-build \ diff --git a/.devcontainer/entrypoint.sh b/.devcontainer/entrypoint.sh index 8c193c6..6dce835 100755 --- a/.devcontainer/entrypoint.sh +++ b/.devcontainer/entrypoint.sh @@ -5,5 +5,5 @@ if [ -d build ]; then fi mkdir build cd build -cmake .. -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=TRUE -DBUILD_CHOREOGRAPHY_LIBS=ON +cmake .. -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=TRUE -DBUILD_CHOREOGRAPHY_LIBS=ON -DBUILD_SHARED_LIBS=ON make -j8 install package diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index d5c332f..9cdb9c1 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -10,7 +10,7 @@ cmake_minimum_required (VERSION 3.10.2) project (bosdyn VERSION 4.1.0) # Add cmake modules -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") # Dependencies: find_package(Protobuf REQUIRED) @@ -18,7 +18,6 @@ find_package(Eigen3 REQUIRED) find_package(gRPC REQUIRED) find_package(Threads REQUIRED) get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION) -include_directories(SYSTEM $) set(CMAKE_EXPORT_COMPILE_COMMANDS true) @@ -196,6 +195,8 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bosdyn ) +include(CMakePackageConfigHelpers) + ### EXAMPLE EXECUTABLES ### if(BUILD_EXAMPLES) find_package(CLI11 REQUIRED) @@ -208,6 +209,7 @@ target_compile_features(arm_grasp_carry_overrides PUBLIC cxx_std_17) target_include_directories(arm_grasp_carry_overrides PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} + $ ) target_link_libraries(arm_grasp_carry_overrides PUBLIC bosdyn_client_static) install(TARGETS arm_grasp_carry_overrides DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -216,6 +218,7 @@ target_compile_features(arm_manipulation_api_walk_to PUBLIC cxx_std_17) target_include_directories(arm_manipulation_api_walk_to PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} + $ ) target_link_libraries(arm_manipulation_api_walk_to PUBLIC bosdyn_client_static) install(TARGETS arm_manipulation_api_walk_to DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -224,6 +227,7 @@ target_compile_features(basic_robot_command PUBLIC cxx_std_17) target_include_directories(basic_robot_command PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} + $ ) target_link_libraries(basic_robot_command PUBLIC bosdyn_client_static) install(TARGETS basic_robot_command DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -232,6 +236,7 @@ target_compile_features(get_image PUBLIC cxx_std_17) target_include_directories(get_image PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} + $ ) target_link_libraries(get_image PUBLIC bosdyn_client_static) install(TARGETS get_image DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -240,6 +245,7 @@ target_compile_features(hello_spot PUBLIC cxx_std_17) target_include_directories(hello_spot PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} + $ ) target_link_libraries(hello_spot PUBLIC bosdyn_client_static) install(TARGETS hello_spot DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -248,6 +254,7 @@ target_compile_features(inverse_kinematics_reachability PUBLIC cxx_std_17) target_include_directories(inverse_kinematics_reachability PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} + $ ) target_link_libraries(inverse_kinematics_reachability PUBLIC bosdyn_client_static) install(TARGETS inverse_kinematics_reachability DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -256,11 +263,11 @@ target_compile_features(spot_cam PUBLIC cxx_std_17) target_include_directories(spot_cam PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} + $ ) target_link_libraries(spot_cam PUBLIC bosdyn_client_static) install(TARGETS spot_cam DESTINATION ${CMAKE_INSTALL_BINDIR}) # Save a version file in the project's binary directory -include(CMakePackageConfigHelpers) set(VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake") write_basic_package_version_file("${VERSION_FILE}" VERSION ${PACKAGE_VERSION} diff --git a/cpp/cmake/FindgRPC.cmake b/cpp/cmake/Modules/FindgRPC.cmake similarity index 100% rename from cpp/cmake/FindgRPC.cmake rename to cpp/cmake/Modules/FindgRPC.cmake From b268d2526189dcdf1bc56bb90191de98caf80c33 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Mon, 14 Oct 2024 13:37:13 -0300 Subject: [PATCH 4/8] Restore Spot C++ SDK builds Signed-off-by: Michel Hidalgo --- cpp/CMakeLists.txt | 40 ++++++++++++++------------------ cpp/cmake/ProjectConfig.cmake.in | 5 ++-- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 9cdb9c1..f0f8ffa 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -9,15 +9,16 @@ cmake_minimum_required (VERSION 3.10.2) project (bosdyn VERSION 4.1.0) -# Add cmake modules -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") - # Dependencies: find_package(Protobuf REQUIRED) find_package(Eigen3 REQUIRED) -find_package(gRPC REQUIRED) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(GRPC REQUIRED grpc) +pkg_check_modules(GRPCPP REQUIRED grpc++) +find_program(GRPC_CPP_PLUGIN_LOCATION grpc_cpp_plugin REQUIRED) + find_package(Threads REQUIRED) -get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION) set(CMAKE_EXPORT_COMPILE_COMMANDS true) @@ -33,30 +34,27 @@ ENDIF (NOT UNIX) include(GNUInstallDirs) - ### API protos LIBRARY ### -set(API_protos_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build/protos/) -# Copy protos folders to build folder so they are in a subdirectory from the cpp folder (necessary for the proto cpp files generation). -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../protos/ DESTINATION ${API_protos_PATH}) +get_filename_component(API_protos_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../protos/ ABSOLUTE) +file(GLOB_RECURSE bosdyn_protos_files CONFIGURE_DEPENDS "${API_protos_PATH}/*.proto") set(protos_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/protos) file(MAKE_DIRECTORY ${protos_OUTPUT_DIR}) -file(GLOB_RECURSE bosdyn_protos_files CONFIGURE_DEPENDS - RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${API_protos_PATH}/*.proto") - if (bosdyn_protos_files) add_library(bosdyn_api_obj OBJECT ${bosdyn_protos_files}) set_property(TARGET bosdyn_api_obj PROPERTY POSITION_INDEPENDENT_CODE 1) - target_link_libraries(bosdyn_api_obj PUBLIC protobuf::libprotobuf gRPC::grpc gRPC::grpc++) + target_link_libraries(bosdyn_api_obj PUBLIC protobuf::libprotobuf ${GRPC_LINK_LIBRARIES} ${GRPCPP_LINK_LIBRARIES}) target_include_directories(bosdyn_api_obj PUBLIC + ${GRPC_INCLUDE_DIRS} ${GRPCPP_INCLUDE_DIRS} $ $ ) protobuf_generate(TARGET bosdyn_api_obj LANGUAGE cpp - IMPORT_DIRS ${API_protos_PATH} - PROTOC_OUT_DIR ${protos_OUTPUT_DIR}) + IMPORT_DIRS ${API_protos_PATH} + PROTOC_OUT_DIR ${protos_OUTPUT_DIR} + ) protobuf_generate(TARGET bosdyn_api_obj LANGUAGE grpc GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc - PLUGIN "protoc-gen-grpc=${grpc_cpp_plugin_location}" + PLUGIN "protoc-gen-grpc=${GRPC_CPP_PLUGIN_LOCATION}" IMPORT_DIRS ${API_protos_PATH} PROTOC_OUT_DIR ${protos_OUTPUT_DIR} ) @@ -95,13 +93,11 @@ endif() if (BUILD_CHOREOGRAPHY_LIBS) ### API choreography_protos LIBRARY ### -set(API_choreography_protos_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build/choreography_protos/) -# Copy choreography_protos folders to build folder so they are in a subdirectory from the cpp folder (necessary for the proto cpp files generation). -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../choreography_protos/ DESTINATION ${API_choreography_protos_PATH}) +get_filename_component(API_choreography_protos_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../choreography_protos/ ABSOLUTE) +file(GLOB_RECURSE bosdyn_choreography_protos_files CONFIGURE_DEPENDS "${API_choreography_protos_PATH}/*.proto") set(choreography_protos_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/choreography_protos) file(MAKE_DIRECTORY ${choreography_protos_OUTPUT_DIR}) -file(GLOB_RECURSE bosdyn_choreography_protos_files CONFIGURE_DEPENDS - RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${API_choreography_protos_PATH}/*.proto") +file(GLOB_RECURSE bosdyn_choreography_protos_files CONFIGURE_DEPENDS "${API_choreography_protos_PATH}/*.proto") if (bosdyn_choreography_protos_files) add_library(bosdyn_choreography_protos_obj OBJECT ${bosdyn_choreography_protos_files}) @@ -116,7 +112,7 @@ if (bosdyn_choreography_protos_files) PROTOC_OUT_DIR ${choreography_protos_OUTPUT_DIR}) protobuf_generate(TARGET bosdyn_choreography_protos_obj LANGUAGE grpc GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc - PLUGIN "protoc-gen-grpc=${grpc_cpp_plugin_location}" + PLUGIN "protoc-gen-grpc=${GRPC_CPP_PLUGIN_LOCATION}" IMPORT_DIRS ${API_choreography_protos_PATH} PROTOC_OUT_DIR ${choreography_protos_OUTPUT_DIR} ) diff --git a/cpp/cmake/ProjectConfig.cmake.in b/cpp/cmake/ProjectConfig.cmake.in index 0bc68d2..eda0dc9 100644 --- a/cpp/cmake/ProjectConfig.cmake.in +++ b/cpp/cmake/ProjectConfig.cmake.in @@ -7,8 +7,9 @@ list(APPEND CMAKE_PREFIX_PATH @DEP_INSTALL_PATH@) include(CMakeFindDependencyMacro) find_dependency(Protobuf CONFIG REQUIRED) find_dependency(Eigen3 CONFIG REQUIRED) -find_dependency(gRPC CONFIG REQUIRED) -find_dependency(CLI11 CONFIG REQUIRED) +find_dependency(PkgConfig CONFIG REQUIRED) +pkg_check_modules(GRPC REQUIRED grpc) +pkg_check_modules(GRPCPP REQUIRED grpc++) find_dependency(Threads REQUIRED) # Pick up the auto-generated file which knows how to add the library targets # This will mean that we do not have to supply full paths for the libraries From 24494824370520a54d50750f870be9d4b66ec170 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Mon, 14 Oct 2024 13:38:00 -0300 Subject: [PATCH 5/8] Remove unused gRPC CMake module Signed-off-by: Michel Hidalgo --- cpp/cmake/Modules/FindgRPC.cmake | 320 ------------------------------- 1 file changed, 320 deletions(-) delete mode 100644 cpp/cmake/Modules/FindgRPC.cmake diff --git a/cpp/cmake/Modules/FindgRPC.cmake b/cpp/cmake/Modules/FindgRPC.cmake deleted file mode 100644 index aa77980..0000000 --- a/cpp/cmake/Modules/FindgRPC.cmake +++ /dev/null @@ -1,320 +0,0 @@ -# ~~~ -# Copyright 2019 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ~~~ - -#[=======================================================================[.rst: -FindgRPC --------- - -Locate and configure the ``gRPC`` library. - -The following variables can be set and are optional: - -``gRPC_DEBUG`` - Show debug messages. -``gRPC_USE_STATIC_LIBS`` - Set to ON to force the use of the static libraries. - Default is OFF. - -Defines the following variables: - -``gRPC_FOUND`` - Found the gRPC library -``gRPC_VERSION`` - Version of package found. - -The following ``IMPORTED`` targets are also defined: - -``gRPC::grpc++`` - The gRPC C++ library. -``gRPC::grpc`` - The gRPC C core library. -``gRPC::cpp_plugin`` - The C++ plugin for the Protobuf protoc compiler. - -The following cache variables are also available to set or use: - -Example: - -.. code-block:: cmake - - find_package(gRPC REQUIRED) - add_executable(bar bar.cc) - target_link_libraries(bar PRIVATE gRPC::grpc++) - -#]=======================================================================] - -if (gRPC_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "gRPC_USE_STATIC_LIBS = ${gRPC_USE_STATIC_LIBS}" - " gRPC_FOUND = ${gRPC_FOUND}") -endif () - -# gRPC always requires Thread support. -find_package(Threads REQUIRED) - -# Load the module to find protobuf with proper targets. Do not use -# `find_package()` because we (have to) install this module in non-standard -# locations. -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") -find_package(Protobuf CONFIG QUIET) -if (NOT Protobuf_FOUND) - find_package(Protobuf) -endif () - -# The gRPC::grpc_cpp_plugin target is sometimes defined, but without a -# IMPORTED_LOCATION -function (_grpc_fix_grpc_cpp_plugin_target) - # The target may already exist, do not create it again if it does. - if (NOT TARGET gRPC::grpc_cpp_plugin) - add_executable(gRPC::grpc_cpp_plugin IMPORTED) - endif () - get_target_property(_gRPC_CPP_PLUGIN_EXECUTABLE gRPC::grpc_cpp_plugin - IMPORTED_LOCATION) - if (gRPC_DEBUG) - message( - STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "LOCATION=${_gRPC_CPP_PLUGIN_EXECUTABLE}") - endif () - # Even if the target exists, gRPC CMake support files do not define the - # executable for the imported target (at least they do not in v1.19.1), so - # we need to define it ourselves. - if (NOT _gRPC_CPP_PLUGIN_EXECUTABLE) - find_program(_gRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin - DOC "The gRPC C++ plugin for protoc") - mark_as_advanced(_gRPC_CPP_PLUGIN_EXECUTABLE) - if (_gRPC_CPP_PLUGIN_EXECUTABLE) - set_property( - TARGET gRPC::grpc_cpp_plugin - PROPERTY IMPORTED_LOCATION ${_gRPC_CPP_PLUGIN_EXECUTABLE}) - else () - set(gRPC_FOUND "grpc_cpp_plugin-NOTFOUND") - endif () - endif () -endfunction () - -# First try to use the `gRPCConfig.cmake` or `grpc-config.cmake` file if it was -# installed. This is common on systems (or package managers) where gRPC was -# compiled and installed with `CMake`. - -find_package(gRPC NO_MODULE QUIET) - -if (gRPC_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "NO_MODULE result gRPC_FOUND = ${gRPC_FOUND}") -endif () - -if (gRPC_FOUND) - _grpc_fix_grpc_cpp_plugin_target() - return() -endif () - -include(SelectLibraryConfigurations) - -# Internal function: search for normal library as well as a debug one if the -# debug one is specified also include debug/optimized keywords in *_LIBRARIES -# variable -function (_gRPC_find_library name filename) - if (${name}_LIBRARY) - # Use result recorded by a previous call. - return() - else () - find_library(${name}_LIBRARY_RELEASE NAMES ${filename}) - mark_as_advanced(${name}_LIBRARY_RELEASE) - - find_library(${name}_LIBRARY_DEBUG NAMES ${filename}d ${filename}) - mark_as_advanced(${name}_LIBRARY_DEBUG) - - select_library_configurations(${name}) - - if (gRPC_DEBUG) - message( - STATUS - "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "${name} ${filename} RELEASE=${${name}_LIBRARY}" - " DEBUG=${${name}_LIBRARY_DEBUG} DEFAULT=${${name}_LIBRARY}" - ) - endif () - - set(${name}_LIBRARY - "${${name}_LIBRARY}" - PARENT_SCOPE) - endif () -endfunction () - -# -# Main -# - -# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES -if (_gRPC_USE_STATIC_LIBS) - set(_gRPC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - if (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else () - set(CMAKE_FIND_LIBRARY_SUFFIXES .a) - endif () -endif () - -_grpc_find_library(_gRPC_grpc grpc) -_grpc_find_library(_gRPC_grpc++ grpc++) - -if (NOT _gRPC_INCLUDE_DIR) - find_path(_gRPC_INCLUDE_DIR grpcpp/grpcpp.h) - mark_as_advanced(_gRPC_INCLUDE_DIR) -endif () - -if (gRPC_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " _gRPC_grpc_LIBRARY = ${_gRPC_grpc_LIBRARY}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " _gRPC_grpc++_LIBRARY = ${_gRPC_grpc++_LIBRARY}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " _gRPC_INCLUDE_DIR = ${_gRPC_INCLUDE_DIR}") -endif () - -if (_gRPC_grpc_LIBRARY) - if (NOT TARGET gRPC::grpc) - add_library(gRPC::grpc UNKNOWN IMPORTED) - set_target_properties( - gRPC::grpc PROPERTIES INTERFACE_INCLUDE_DIRECTORIES - "${_gRPC_INCLUDE_DIR}") - if (EXISTS "${_gRPC_grpc_LIBRARY}") - set_target_properties(gRPC::grpc PROPERTIES IMPORTED_LOCATION - "${_gRPC_grpc_LIBRARY}") - endif () - if (EXISTS "${_gRPC_grpc_LIBRARY_RELEASE}") - set_property( - TARGET gRPC::grpc - APPEND - PROPERTY IMPORTED_CONFIGURATIONS RELEASE) - set_target_properties( - gRPC::grpc PROPERTIES IMPORTED_LOCATION_RELEASE - "${_gRPC_grpc_LIBRARY_RELEASE}") - endif () - if (EXISTS "${_gRPC_grpc_LIBRARY_DEBUG}") - set_property( - TARGET gRPC::grpc - APPEND - PROPERTY IMPORTED_CONFIGURATIONS DEBUG) - set_target_properties( - gRPC::grpc PROPERTIES IMPORTED_LOCATION_DEBUG - "${_gRPC_grpc_LIBRARY_DEBUG}") - endif () - set_property( - TARGET gRPC::grpc - APPEND - PROPERTY INTERFACE_LINK_LIBRARIES protobuf::libprotobuf - Threads::Threads) - endif () -endif () - -if (_gRPC_grpc++_LIBRARY) - if (NOT TARGET gRPC::grpc++) - add_library(gRPC::grpc++ UNKNOWN IMPORTED) - set_target_properties( - gRPC::grpc++ PROPERTIES INTERFACE_INCLUDE_DIRECTORIES - "${_gRPC++_INCLUDE_DIR}") - if (EXISTS "${_gRPC_grpc++_LIBRARY}") - set_target_properties( - gRPC::grpc++ PROPERTIES IMPORTED_LOCATION - "${_gRPC_grpc++_LIBRARY}") - endif () - if (EXISTS "${_gRPC_grpc++_LIBRARY_RELEASE}") - set_property( - TARGET gRPC::grpc++ - APPEND - PROPERTY IMPORTED_CONFIGURATIONS RELEASE) - set_target_properties( - gRPC::grpc++ PROPERTIES IMPORTED_LOCATION_RELEASE - "${_gRPC_grpc++_LIBRARY_RELEASE}") - endif () - if (EXISTS "${_gRPC_grpc++_LIBRARY_DEBUG}") - set_property( - TARGET gRPC::grpc++ - APPEND - PROPERTY IMPORTED_CONFIGURATIONS DEBUG) - set_target_properties( - gRPC::grpc++ PROPERTIES IMPORTED_LOCATION_DEBUG - "${_gRPC_grpc++_LIBRARY_DEBUG}") - endif () - set_property( - TARGET gRPC::grpc++ - APPEND - PROPERTY INTERFACE_LINK_LIBRARIES gRPC::grpc protobuf::libprotobuf - Threads::Threads) - # gRPC++ requires C++14. It does not yet define the compile features, so - # we define the feature ourselves. - set_property( - TARGET gRPC::grpc++ - APPEND - PROPERTY INTERFACE_COMPILE_FEATURES cxx_std_14) - endif () -endif () - -# Restore original find library prefixes -if (_gRPC_USE_STATIC_LIBS) - set(CMAKE_FIND_LIBRARY_PREFIXES "${_gRPC_ORIG_FIND_LIBRARY_PREFIXES}") -endif () - -file( - WRITE "${CMAKE_BINARY_DIR}/get_gRPC_version.cc" - [====[ -#include -#include -int main() { - std::cout << grpc::Version(); // no newline to simplify CMake module - return 0; -} - ]====]) - -try_run( - _gRPC_GET_VERSION_STATUS - _gRPC_GET_VERSION_COMPILE_STATUS - "${CMAKE_BINARY_DIR}" - "${CMAKE_BINARY_DIR}/get_gRPC_version.cc" - LINK_LIBRARIES - gRPC::grpc++ - gRPC::grpc - COMPILE_OUTPUT_VARIABLE _gRPC_GET_VERSION_COMPILE_OUTPUT - RUN_OUTPUT_VARIABLE gRPC_VERSION) - -file(REMOVE "${CMAKE_BINARY_DIR}/get_gRPC_version.cc") - -_grpc_fix_grpc_cpp_plugin_target() - -if (gRPC_DEBUG) - foreach ( - _var - _gRPC_CPP_PLUGIN_EXECUTABLE - _gRPC_VERSION_RAW - _gRPC_GET_VERSION_STATUS - _gRPC_GET_VERSION_COMPILE_STATUS - _gRPC_GET_VERSION_COMPILE_OUTPUT - _gRPC_grpc_LIBRARY - _gRPC_grpc++_LIBRARY - _gRPC_INCLUDE_DIR) - message( - STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "${_var} = ${${_var}}") - endforeach () - unset(_var) -endif () - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - gRPC - REQUIRED_VARS _gRPC_grpc_LIBRARY _gRPC_INCLUDE_DIR - VERSION_VAR gRPC_VERSION) From 49c281e3cff426cd819779ac47ecfcad92769952 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Mon, 14 Oct 2024 13:56:29 -0300 Subject: [PATCH 6/8] Restore cli11 dependency Signed-off-by: Michel Hidalgo --- .devcontainer/Dockerfile.amd64 | 1 + cpp/CMakeLists.txt | 13 ++++--------- cpp/cmake/ProjectConfig.cmake.in | 1 + 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.devcontainer/Dockerfile.amd64 b/.devcontainer/Dockerfile.amd64 index 1939010..1e4c0af 100644 --- a/.devcontainer/Dockerfile.amd64 +++ b/.devcontainer/Dockerfile.amd64 @@ -6,6 +6,7 @@ RUN apt-get update --fix-missing \ ca-certificates \ cmake \ git \ + libcli11-dev \ libeigen3-dev \ libgrpc++-dev \ libprotobuf-dev \ diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index f0f8ffa..eea9e12 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -17,9 +17,11 @@ find_package(PkgConfig REQUIRED) pkg_check_modules(GRPC REQUIRED grpc) pkg_check_modules(GRPCPP REQUIRED grpc++) find_program(GRPC_CPP_PLUGIN_LOCATION grpc_cpp_plugin REQUIRED) - +find_package(CLI11 REQUIRED) find_package(Threads REQUIRED) +include_directories(SYSTEM $) + set(CMAKE_EXPORT_COMPILE_COMMANDS true) # Command-line arguments: @@ -195,8 +197,7 @@ include(CMakePackageConfigHelpers) ### EXAMPLE EXECUTABLES ### if(BUILD_EXAMPLES) -find_package(CLI11 REQUIRED) - + link_directories( ${PROTOBUF_LIB_DIR} ) @@ -205,7 +206,6 @@ target_compile_features(arm_grasp_carry_overrides PUBLIC cxx_std_17) target_include_directories(arm_grasp_carry_overrides PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} - $ ) target_link_libraries(arm_grasp_carry_overrides PUBLIC bosdyn_client_static) install(TARGETS arm_grasp_carry_overrides DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -223,7 +223,6 @@ target_compile_features(basic_robot_command PUBLIC cxx_std_17) target_include_directories(basic_robot_command PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} - $ ) target_link_libraries(basic_robot_command PUBLIC bosdyn_client_static) install(TARGETS basic_robot_command DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -232,7 +231,6 @@ target_compile_features(get_image PUBLIC cxx_std_17) target_include_directories(get_image PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} - $ ) target_link_libraries(get_image PUBLIC bosdyn_client_static) install(TARGETS get_image DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -241,7 +239,6 @@ target_compile_features(hello_spot PUBLIC cxx_std_17) target_include_directories(hello_spot PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} - $ ) target_link_libraries(hello_spot PUBLIC bosdyn_client_static) install(TARGETS hello_spot DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -250,7 +247,6 @@ target_compile_features(inverse_kinematics_reachability PUBLIC cxx_std_17) target_include_directories(inverse_kinematics_reachability PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} - $ ) target_link_libraries(inverse_kinematics_reachability PUBLIC bosdyn_client_static) install(TARGETS inverse_kinematics_reachability DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -259,7 +255,6 @@ target_compile_features(spot_cam PUBLIC cxx_std_17) target_include_directories(spot_cam PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROTOBUF_INCLUDE_DIR} - $ ) target_link_libraries(spot_cam PUBLIC bosdyn_client_static) install(TARGETS spot_cam DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/cpp/cmake/ProjectConfig.cmake.in b/cpp/cmake/ProjectConfig.cmake.in index eda0dc9..fc53629 100644 --- a/cpp/cmake/ProjectConfig.cmake.in +++ b/cpp/cmake/ProjectConfig.cmake.in @@ -11,6 +11,7 @@ find_dependency(PkgConfig CONFIG REQUIRED) pkg_check_modules(GRPC REQUIRED grpc) pkg_check_modules(GRPCPP REQUIRED grpc++) find_dependency(Threads REQUIRED) +find_dependency(CLI11 REQUIRED) # Pick up the auto-generated file which knows how to add the library targets # This will mean that we do not have to supply full paths for the libraries set(exports_file "${CMAKE_CURRENT_LIST_DIR}/@EXPORTS_FILE@") From 1b09cb29a765905ccf8ca0867cbabf1a40e1dd59 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Tue, 15 Oct 2024 18:47:08 -0300 Subject: [PATCH 7/8] Remove vcpkg reference in CPack config Signed-off-by: Michel Hidalgo --- cpp/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index eea9e12..0d118d6 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -278,7 +278,6 @@ install( # Define Variables needed by package config file set(PACKAGE_INSTALL_PREFIX /opt/spot-cpp-sdk) -set(DEP_INSTALL_PATH ${PACKAGE_INSTALL_PREFIX}/external) #this generates a relocatable config file for install, but it gets invoked at build time, #so the output has to be saved in a way that will not conflict with the export config @@ -327,6 +326,5 @@ if (UNIX) set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE") set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") set(CPACK_PACKAGING_INSTALL_PREFIX "${PACKAGE_INSTALL_PREFIX}") - set(CPACK_INSTALLED_DIRECTORIES "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/;${DEP_INSTALL_PATH}/") include(CPack) endif() From 0a17fecf68df72066a5e2a7103d568d6d50f71ae Mon Sep 17 00:00:00 2001 From: Andrew Messing Date: Wed, 16 Oct 2024 13:41:14 +0000 Subject: [PATCH 8/8] Update arm version of the docker image --- .devcontainer/Dockerfile.arm64 | 52 +++++++++++++++------------- .devcontainer/Dockerfile.arm64_vcpkg | 29 ++++++++++++++++ .devcontainer/build.sh | 11 ++++++ 3 files changed, 68 insertions(+), 24 deletions(-) create mode 100644 .devcontainer/Dockerfile.arm64_vcpkg diff --git a/.devcontainer/Dockerfile.arm64 b/.devcontainer/Dockerfile.arm64 index 7f32e6e..dcbfb10 100644 --- a/.devcontainer/Dockerfile.arm64 +++ b/.devcontainer/Dockerfile.arm64 @@ -1,29 +1,33 @@ FROM arm64v8/ubuntu:22.04 -SHELL ["/bin/bash", "-c"] -RUN apt-get update --fix-missing &&\ - apt-get install -y --no-install-recommends build-essential ca-certificates cmake git g++ pkg-config python3 curl ninja-build tar zip unzip zlib1g-dev libssl-dev wget &&\ - apt-get autoclean &&\ - apt-get autoremove &&\ - apt-get clean &&\ - rm -rf /var/lib/apt/lists/* +RUN apt-get update --fix-missing \ + && apt-get install -y --no-install-recommends \ + build-essential \ + ca-certificates \ + cmake \ + git \ + libcli11-dev \ + libeigen3-dev \ + libgrpc++-dev \ + libprotobuf-dev \ + g++ \ + pkg-config \ + protobuf-compiler \ + protobuf-compiler-grpc \ + python3 \ + curl \ + ninja-build \ + tar \ + zip \ + unzip \ + zlib1g-dev \ + libssl-dev \ + wget \ + && apt-get autoclean \ + && apt-get autoremove \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* RUN update-ca-certificates -RUN wget https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3.tar.gz &&\ - tar -xzf cmake-3.28.3.tar.gz &&\ - cd cmake-3.28.3 &&\ - ./configure &&\ - make install &&\ - cd .. &&\ - rm cmake-3.28.3.tar.gz &&\ - rm -r cmake-3.28.3 - -RUN git clone https://github.com/microsoft/vcpkg &&\ - cd vcpkg &&\ - git checkout 3b213864579b6fa686e38715508f7cd41a50900f &&\ - export VCPKG_FORCE_SYSTEM_BINARIES=arm &&\ - ./bootstrap-vcpkg.sh -disableMetrics &&\ - ./vcpkg install grpc:arm64-linux &&\ - ./vcpkg install eigen3:arm64-linux &&\ - ./vcpkg install cli11:arm64-linux +COPY entrypoint.sh . diff --git a/.devcontainer/Dockerfile.arm64_vcpkg b/.devcontainer/Dockerfile.arm64_vcpkg new file mode 100644 index 0000000..7f32e6e --- /dev/null +++ b/.devcontainer/Dockerfile.arm64_vcpkg @@ -0,0 +1,29 @@ +FROM arm64v8/ubuntu:22.04 +SHELL ["/bin/bash", "-c"] + +RUN apt-get update --fix-missing &&\ + apt-get install -y --no-install-recommends build-essential ca-certificates cmake git g++ pkg-config python3 curl ninja-build tar zip unzip zlib1g-dev libssl-dev wget &&\ + apt-get autoclean &&\ + apt-get autoremove &&\ + apt-get clean &&\ + rm -rf /var/lib/apt/lists/* + +RUN update-ca-certificates + +RUN wget https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3.tar.gz &&\ + tar -xzf cmake-3.28.3.tar.gz &&\ + cd cmake-3.28.3 &&\ + ./configure &&\ + make install &&\ + cd .. &&\ + rm cmake-3.28.3.tar.gz &&\ + rm -r cmake-3.28.3 + +RUN git clone https://github.com/microsoft/vcpkg &&\ + cd vcpkg &&\ + git checkout 3b213864579b6fa686e38715508f7cd41a50900f &&\ + export VCPKG_FORCE_SYSTEM_BINARIES=arm &&\ + ./bootstrap-vcpkg.sh -disableMetrics &&\ + ./vcpkg install grpc:arm64-linux &&\ + ./vcpkg install eigen3:arm64-linux &&\ + ./vcpkg install cli11:arm64-linux diff --git a/.devcontainer/build.sh b/.devcontainer/build.sh index 84264e9..69ee41b 100755 --- a/.devcontainer/build.sh +++ b/.devcontainer/build.sh @@ -1,2 +1,13 @@ #!/usr/bin/env bash +ARCH=$(dpkg --print-architecture) + +if [ "$ARCH" == "amd64" ]; then + docker build -t spot_builder -f Dockerfile.amd64 . +elif [ "$ARCH" == "arm64" ]; then + docker build -t spot_builder -f Dockerfile.arm64 . +else + echo "Unknown architecture: $ARCH" > /dev/stderr + exit 1 +fi + docker run -v ~/spot-cpp-sdk:/spot-cpp-sdk spot_builder /entrypoint.sh