Skip to content

Commit

Permalink
cmake: Add math_opt/
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Sep 1, 2023
1 parent 546f612 commit 248949d
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down Expand Up @@ -401,7 +405,15 @@ include(dotnet)

# Since samples mix all languages we must parse them once we have included all
# <language>.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()

Expand Down
12 changes: 12 additions & 0 deletions cmake/cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -261,6 +272,7 @@ foreach(SUBPROJECT IN ITEMS
bop
constraint_solver
${GLPK_DIR}
${MATH_OPT_DIR}
${PDLP_DIR}
${GSCIP_DIR}
glop
Expand Down
50 changes: 50 additions & 0 deletions ortools/math_opt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>)
target_link_libraries(${NAME} PRIVATE
absl::strings
protobuf::libprotobuf
$<$<BOOL:${USE_GLPK}>:GLPK::GLPK>
$<$<BOOL:${USE_SCIP}>:libscip>
${PROJECT_NAME}::proto)
#add_library(${PROJECT_NAME}::math_opt ALIAS ${NAME})
40 changes: 40 additions & 0 deletions ortools/math_opt/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 248949d

Please sign in to comment.