Skip to content

Commit 9dbbeee

Browse files
authored
Merge pull request #347 from nim65s/standalone
CMake: BUILD_STANDALONE_PYTHON_INTERFACE
2 parents 7cc011c + e95df11 commit 9dbbeee

File tree

7 files changed

+103
-57
lines changed

7 files changed

+103
-57
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- gar: add CTAD for the `ParallelRiccatiSolver` and `ProximalRiccatiSolver` classes
2525
- testing: added a test_mpc.py script to test parallel and serial mpc implementations (https://github.com/Simple-Robotics/aligator/pull/331)
2626
- modelling : added wheeled inverted pendulum dynamics (https://github.com/Simple-Robotics/aligator/pull/326)
27+
- CMake option to `BUILD_STANDALONE_PYTHON_INTERFACE` (https://github.com/Simple-Robotics/aligator/pull/347)
2728

2829
## [0.15.0] - 2025-05-23
2930

CMakeLists.txt

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ function(set_standard_output_directory target)
124124
endfunction()
125125

126126
# --- OPTIONS ----------------------------------------
127-
option(BUILD_PYTHON_INTERFACE "Build the Python bindings" ON)
128127
option(
129128
BUILD_WITH_VERSION_SUFFIX
130129
"Build libraries with version appended to suffix"
@@ -409,17 +408,21 @@ function(create_library)
409408
endforeach()
410409
endfunction()
411410

412-
create_library()
411+
if(BUILD_STANDALONE_PYTHON_INTERFACE)
412+
ADD_PROJECT_DEPENDENCY(${PROJECT_NAME} REQUIRED CONFIG)
413+
else()
414+
create_library()
413415

414-
ADD_HEADER_GROUP(LIB_HEADERS)
415-
ADD_SOURCE_GROUP(LIB_SOURCES)
416+
ADD_HEADER_GROUP(LIB_HEADERS)
417+
ADD_SOURCE_GROUP(LIB_SOURCES)
416418

417-
install(
418-
TARGETS ${PROJECT_NAME}
419-
EXPORT ${TARGETS_EXPORT_NAME}
420-
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
421-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
422-
)
419+
install(
420+
TARGETS ${PROJECT_NAME}
421+
EXPORT ${TARGETS_EXPORT_NAME}
422+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
423+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
424+
)
425+
endif()
423426

424427
if(DOWNLOAD_TRACY)
425428
install(
@@ -434,7 +437,7 @@ if(DOWNLOAD_TRACY)
434437
)
435438
endif()
436439

437-
if(BUILD_CROCODDYL_COMPAT)
440+
if(BUILD_CROCODDYL_COMPAT AND NOT BUILD_STANDALONE_PYTHON_INTERFACE)
438441
ADD_PROJECT_DEPENDENCY(crocoddyl 3.0.1 REQUIRED)
439442
add_subdirectory(src/compat/crocoddyl)
440443
endif()
@@ -478,7 +481,11 @@ endif()
478481

479482
# create an utility library to avoid recompiling crocoddyl talos arm problem
480483
# used in examples and benchmarks
481-
if(BUILD_CROCODDYL_COMPAT AND (BUILD_EXAMPLES OR BUILD_BENCHMARKS))
484+
if(
485+
NOT BUILD_STANDALONE_PYTHON_INTERFACE
486+
AND BUILD_CROCODDYL_COMPAT
487+
AND (BUILD_EXAMPLES OR BUILD_BENCHMARKS)
488+
)
482489
add_library(
483490
croc_talos_arm_utils
484491
STATIC
@@ -500,7 +507,10 @@ if(BUILD_CROCODDYL_COMPAT AND (BUILD_EXAMPLES OR BUILD_BENCHMARKS))
500507
set_standard_output_directory(croc_talos_arm_utils)
501508
endif()
502509

503-
if(BUILD_BENCHMARKS OR BUILD_TESTING)
510+
if(
511+
NOT BUILD_STANDALONE_PYTHON_INTERFACE
512+
AND (BUILD_BENCHMARKS OR BUILD_TESTING)
513+
)
504514
add_library(
505515
gar_test_utils
506516
STATIC
@@ -510,7 +520,10 @@ if(BUILD_BENCHMARKS OR BUILD_TESTING)
510520
set_standard_output_directory(gar_test_utils)
511521
endif()
512522

513-
if(BUILD_EXAMPLES OR BUILD_BENCHMARKS)
523+
if(
524+
NOT BUILD_STANDALONE_PYTHON_INTERFACE
525+
AND (BUILD_EXAMPLES OR BUILD_BENCHMARKS)
526+
)
514527
add_library(
515528
talos_walk_utils
516529
STATIC
@@ -535,7 +548,7 @@ if(BUILD_EXAMPLES)
535548
add_subdirectory(examples)
536549
endif()
537550

538-
if(BUILD_BENCHMARKS)
551+
if(BUILD_BENCHMARKS AND NOT BUILD_STANDALONE_PYTHON_INTERFACE)
539552
find_package(benchmark REQUIRED)
540553
add_subdirectory(bench)
541554
endif()

bindings/python/CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ endfunction()
7474

7575
make_bindings()
7676

77-
install(
78-
DIRECTORY ${PY_HEADER_DIR}
79-
DESTINATION "include/${PROJECT_NAME}"
80-
FILES_MATCHING
81-
PATTERN "*.hpp"
82-
)
77+
if(NOT BUILD_STANDALONE_PYTHON_INTERFACE)
78+
install(
79+
DIRECTORY ${PY_HEADER_DIR}
80+
DESTINATION "include/${PROJECT_NAME}"
81+
FILES_MATCHING
82+
PATTERN "*.hpp"
83+
)
84+
endif()
8385

8486
if(IS_ABSOLUTE ${PYTHON_SITELIB})
8587
set(ABSOLUTE_PYTHON_SITELIB ${PYTHON_SITELIB})

examples/CMakeLists.txt

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# Copyright (C) 2022-2024 LAAS-CNRS, INRIA
33
#
44

5-
cmake_policy(SET CMP0057 NEW)
6-
75
# Create an example
86
function(create_example exfile)
97
set(options "")
@@ -23,25 +21,29 @@ function(create_example exfile)
2321
create_ex_or_bench(${exfile} ${exname} DEPENDENCIES ${arg_crex_DEPENDENCIES})
2422
endfunction()
2523

26-
create_example(clqr.cpp)
27-
create_example(talos-walk.cpp DEPENDENCIES talos_walk_utils)
28-
create_example(se2-car.cpp)
29-
30-
if(BUILD_CROCODDYL_COMPAT)
31-
ADD_PROJECT_PRIVATE_DEPENDENCY(example-robot-data 4.0.9 REQUIRED)
32-
create_example(
33-
talos-arm.cpp
34-
DEPENDENCIES aligator::croc_compat croc_talos_arm_utils
35-
)
24+
if(NOT BUILD_STANDALONE_PYTHON_INTERFACE)
25+
create_example(clqr.cpp)
26+
create_example(talos-walk.cpp DEPENDENCIES talos_walk_utils)
27+
create_example(se2-car.cpp)
28+
29+
if(BUILD_CROCODDYL_COMPAT)
30+
ADD_PROJECT_PRIVATE_DEPENDENCY(example-robot-data 4.0.9 REQUIRED)
31+
create_example(
32+
talos-arm.cpp
33+
DEPENDENCIES aligator::croc_compat croc_talos_arm_utils
34+
)
35+
endif()
3636
endif()
3737

38-
file(GLOB EXAMPLES_PY *.py)
39-
40-
foreach(pyfile ${EXAMPLES_PY})
41-
get_filename_component(pyfile_name ${pyfile} NAME)
42-
execute_process(
43-
COMMAND
44-
${CMAKE_COMMAND} -E create_symlink ${pyfile}
45-
${CMAKE_CURRENT_BINARY_DIR}/${pyfile_name}
46-
)
47-
endforeach()
38+
if(BUILD_PYTHON_INTERFACE)
39+
file(GLOB EXAMPLES_PY *.py)
40+
41+
foreach(pyfile ${EXAMPLES_PY})
42+
get_filename_component(pyfile_name ${pyfile} NAME)
43+
execute_process(
44+
COMMAND
45+
${CMAKE_COMMAND} -E create_symlink ${pyfile}
46+
${CMAKE_CURRENT_BINARY_DIR}/${pyfile_name}
47+
)
48+
endforeach()
49+
endif()

flake.nix

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
systems = inputs.nixpkgs.lib.systems.flakeExposed;
1313
perSystem =
1414
{
15+
lib,
1516
pkgs,
1617
self',
1718
...
@@ -21,13 +22,12 @@
2122
type = "app";
2223
program = pkgs.python3.withPackages (_: [ self'.packages.default ]);
2324
};
24-
devShells.default = pkgs.mkShell { inputsFrom = [ self'.packages.default ]; };
2525
packages = {
26-
default = self'.packages.aligator;
27-
aligator = pkgs.python3Packages.aligator.overrideAttrs {
28-
src = pkgs.lib.fileset.toSource {
26+
default = self'.packages.py-aligator;
27+
aligator = pkgs.aligator.overrideAttrs {
28+
src = lib.fileset.toSource {
2929
root = ./.;
30-
fileset = pkgs.lib.fileset.unions [
30+
fileset = lib.fileset.unions [
3131
./bench
3232
./bindings
3333
./CMakeLists.txt
@@ -41,6 +41,31 @@
4141
];
4242
};
4343
};
44+
py-aligator = pkgs.python3Packages.toPythonModule (self'.packages.aligator.overrideAttrs (super:{
45+
cmakeFlags = super.cmakeFlags ++ [
46+
(lib.cmakeBool "BUILD_PYTHON_INTERFACE" true)
47+
(lib.cmakeBool "BUILD_STANDALONE_PYTHON_INTERFACE" true)
48+
];
49+
nativeBuildInputs = super.nativeBuildInputs ++ [
50+
pkgs.python3Packages.python
51+
];
52+
propagatedBuildInputs = super.propagatedBuildInputs ++ [
53+
self'.packages.aligator
54+
pkgs.python3Packages.crocoddyl
55+
pkgs.python3Packages.pinocchio
56+
];
57+
nativeCheckInputs = [
58+
pkgs.ctestCheckHook
59+
pkgs.python3Packages.pythonImportsCheckHook
60+
];
61+
checkInputs = super.checkInputs++ [
62+
pkgs.python3Packages.matplotlib
63+
pkgs.python3Packages.pytest
64+
];
65+
disabledTests = lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
66+
"aligator-test-py-rollout"
67+
];
68+
}));
4469
};
4570
};
4671
};

src/compat/crocoddyl/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ file(GLOB_RECURSE HEADERS ${INCLUDE_DIR}/*.hpp ${INCLUDE_DIR}/*.hxx)
88
add_library(aligator_croc_compat SHARED ${HEADERS})
99
add_library(aligator::croc_compat ALIAS aligator_croc_compat)
1010

11+
set_target_properties(aligator_croc_compat PROPERTIES EXPORT_NAME croc_compat)
12+
1113
if(ENABLE_TEMPLATE_INSTANTIATION)
1214
file(GLOB SOURCES_TEMPL ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
1315
list(APPEND HEADERS ${HEADERS_TEMPL})

tests/CMakeLists.txt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,18 @@ if(CHECK_RUNTIME_MALLOC)
6565
list(APPEND TEST_NAMES nomalloc)
6666
endif()
6767

68-
foreach(test_name ${TEST_NAMES})
69-
add_aligator_test(${test_name})
70-
endforeach()
71-
72-
add_subdirectory(gar)
68+
if(NOT BUILD_STANDALONE_PYTHON_INTERFACE)
69+
foreach(test_name ${TEST_NAMES})
70+
add_aligator_test(${test_name})
71+
endforeach()
72+
add_subdirectory(gar)
73+
74+
if(BUILD_CROCODDYL_COMPAT)
75+
add_subdirectory(compat)
76+
endif()
77+
endif()
7378

7479
# PYTHON TESTS
7580
if(BUILD_PYTHON_INTERFACE)
7681
add_subdirectory(python)
7782
endif()
78-
79-
if(BUILD_CROCODDYL_COMPAT)
80-
add_subdirectory(compat)
81-
endif()

0 commit comments

Comments
 (0)