Skip to content

Commit

Permalink
Restore Spot C++ SDK builds
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
mhidalgo-bdai committed Oct 14, 2024
1 parent 4c38caf commit b268d25
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
40 changes: 18 additions & 22 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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}
$<BUILD_INTERFACE:${protos_OUTPUT_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
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}
)
Expand Down Expand Up @@ -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})
Expand All @@ -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}
)
Expand Down
5 changes: 3 additions & 2 deletions cpp/cmake/ProjectConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b268d25

Please sign in to comment.