From 248949dcf3d983cbc29291cb2b09ce6856ce0765 Mon Sep 17 00:00:00 2001 From: Mizux Seiha Date: Fri, 1 Sep 2023 00:24:31 +0200 Subject: [PATCH] cmake: Add math_opt/ --- CMakeLists.txt | 14 ++++++- cmake/cpp.cmake | 12 ++++++ ortools/math_opt/CMakeLists.txt | 50 +++++++++++++++++++++++++ ortools/math_opt/samples/CMakeLists.txt | 40 ++++++++++++++++++++ 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 ortools/math_opt/CMakeLists.txt create mode 100644 ortools/math_opt/samples/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index fa1ac5f002d..57adf676d20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,6 +121,10 @@ message(STATUS "Build Flatzinc: ${BUILD_FLATZINC}") CMAKE_DEPENDENT_OPTION(BUILD_LP_PARSER "Build lp_parser" ON "BUILD_CXX" OFF) message(STATUS "Build LP Parser: ${BUILD_LP_PARSER}") +## MathOpt +CMAKE_DEPENDENT_OPTION(BUILD_MATH_OPT "Build the MATH_OPT" ON "BUILD_CXX" OFF) +message(STATUS "Build MathOpt: ${BUILD_MATH_OPT}") + CMAKE_DEPENDENT_OPTION(BUILD_GLOP "Build GLOP standalone" ON "NOT BUILD_CXX" OFF) message(STATUS "Build standalone Glop: ${BUILD_GLOP}") @@ -401,7 +405,15 @@ include(dotnet) # Since samples mix all languages we must parse them once we have included all # .cmake files -foreach(SAMPLES IN ITEMS algorithms graph glop constraint_solver linear_solver pdlp sat) +foreach(SAMPLES IN ITEMS + algorithms + graph + glop + constraint_solver + linear_solver + ${MATH_OPT_DIR} + ${PDLP_DIR} + sat) add_subdirectory(ortools/${SAMPLES}/samples) endforeach() diff --git a/cmake/cpp.cmake b/cmake/cpp.cmake index f03d56b2aac..78e6fa82e85 100644 --- a/cmake/cpp.cmake +++ b/cmake/cpp.cmake @@ -35,6 +35,10 @@ list(APPEND OR_TOOLS_COMPILE_DEFINITIONS if(BUILD_LP_PARSER) list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "USE_LP_PARSER") endif() +if(BUILD_MATH_OPT) + list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "USE_MATH_OPT") + set(MATH_OPT_DIR math_opt) +endif() if(USE_COINOR) list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "USE_CBC" # enable COIN-OR CBC support @@ -188,6 +192,13 @@ file(GLOB_RECURSE proto_files RELATIVE ${PROJECT_SOURCE_DIR} "ortools/scheduling/*.proto" "ortools/util/*.proto" ) +if(BUILD_MATH_OPT) + file(GLOB_RECURSE math_opt_proto_files RELATIVE ${PROJECT_SOURCE_DIR} + "ortools/math_opt/*.proto" + "ortools/math_opt/solvers/*.proto" + ) + list(APPEND proto_files ${math_opt_proto_files}) +endif() if(USE_PDLP) file(GLOB_RECURSE pdlp_proto_files RELATIVE ${PROJECT_SOURCE_DIR} "ortools/pdlp/*.proto") list(APPEND proto_files ${pdlp_proto_files}) @@ -261,6 +272,7 @@ foreach(SUBPROJECT IN ITEMS bop constraint_solver ${GLPK_DIR} + ${MATH_OPT_DIR} ${PDLP_DIR} ${GSCIP_DIR} glop diff --git a/ortools/math_opt/CMakeLists.txt b/ortools/math_opt/CMakeLists.txt new file mode 100644 index 00000000000..65f835d36a1 --- /dev/null +++ b/ortools/math_opt/CMakeLists.txt @@ -0,0 +1,50 @@ +# Copyright 2010-2022 Google LLC +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if(NOT BUILD_MATH_OPT) + return() +endif() + +file(GLOB_RECURSE _SRCS "*.h" "*.cc") +list(FILTER _SRCS EXCLUDE REGEX "/c_api/") +list(FILTER _SRCS EXCLUDE REGEX "/tools/") +list(FILTER _SRCS EXCLUDE REGEX "/samples/") + +if(NOT USE_GLPK) + list(FILTER _SRCS EXCLUDE REGEX "/glpk/") + list(FILTER _SRCS EXCLUDE REGEX "/glpk_.*.h$") + list(FILTER _SRCS EXCLUDE REGEX "/glpk_.*.cc$") +endif() + +if(NOT USE_SCIP) + list(FILTER _SRCS EXCLUDE REGEX "/gscip/") +endif() + +set(NAME ${PROJECT_NAME}_math_opt) + +# Will be merge in libortools.so +#add_library(${NAME} STATIC ${_SRCS}) +add_library(${NAME} OBJECT ${_SRCS}) +set_target_properties(${NAME} PROPERTIES + POSITION_INDEPENDENT_CODE ON + ) +target_include_directories(${NAME} PUBLIC + $ + $) +target_link_libraries(${NAME} PRIVATE + absl::strings + protobuf::libprotobuf + $<$:GLPK::GLPK> + $<$:libscip> + ${PROJECT_NAME}::proto) +#add_library(${PROJECT_NAME}::math_opt ALIAS ${NAME}) diff --git a/ortools/math_opt/samples/CMakeLists.txt b/ortools/math_opt/samples/CMakeLists.txt new file mode 100644 index 00000000000..3904f481c53 --- /dev/null +++ b/ortools/math_opt/samples/CMakeLists.txt @@ -0,0 +1,40 @@ +# Copyright 2010-2022 Google LLC +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if(NOT BUILD_SAMPLES) + return() +endif() + +if(BUILD_CXX_SAMPLES) + file(GLOB CXX_SRCS "*.cc") + list(FILTER CXX_SRCS EXCLUDE REGEX "area_socp.cc$") + + # conflict name + list(FILTER CXX_SRCS EXCLUDE REGEX "basic_example.cc$") + list(FILTER CXX_SRCS EXCLUDE REGEX "tsp.cc$") + list(FILTER CXX_SRCS EXCLUDE REGEX "integer_programming.cc$") + list(FILTER CXX_SRCS EXCLUDE REGEX "linear_programming.cc$") + list(FILTER CXX_SRCS EXCLUDE REGEX "linear_regression.cc$") + + + foreach(SAMPLE IN LISTS CXX_SRCS) + add_cxx_sample(${SAMPLE}) + endforeach() +endif() + +if(BUILD_PYTHON_SAMPLES) + file(GLOB PYTHON_SRCS "*.py") + foreach(SAMPLE IN LISTS PYTHON_SRCS) + add_python_sample(${SAMPLE}) + endforeach() +endif()