Skip to content

Commit 0d15b8c

Browse files
authored
[build] CMake options for solver opt-out (#22626)
1 parent bc0075b commit 0d15b8c

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

CMakeLists.txt

+23-3
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,30 @@ endif()
477477

478478
set(BAZEL_CONFIG)
479479

480-
option(WITH_GUROBI "Build with support for Gurobi" OFF)
480+
# Defines common options for open-source solver dependencies.
481+
# By default, these are all ON.
482+
# Passes the corresponding options to Bazel.
483+
function(open_solver_option SOLVER)
484+
string(TOUPPER "WITH_${SOLVER}" OPTION_NAME)
485+
string(TOLOWER "with_${SOLVER}" OPTION_BAZEL_ARG)
486+
option("${OPTION_NAME}" "Build with support for ${SOLVER}" ON)
487+
if(${OPTION_NAME})
488+
string(APPEND BAZEL_CONFIG " --@drake//tools/flags:${OPTION_BAZEL_ARG}=True")
489+
else()
490+
string(APPEND BAZEL_CONFIG " --@drake//tools/flags:${OPTION_BAZEL_ARG}=False")
491+
endif()
492+
set(BAZEL_CONFIG ${BAZEL_CONFIG} PARENT_SCOPE)
493+
endfunction()
481494

495+
open_solver_option("Clarabel")
496+
open_solver_option("CLP")
497+
open_solver_option("CSDP")
498+
open_solver_option("Ipopt")
499+
open_solver_option("NLopt")
500+
open_solver_option("OSQP")
501+
open_solver_option("SCS")
502+
503+
option(WITH_GUROBI "Build with support for Gurobi" OFF)
482504
if(WITH_GUROBI)
483505
find_package(Gurobi 10.0 EXACT MODULE REQUIRED)
484506

@@ -491,13 +513,11 @@ if(WITH_GUROBI)
491513
endif()
492514

493515
option(WITH_MOSEK "Build with support for MOSEK" OFF)
494-
495516
if(WITH_MOSEK)
496517
string(APPEND BAZEL_CONFIG " --config=mosek")
497518
endif()
498519

499520
option(WITH_OPENMP "Build with support for OpenMP" OFF)
500-
501521
if(WITH_OPENMP)
502522
string(APPEND BAZEL_CONFIG " --config=omp")
503523
endif()

bindings/pydrake/solvers/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ drake_py_unittest(
129129
name = "csdp_solver_test",
130130
args = select({
131131
"//tools/workspace/csdp_internal:enabled": [],
132-
"//conditions:default": ["TestCsdptSolver.unavailable"],
132+
"//conditions:default": ["TestCsdpSolver.unavailable"],
133133
}),
134134
deps = [
135135
":solvers",

doc/_pages/from_source.md

+8
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ Adjusting open-source dependencies:
9999
* WITH_USER_ZLIB (default ON). When ON, uses `find_package(ZLIB)` to locate a
100100
user-provided `ZLIB::ZLIB` library instead of building from source. Caveat:
101101
On macOS, for now this hardcodes `-lz` instead of calling `find_package`.
102+
* WITH_CLARABEL (default ON). When ON, enables the `ClarabelSolver`
103+
in the build.
104+
* WITH_CLP (default ON). When ON, enables the `ClpSolver` in the build.
105+
* WITH_CSDP (default ON). When ON, enables the `CsdpSolver` in the build.
106+
* WITH_IPOPT (default ON). When ON, enables the `IpoptSolver` in the build.
107+
* WITH_NLOPT (default ON). When ON, enables the `NloptSolver` in the build.
108+
* WITH_OSQP (default ON). When ON, enables the `OsqpSolver` in the build.
109+
* WITH_SCS (default ON). When ON, enables the `ScsSolver` in the build.
102110

103111
Adjusting closed-source (commercial) software dependencies:
104112

0 commit comments

Comments
 (0)