From 9a661601cea451635595bb836e4eff5fd7a46893 Mon Sep 17 00:00:00 2001 From: Andrew Messing Date: Thu, 10 Oct 2024 18:19:39 +0000 Subject: [PATCH] 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)