From a5d66fb4ffcda9024c7fa0ac8e42a164dfe52804 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sat, 27 Jun 2026 12:11:54 -0700 Subject: [PATCH] [build] Add CMake option to use system Sleipnir install (#9028) This allows using an alternate version from FetchContent. --- CMakeLists.txt | 3 ++- wpimath/CMakeLists.txt | 43 +++++++++++++++++++++++---------- wpimath/wpimath-config.cmake.in | 4 +++ 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc832067cb..6c2745e949 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,9 +84,10 @@ option(WITH_SIMULATION_MODULES "Build simulation modules" ON) option(WITH_BENCHMARK "Build the benchmark project" ON) # Options for using a package manager (e.g., vcpkg) for certain dependencies. +option(USE_SYSTEM_EIGEN "Use system Eigen" OFF) option(USE_SYSTEM_FMTLIB "Use system fmtlib" OFF) option(USE_SYSTEM_LIBUV "Use system libuv" OFF) -option(USE_SYSTEM_EIGEN "Use system eigen" OFF) +option(USE_SYSTEM_SLEIPNIR "Use system Sleipnir" OFF) option(USE_LINKED_AVAHI "Use directly linked Avahi instead of loading at runtime" OFF) # Options for compilation flags. diff --git a/wpimath/CMakeLists.txt b/wpimath/CMakeLists.txt index c74a443dab..5df3a1aab5 100644 --- a/wpimath/CMakeLists.txt +++ b/wpimath/CMakeLists.txt @@ -20,13 +20,11 @@ file( src/main/native/cpp/jni/optimization/ProblemJNI.cpp ) -file( - GLOB_RECURSE wpimath_native_src - src/main/native/cpp/*.cpp - src/main/native/thirdparty/sleipnir/src/*.cpp -) +file(GLOB_RECURSE wpimath_native_src src/main/native/cpp/*.cpp) list(REMOVE_ITEM wpimath_native_src ${wpimath_jni_src}) +file(GLOB_RECURSE sleipnir_native_src src/main/native/thirdparty/sleipnir/src/*.cpp) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS FALSE) file(GLOB_RECURSE wpimath_protobuf_native_src src/generated/main/native/cpp/wpimath/protobuf/*.cpp) @@ -86,19 +84,38 @@ else() target_link_libraries(wpimath Eigen3::Eigen) endif() -install( - DIRECTORY src/main/native/thirdparty/gcem/include/ src/main/native/thirdparty/sleipnir/include/ - DESTINATION "${include_dest}/wpimath" -) +install(DIRECTORY src/main/native/thirdparty/gcem/include/ DESTINATION "${include_dest}/wpimath") target_include_directories( wpimath SYSTEM - PUBLIC - $ - $ - $ + PUBLIC $ ) +if(NOT USE_SYSTEM_SLEIPNIR) + target_sources(wpimath PRIVATE ${sleipnir_native_src}) + install( + DIRECTORY src/main/native/thirdparty/sleipnir/include/ + DESTINATION "${include_dest}/wpimath" + ) + target_include_directories( + wpimath + SYSTEM + PUBLIC + $ + $ + ) +else() + find_package(Sleipnir CONFIG REQUIRED) + target_link_libraries(wpimath Sleipnir::Sleipnir) + if(MSVC) + get_target_property(Sleipnir_includes Sleipnir::Sleipnir INTERFACE_INCLUDE_DIRECTORIES) + foreach(dir ${Sleipnir_includes}) + target_compile_options(wpimath PUBLIC /external:I "${dir}") + endforeach() + target_compile_options(wpimath PUBLIC /external:W0) + endif() +endif() + install( DIRECTORY src/generated/main/native/cpp/ DESTINATION "${include_dest}/wpimath" diff --git a/wpimath/wpimath-config.cmake.in b/wpimath/wpimath-config.cmake.in index 9100d7943d..62daba04cd 100644 --- a/wpimath/wpimath-config.cmake.in +++ b/wpimath/wpimath-config.cmake.in @@ -6,5 +6,9 @@ if(@USE_SYSTEM_EIGEN@) find_dependency(Eigen3) endif() +if(@USE_SYSTEM_SLEIPNIR@) + find_dependency(Sleipnir) +endif() + @FILENAME_DEP_REPLACE@ include(${SELF_DIR}/wpimath.cmake)