Skip to content

Commit fb7a702

Browse files
diegoferigo-raiexploy-bot
authored andcommitted
Add support for distributing and consuming the CMake project (#92)
### What change is being made - Add installation support. - Export C++ targets. - Scope headers to have a symmetric build and install trees. Fixes #65. ### Why this change is being made Enhance how the C++ project is consumed by upstream and downstream projects. ### Tested Waited CI to pass. GitOrigin-RevId: adae13412984ce65be3c52d7ac452aab16429c46
1 parent 05eb527 commit fb7a702

36 files changed

Lines changed: 1233 additions & 156 deletions

.github/workflows/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ jobs:
100100
OMNI_KIT_ACCEPT_EULA: yes
101101
run: pixi run -e isaaclab export-isaaclab-ci
102102

103+
- name: Build Exploy Library
104+
run: |
105+
pixi run -e controller setup
106+
pixi run -e controller build
107+
103108
- name: Run Controller Loopback Example
104109
run: pixi run -e controller run-example
105110

cmake/Findonnxruntime.cmake

Lines changed: 0 additions & 30 deletions
This file was deleted.

control/CMakeLists.txt

Lines changed: 136 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,159 @@
11
# Copyright (c) 2026 Robotics and AI Institute LLC dba RAI Institute. All rights reserved.
22

3-
cmake_minimum_required(VERSION 3.20)
4-
project(exploy LANGUAGES CXX)
3+
cmake_minimum_required(VERSION 3.22)
54

6-
set(CMAKE_CXX_STANDARD 20)
7-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5+
# Keep this aligned with the Python version defined in pyproject.toml.
6+
project(exploy LANGUAGES CXX VERSION 0.1.0)
87

98
include(CTest)
9+
include(GNUInstallDirs)
10+
include(CMakePackageConfigHelpers)
1011

11-
# Treat warnings as errors
12+
# Enable shared libraries and position independent code by default.
13+
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
14+
15+
# Configure RPATH.
16+
set(CMAKE_SKIP_BUILD_RPATH FALSE)
17+
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
18+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
19+
if(APPLE)
20+
list(APPEND CMAKE_INSTALL_RPATH "@loader_path/../lib")
21+
else()
22+
list(APPEND CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
23+
endif()
24+
25+
# Treat warnings as errors.
1226
add_compile_options(-Werror -Wpedantic -Wunused-variable -Wunused-parameter -Wreorder)
1327

14-
# Find dependencies
28+
# Find dependencies.
1529
find_package(Eigen3 REQUIRED)
1630
find_package(nlohmann_json REQUIRED)
1731
find_package(fmt REQUIRED)
1832
find_package(onnxruntime REQUIRED)
1933

20-
# C++ Shared Library
34+
# ==============
35+
# Exploy library
36+
# ==============
37+
38+
# C++ shared library.
2139
add_library(exploy SHARED
22-
controller.cpp
23-
context.cpp
24-
onnx_runtime.cpp
25-
components.cpp
26-
matcher.cpp
40+
src/controller.cpp
41+
src/context.cpp
42+
src/onnx_runtime.cpp
43+
src/components.cpp
44+
src/matcher.cpp
45+
)
46+
47+
# Create an alias target for symmetry between the build tree and install tree.
48+
add_library(exploy::exploy ALIAS exploy)
49+
50+
# Set the C++ standard.
51+
target_compile_features(exploy PUBLIC cxx_std_20)
52+
set_target_properties(exploy PROPERTIES
53+
CXX_STANDARD_REQUIRED ON
54+
CXX_EXTENSIONS OFF
55+
POSITION_INDEPENDENT_CODE ON
2756
)
2857

29-
target_include_directories(exploy PUBLIC .)
58+
# Include directories and public headers.
59+
target_include_directories(exploy PUBLIC
60+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
61+
$<INSTALL_INTERFACE:include>
62+
)
63+
64+
# Find all header files in the include directory.
65+
file(GLOB EXPLOY_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/exploy/*.hpp")
66+
67+
# Add public headers to the target.
68+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.23)
69+
target_sources(exploy PUBLIC
70+
FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
71+
FILES ${EXPLOY_HEADERS}
72+
)
73+
endif()
3074

75+
# Link dependencies.
3176
target_link_libraries(exploy PUBLIC
3277
Eigen3::Eigen
3378
nlohmann_json::nlohmann_json
3479
fmt::fmt
3580
onnxruntime::onnxruntime
3681
)
3782

83+
# =================================
84+
# Exported targets and installation
85+
# =================================
86+
87+
# Install the target (the library itself) and public headers.
88+
if(CMAKE_VERSION VERSION_LESS 3.23)
89+
install(
90+
FILES ${EXPLOY_HEADERS}
91+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/exploy
92+
)
93+
install(
94+
TARGETS exploy
95+
EXPORT exployTargets
96+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
97+
)
98+
else()
99+
install(TARGETS exploy
100+
EXPORT exployTargets
101+
FILE_SET HEADERS
102+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
103+
)
104+
endif()
105+
106+
# Export the targets for use by downstream packages.
107+
install(EXPORT exployTargets
108+
FILE exployTargets.cmake
109+
NAMESPACE exploy::
110+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/exploy
111+
)
112+
113+
# Generate and install the package configuration files.
114+
export(EXPORT exployTargets
115+
FILE "${CMAKE_CURRENT_BINARY_DIR}/exployTargets.cmake"
116+
NAMESPACE exploy::
117+
)
118+
119+
# Create a ConfigVersion.cmake file.
120+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/exployConfig.cmake.in"
121+
"@PACKAGE_INIT@
122+
123+
include(CMakeFindDependencyMacro)
124+
find_dependency(Eigen3)
125+
find_dependency(nlohmann_json)
126+
find_dependency(fmt)
127+
find_dependency(onnxruntime)
128+
129+
include(\"\${CMAKE_CURRENT_LIST_DIR}/exployTargets.cmake\")
130+
")
131+
132+
# Configure and install the package configuration files.
133+
configure_package_config_file(
134+
"${CMAKE_CURRENT_BINARY_DIR}/exployConfig.cmake.in"
135+
"${CMAKE_CURRENT_BINARY_DIR}/exployConfig.cmake"
136+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/exploy
137+
)
138+
139+
# Create a version file for the config file.
140+
write_basic_package_version_file(
141+
"${CMAKE_CURRENT_BINARY_DIR}/exployConfigVersion.cmake"
142+
VERSION ${PROJECT_VERSION}
143+
COMPATIBILITY SameMajorVersion
144+
)
145+
146+
# Install the config and version files.
147+
install(FILES
148+
"${CMAKE_CURRENT_BINARY_DIR}/exployConfig.cmake"
149+
"${CMAKE_CURRENT_BINARY_DIR}/exployConfigVersion.cmake"
150+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/exploy
151+
)
152+
153+
# =====
38154
# Tests
155+
# =====
156+
39157
if(BUILD_TESTING)
40158
find_package(GTest REQUIRED)
41159
find_package(Python3 REQUIRED COMPONENTS Interpreter)
@@ -50,7 +168,7 @@ if(BUILD_TESTING)
50168
COMMENT "Generating test ONNX model..."
51169
)
52170

53-
add_executable(exploy_test
171+
add_executable(${PROJECT_NAME}_test
54172
test/controller_test.cpp
55173
test/components_test.cpp
56174
test/context_test.cpp
@@ -59,14 +177,13 @@ if(BUILD_TESTING)
59177
test/onnx_runtime_test.cpp
60178
"${GEN_OUTPUT}"
61179
)
62-
target_compile_definitions(exploy_test PRIVATE
180+
target_compile_definitions(${PROJECT_NAME}_test PRIVATE
63181
TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test/testdata"
64182
)
65-
target_link_libraries(exploy_test PRIVATE
66-
exploy
183+
target_link_libraries(${PROJECT_NAME}_test PRIVATE
184+
exploy::exploy
67185
GTest::gtest_main
68186
GTest::gmock
69-
fmt::fmt
70187
)
71-
add_test(NAME exploy_test COMMAND exploy_test)
188+
add_test(NAME ${PROJECT_NAME}_test COMMAND ${PROJECT_NAME}_test)
72189
endif()

control/command_interface.hpp renamed to control/include/exploy/command_interface.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include <optional>
66
#include <string>
77

8-
#include "interfaces.hpp"
9-
#include "logging_utils.hpp"
8+
#include "exploy/interfaces.hpp"
9+
#include "exploy/logging_utils.hpp"
1010

1111
namespace exploy::control {
1212

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#include <regex>
66
#include <string>
77

8-
#include "command_interface.hpp"
9-
#include "metadata.hpp"
10-
#include "onnx_runtime.hpp"
11-
#include "state_interface.hpp"
8+
#include "exploy/command_interface.hpp"
9+
#include "exploy/metadata.hpp"
10+
#include "exploy/onnx_runtime.hpp"
11+
#include "exploy/state_interface.hpp"
1212

1313
namespace exploy::control {
1414

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#include <unordered_map>
88
#include <vector>
99

10-
#include "components.hpp"
11-
#include "matcher.hpp"
12-
#include "onnx_runtime.hpp"
10+
#include "exploy/components.hpp"
11+
#include "exploy/matcher.hpp"
12+
#include "exploy/onnx_runtime.hpp"
1313

1414
namespace exploy::control {
1515

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
#pragma once
44

5-
#include "command_interface.hpp"
6-
#include "context.hpp"
7-
#include "data_collection_interface.hpp"
8-
#include "interfaces.hpp"
9-
#include "onnx_runtime.hpp"
10-
#include "state_interface.hpp"
5+
#include "exploy/command_interface.hpp"
6+
#include "exploy/context.hpp"
7+
#include "exploy/data_collection_interface.hpp"
8+
#include "exploy/interfaces.hpp"
9+
#include "exploy/onnx_runtime.hpp"
10+
#include "exploy/state_interface.hpp"
1111

1212
#include <string>
1313
#include <unordered_map>
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)