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
98include (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.
1226add_compile_options (-Werror -Wpedantic -Wunused-variable -Wunused-parameter -Wreorder )
1327
14- # Find dependencies
28+ # Find dependencies.
1529find_package (Eigen3 REQUIRED )
1630find_package (nlohmann_json REQUIRED )
1731find_package (fmt REQUIRED )
1832find_package (onnxruntime REQUIRED )
1933
20- # C++ Shared Library
34+ # ==============
35+ # Exploy library
36+ # ==============
37+
38+ # C++ shared library.
2139add_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.
3176target_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+
39157if (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 )
72189endif ()
0 commit comments