From f134f8921284803a99b16503b4766760be5fa6c9 Mon Sep 17 00:00:00 2001 From: tyler-yankee Date: Wed, 12 Feb 2025 13:48:37 -0500 Subject: [PATCH 1/4] add CMake options to disable open-source solvers, and update documentation to reflect --- CMakeLists.txt | 38 +++++++++++++++++++++++++++++++++++--- doc/_pages/from_source.md | 8 ++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e81a07ea4bc8..70b2d9060a8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -477,8 +477,42 @@ endif() set(BAZEL_CONFIG) -option(WITH_GUROBI "Build with support for Gurobi" OFF) +option(WITH_CLARABEL "Build with support for Clarabel" ON) +if(NOT WITH_CLARABEL) + string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_clarabel=False") +endif() +option(WITH_CLP "Build with support for CLP" ON) +if(NOT WITH_CLP) + string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_clp=False") +endif() + +option(WITH_CSDP "Build with support for CSDP" ON) +if(NOT WITH_CSDP) + string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_csdp=False") +endif() + +option(WITH_IPOPT "Build with support for Ipopt" ON) +if(NOT WITH_IPOPT) + string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_ipopt=False") +endif() + +option(WITH_NLOPT "Build with support for NLopt" ON) +if(NOT WITH_NLOPT) + string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_nlopt=False") +endif() + +option(WITH_OSQP "Build with support for OSQP" ON) +if(NOT WITH_OSQP) + string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_osqp=False") +endif() + +option(WITH_SCS "Build with support for SCS" ON) +if(NOT WITH_SCS) + string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_scs=False") +endif() + +option(WITH_GUROBI "Build with support for Gurobi" OFF) if(WITH_GUROBI) find_package(Gurobi 10.0 EXACT MODULE REQUIRED) @@ -491,13 +525,11 @@ if(WITH_GUROBI) endif() option(WITH_MOSEK "Build with support for MOSEK" OFF) - if(WITH_MOSEK) string(APPEND BAZEL_CONFIG " --config=mosek") endif() option(WITH_OPENMP "Build with support for OpenMP" OFF) - if(WITH_OPENMP) string(APPEND BAZEL_CONFIG " --config=omp") endif() diff --git a/doc/_pages/from_source.md b/doc/_pages/from_source.md index 00692b0e04b7..315daee8ab30 100644 --- a/doc/_pages/from_source.md +++ b/doc/_pages/from_source.md @@ -99,6 +99,14 @@ Adjusting open-source dependencies: * WITH_USER_ZLIB (default ON). When ON, uses `find_package(ZLIB)` to locate a user-provided `ZLIB::ZLIB` library instead of building from source. Caveat: On macOS, for now this hardcodes `-lz` instead of calling `find_package`. +* WITH_CLARABEL (default ON). When ON, enables the `ClarabelSolver` + in the build. +* WITH_CLP (default ON). When ON, enables the `ClpSolver` in the build. +* WITH_CSDP (default ON). When ON, enables the `CsdpSolver` in the build. +* WITH_IPOPT (default ON). When ON, enables the `IpoptSolver` in the build. +* WITH_NLOPT (default ON). When ON, enables the `NloptSolver` in the build. +* WITH_OSQP (default ON). When ON, enables the `OsqpSolver` in the build. +* WITH_SCS (default ON). When ON, enables the `ScsSolver` in the build. Adjusting closed-source (commercial) software dependencies: From f848b02282cda2128475aa9a10db704a086b9752 Mon Sep 17 00:00:00 2001 From: tyler-yankee Date: Wed, 12 Feb 2025 15:24:35 -0500 Subject: [PATCH 2/4] fix typo on CSDP test --- bindings/pydrake/solvers/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/pydrake/solvers/BUILD.bazel b/bindings/pydrake/solvers/BUILD.bazel index 02d3e23914ca..0ba0e0f35d7f 100644 --- a/bindings/pydrake/solvers/BUILD.bazel +++ b/bindings/pydrake/solvers/BUILD.bazel @@ -129,7 +129,7 @@ drake_py_unittest( name = "csdp_solver_test", args = select({ "//tools/workspace/csdp_internal:enabled": [], - "//conditions:default": ["TestCsdptSolver.unavailable"], + "//conditions:default": ["TestCsdpSolver.unavailable"], }), deps = [ ":solvers", From f085d664de7be525a64a4b54d37a84e19cd7bf65 Mon Sep 17 00:00:00 2001 From: tyler-yankee Date: Thu, 20 Feb 2025 11:38:42 -0500 Subject: [PATCH 3/4] refactor open source solver options into function --- CMakeLists.txt | 51 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 70b2d9060a8e..1f82fc69ac2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -477,40 +477,25 @@ endif() set(BAZEL_CONFIG) -option(WITH_CLARABEL "Build with support for Clarabel" ON) -if(NOT WITH_CLARABEL) - string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_clarabel=False") -endif() - -option(WITH_CLP "Build with support for CLP" ON) -if(NOT WITH_CLP) - string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_clp=False") -endif() - -option(WITH_CSDP "Build with support for CSDP" ON) -if(NOT WITH_CSDP) - string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_csdp=False") -endif() - -option(WITH_IPOPT "Build with support for Ipopt" ON) -if(NOT WITH_IPOPT) - string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_ipopt=False") -endif() - -option(WITH_NLOPT "Build with support for NLopt" ON) -if(NOT WITH_NLOPT) - string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_nlopt=False") -endif() - -option(WITH_OSQP "Build with support for OSQP" ON) -if(NOT WITH_OSQP) - string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_osqp=False") -endif() +# Defines common options for open-source solver dependencies. +# By default, these are all ON. +# Passes the corresponding options to Bazel. +function(open_solver_option SOLVER) + string(TOUPPER "WITH_${SOLVER}" OPTION_NAME) + string(TOLOWER "with_${SOLVER}" OPTION_BAZEL_ARG) + option("${OPTION_NAME}" "Build with support for ${SOLVER}" ON) + if(NOT ${OPTION_NAME}) + string(APPEND BAZEL_CONFIG " --@drake//tools/flags:${OPTION_BAZEL_ARG}=False") + endif() +endfunction() -option(WITH_SCS "Build with support for SCS" ON) -if(NOT WITH_SCS) - string(APPEND BAZEL_CONFIG " --@drake//tools/flags:with_scs=False") -endif() +open_solver_option("Clarabel") +open_solver_option("CLP") +open_solver_option("CSDP") +open_solver_option("Ipopt") +open_solver_option("NLopt") +open_solver_option("OSQP") +open_solver_option("SCS") option(WITH_GUROBI "Build with support for Gurobi" OFF) if(WITH_GUROBI) From 565130305be05a4d2071761442ae93ce5aadbcb7 Mon Sep 17 00:00:00 2001 From: tyler-yankee Date: Thu, 20 Feb 2025 16:21:05 -0500 Subject: [PATCH 4/4] bug fix: propagate BAZEL_CONFIG to PARENT_SCOPE --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f82fc69ac2e..d90551233185 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -487,6 +487,7 @@ function(open_solver_option SOLVER) if(NOT ${OPTION_NAME}) string(APPEND BAZEL_CONFIG " --@drake//tools/flags:${OPTION_BAZEL_ARG}=False") endif() + set(BAZEL_CONFIG ${BAZEL_CONFIG} PARENT_SCOPE) endfunction() open_solver_option("Clarabel")