cmake: Added GLPK support and docs
* Use Mizux/GLPK (Tag 5.0) * cmake: Fix swig flags * cmake: Update ortoolsConfig.cmake
This commit is contained in:
@@ -5,7 +5,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
include(utils)
|
||||
set_version(VERSION)
|
||||
|
||||
project(ortools VERSION ${VERSION} LANGUAGES CXX)
|
||||
project(ortools VERSION ${VERSION} LANGUAGES CXX C)
|
||||
set(PROJECT_NAMESPACE ortools)
|
||||
message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION}")
|
||||
#message(STATUS "major: ${PROJECT_VERSION_MAJOR}")
|
||||
@@ -136,6 +136,14 @@ if(USE_SCIP)
|
||||
message(STATUS "Build SCIP: ${BUILD_SCIP}")
|
||||
endif()
|
||||
|
||||
CMAKE_DEPENDENT_OPTION(USE_GLPK "Use the GLPK solver" ON "BUILD_CXX" OFF)
|
||||
message(STATUS "GLPK support: ${USE_GLPK}")
|
||||
if(USE_GLPK)
|
||||
CMAKE_DEPENDENT_OPTION(BUILD_GLPK "Build the GLPK dependency Library" OFF
|
||||
"NOT BUILD_DEPS" ON)
|
||||
message(STATUS "Build GLPK: ${BUILD_GLPK}")
|
||||
endif()
|
||||
|
||||
CMAKE_DEPENDENT_OPTION(USE_COINOR "Use the COIN-OR solver" ON "BUILD_CXX" OFF)
|
||||
message(STATUS "COIN-OR support: ${USE_COINOR}")
|
||||
if(USE_COINOR)
|
||||
|
||||
85
cmake/FindGLPK.cmake
Normal file
85
cmake/FindGLPK.cmake
Normal file
@@ -0,0 +1,85 @@
|
||||
#[=======================================================================[.rst:
|
||||
FindGLPK
|
||||
--------
|
||||
|
||||
This module determines the GLPK library of the system.
|
||||
|
||||
IMPORTED Targets
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module defines :prop_tgt:`IMPORTED` target ``GLPK::GLPK``, if
|
||||
GLPK has been found.
|
||||
|
||||
Result Variables
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This module defines the following variables:
|
||||
|
||||
::
|
||||
|
||||
GLPK_FOUND - True if GLPK found.
|
||||
|
||||
Hints
|
||||
^^^^^
|
||||
|
||||
A user may set ``GLPK_ROOT`` to a GLPK installation root to tell this
|
||||
module where to look.
|
||||
#]=======================================================================]
|
||||
# first specifically look for the CMake version of GLPK
|
||||
find_package(GLPK QUIET NO_MODULE)
|
||||
# if we found the GLPK cmake package then we are done.
|
||||
if(GLPK_FOUND)
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(GLPK_FOUND FALSE)
|
||||
if(CMAKE_C_COMPILER_LOADED)
|
||||
include (CheckIncludeFile)
|
||||
include (CheckCSourceCompiles)
|
||||
elseif(CMAKE_CXX_COMPILER_LOADED)
|
||||
include (CheckIncludeFileCXX)
|
||||
include (CheckCXXSourceCompiles)
|
||||
else()
|
||||
message(FATAL_ERROR "FindGLPK only works if either C or CXX language is enabled")
|
||||
endif()
|
||||
|
||||
if(NOT GLPK_ROOT)
|
||||
if (DEFINED ENV{GLPK_ROOT})
|
||||
set(GLPK_ROOT $ENV{GLPK_ROOT})
|
||||
else()
|
||||
find_path(GLPK_PATH libglpk.a libglpk.lib
|
||||
DOC "Path in which libglpk is found"
|
||||
PATHS
|
||||
"/usr/local/lib"
|
||||
"/usr/lib"
|
||||
"${CMAKE_BINARY_DIR}/dependencies/GLPK/source/w32"
|
||||
"${CMAKE_BINARY_DIR}/dependencies/GLPK/source/w64"
|
||||
"${CMAKE_BINARY_DIR}/dependencies/GLPK/source/src/.lib"
|
||||
)
|
||||
if(GLPK_PATH)
|
||||
set(GLPK_ROOT ${GLPK_PATH})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "GLPK_ROOT: ${GLPK_ROOT}")
|
||||
if(NOT GLPK_ROOT)
|
||||
message(FATAL_ERROR "GLPK_ROOT: not found")
|
||||
else()
|
||||
set(GLPK_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
if(GLPK_FOUND AND NOT TARGET GLPK::GLPK)
|
||||
add_library(GLPK::GLPK UNKNOWN IMPORTED)
|
||||
if (UNIX)
|
||||
set_property(TARGET GLPK::GLPK PROPERTY IMPORTED_LOCATION
|
||||
${GLPK_ROOT}/libglpk.a
|
||||
)
|
||||
elseif(MSVC)
|
||||
set_property(TARGET GLPK::GLPK PROPERTY IMPORTED_LOCATION
|
||||
${GLPK_ROOT}/libglpk.lib
|
||||
)
|
||||
else()
|
||||
message(FATAL_ERROR "OR-Tools with GLPK not supported for ${CMAKE_SYSTEM}")
|
||||
endif()
|
||||
endif()
|
||||
@@ -75,6 +75,9 @@ compile few of them using the options below (see [CMake Options](#cmake-options)
|
||||
* SCIP (`BUILD_SCIP`),<br>
|
||||
note: You can disable the support of SCIP solvers
|
||||
by using `-DUSE_SCIP=OFF` (`ON` by default).
|
||||
* GLPK (`BUILD_GLPK`),<br>
|
||||
note: You can disable the support of GLPK solvers
|
||||
by using `-DUSE_GLPK=OFF` (`ON` by default).
|
||||
|
||||
* COIN-OR solvers,
|
||||
* COIN-OR CoinUtils (`BUILD_CoinUtils`),
|
||||
@@ -152,6 +155,8 @@ cmake -S. -Bbuild -LH
|
||||
| `BUILD_Protobuf` | OFF* | Static build the protobuf libraries<br>**Forced** to ON if `BUILD_DEPS=ON` |
|
||||
| `USE_SCIP` | ON\* | Enable SCIP support<br>**Forced** to OFF if `BUILD_CXX=OFF` |
|
||||
| `BUILD_SCIP` | OFF\* | Static build the SCIP libraries<br>**Forced** to ON if `USE_SCIP=ON` **and** `BUILD_DEPS=ON` |
|
||||
| `USE_GLPK` | ON\* | Enable GLPK support<br>**Forced** to OFF if `BUILD_CXX=OFF` |
|
||||
| `BUILD_GLPK` | OFF\* | Static build the GLPK libraries<br>**Forced** to ON if `USE_GLPK=ON` **and** `BUILD_DEPS=ON` |
|
||||
| `USE_COINOR` | ON\* | Enable Coin-OR support<br>**Forced** to OFF if `BUILD_CXX=OFF` |
|
||||
| `BUILD_CoinUtils` | OFF\* | Static build the CoinUtils library<br>**Forced** to ON if `USE_COINOR=ON` **and** `BUILD_DEPS=ON` |
|
||||
| `BUILD_Osi` | OFF\* | Static build the Osi library<br>**Forced** to ON if `USE_COINOR=ON` **and** `BUILD_DEPS=ON` |
|
||||
|
||||
@@ -23,6 +23,9 @@ if(USE_SCIP)
|
||||
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "USE_SCIP")
|
||||
set(GSCIP_DIR gscip)
|
||||
endif()
|
||||
if(USE_GLPK)
|
||||
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS "USE_GLPK")
|
||||
endif()
|
||||
if(USE_COINOR)
|
||||
list(APPEND OR_TOOLS_COMPILE_DEFINITIONS
|
||||
"USE_CBC" # enable COIN-OR CBC support
|
||||
@@ -123,6 +126,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
|
||||
protobuf::libprotobuf
|
||||
${COINOR_DEPS}
|
||||
$<$<BOOL:${USE_SCIP}>:libscip>
|
||||
$<$<BOOL:${USE_GLPK}>:GLPK::GLPK>
|
||||
$<$<BOOL:${USE_CPLEX}>:CPLEX::CPLEX>
|
||||
$<$<BOOL:${USE_XPRESS}>:XPRESS::XPRESS>
|
||||
Threads::Threads)
|
||||
|
||||
@@ -102,6 +102,27 @@ if(BUILD_SCIP)
|
||||
message(CHECK_PASS "fetched")
|
||||
endif()
|
||||
|
||||
# ##############################################################################
|
||||
# GLPK
|
||||
# ##############################################################################
|
||||
if(BUILD_GLPK)
|
||||
message(CHECK_START "Fetching GLPK")
|
||||
list(APPEND CMAKE_MESSAGE_INDENT " ")
|
||||
set(BUILD_EXAMPLES OFF)
|
||||
set(WITH_GMP OFF)
|
||||
set(WITH_ODBC OFF)
|
||||
set(WITH_MYSQL OFF)
|
||||
|
||||
FetchContent_Declare(
|
||||
glpk
|
||||
GIT_REPOSITORY https://github.com/Mizux/GLPK.git
|
||||
GIT_TAG 5.0
|
||||
)
|
||||
FetchContent_MakeAvailable(glpk)
|
||||
list(POP_BACK CMAKE_MESSAGE_INDENT)
|
||||
message(CHECK_PASS "fetched")
|
||||
endif()
|
||||
|
||||
# ##############################################################################
|
||||
# Protobuf
|
||||
# ##############################################################################
|
||||
|
||||
@@ -54,6 +54,12 @@ if(USE_SCIP)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(USE_GLPK)
|
||||
if(NOT BUILD_GLPK)
|
||||
find_package(GLPK REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(USE_COINOR)
|
||||
if(NOT BUILD_CoinUtils)
|
||||
find_package(CoinUtils REQUIRED)
|
||||
|
||||
@@ -81,12 +81,15 @@ endif()
|
||||
# CMake will remove all '-D' prefix (i.e. -DUSE_FOO become USE_FOO)
|
||||
#get_target_property(FLAGS ${PROJECT_NAMESPACE}::ortools COMPILE_DEFINITIONS)
|
||||
set(FLAGS -DUSE_BOP -DUSE_GLOP -DABSL_MUST_USE_RESULT)
|
||||
if(USE_SCIP)
|
||||
list(APPEND FLAGS "-DUSE_SCIP")
|
||||
endif()
|
||||
if(USE_COINOR)
|
||||
list(APPEND FLAGS "-DUSE_CBC" "-DUSE_CLP")
|
||||
endif()
|
||||
if(USE_GLPK)
|
||||
list(APPEND FLAGS "-DUSE_GLPK")
|
||||
endif()
|
||||
if(USE_SCIP)
|
||||
list(APPEND FLAGS "-DUSE_SCIP")
|
||||
endif()
|
||||
list(APPEND CMAKE_SWIG_FLAGS ${FLAGS} "-I${PROJECT_SOURCE_DIR}")
|
||||
|
||||
# Needed by dotnet/CMakeLists.txt
|
||||
|
||||
@@ -56,12 +56,15 @@ set(JAVA_PROJECT ortools-java)
|
||||
# CMake will remove all '-D' prefix (i.e. -DUSE_FOO become USE_FOO)
|
||||
#get_target_property(FLAGS ${PROJECT_NAMESPACE}::ortools COMPILE_DEFINITIONS)
|
||||
set(FLAGS -DUSE_BOP -DUSE_GLOP -DABSL_MUST_USE_RESULT)
|
||||
if(USE_SCIP)
|
||||
list(APPEND FLAGS "-DUSE_SCIP")
|
||||
endif()
|
||||
if(USE_COINOR)
|
||||
list(APPEND FLAGS "-DUSE_CBC" "-DUSE_CLP")
|
||||
endif()
|
||||
if(USE_GLPK)
|
||||
list(APPEND FLAGS "-DUSE_GLPK")
|
||||
endif()
|
||||
if(USE_SCIP)
|
||||
list(APPEND FLAGS "-DUSE_SCIP")
|
||||
endif()
|
||||
list(APPEND CMAKE_SWIG_FLAGS ${FLAGS} "-I${PROJECT_SOURCE_DIR}")
|
||||
|
||||
# Generate Protobuf java sources
|
||||
|
||||
@@ -17,16 +17,11 @@ endif()
|
||||
if(NOT absl_FOUND)
|
||||
find_dependency(absl REQUIRED ${CONFIG_FLAG})
|
||||
endif()
|
||||
|
||||
if(NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND AND NOT TARGET protobuf::libprotobuf)
|
||||
find_dependency(Protobuf REQUIRED ${CONFIG_FLAG})
|
||||
endif()
|
||||
|
||||
if(@USE_SCIP@)
|
||||
if(NOT scip_FOUND AND NOT TARGET libscip)
|
||||
find_dependency(scip REQUIRED ${CONFIG_FLAG})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(@USE_COINOR@)
|
||||
if(NOT Clp_FOUND AND NOT TARGET Coin::ClpSolver)
|
||||
find_dependency(Clp REQUIRED ${CONFIG_FLAG})
|
||||
@@ -36,4 +31,16 @@ if(@USE_COINOR@)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(@USE_GLPK@)
|
||||
if(NOT GLPK_FOUND AND NOT TARGET GLPK::GLPK)
|
||||
find_dependency(GLPK REQUIRED ${CONFIG_FLAG})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(@USE_SCIP@)
|
||||
if(NOT scip_FOUND AND NOT TARGET libscip)
|
||||
find_dependency(scip REQUIRED ${CONFIG_FLAG})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
|
||||
@@ -149,12 +149,15 @@ add_custom_target(Py${PROJECT_NAME}_proto DEPENDS ${PROTO_PYS} ${PROJECT_NAMESPA
|
||||
# CMake will remove all '-D' prefix (i.e. -DUSE_FOO become USE_FOO)
|
||||
#get_target_property(FLAGS ${PROJECT_NAMESPACE}::ortools COMPILE_DEFINITIONS)
|
||||
set(FLAGS -DUSE_BOP -DUSE_GLOP -DABSL_MUST_USE_RESULT)
|
||||
if(USE_SCIP)
|
||||
list(APPEND FLAGS "-DUSE_SCIP")
|
||||
endif()
|
||||
if(USE_COINOR)
|
||||
list(APPEND FLAGS "-DUSE_CBC" "-DUSE_CLP")
|
||||
endif()
|
||||
if(USE_GLPK)
|
||||
list(APPEND FLAGS "-DUSE_GLPK")
|
||||
endif()
|
||||
if(USE_SCIP)
|
||||
list(APPEND FLAGS "-DUSE_SCIP")
|
||||
endif()
|
||||
list(APPEND CMAKE_SWIG_FLAGS ${FLAGS} "-I${PROJECT_SOURCE_DIR}")
|
||||
|
||||
set(PYTHON_PROJECT ${PROJECT_NAME})
|
||||
|
||||
@@ -23,10 +23,11 @@ target_link_libraries(${NAME} PRIVATE
|
||||
absl::strings
|
||||
absl::str_format
|
||||
protobuf::libprotobuf
|
||||
$<$<BOOL:${USE_SCIP}>:libscip>
|
||||
$<$<BOOL:${USE_GLPK}>:GLPK::GLPK>
|
||||
$<$<BOOL:${USE_COINOR}>:Coin::Cbc>
|
||||
$<$<BOOL:${USE_COINOR}>:Coin::Clp>
|
||||
$<$<BOOL:${USE_CPLEX}>:CPLEX::CPLEX>
|
||||
$<$<BOOL:${USE_XPRESS}>:XPRESS::XPRESS>
|
||||
$<$<BOOL:${USE_SCIP}>:libscip>
|
||||
${PROJECT_NAME}::proto)
|
||||
#add_library(${PROJECT_NAME}::linear_solver ALIAS ${NAME})
|
||||
|
||||
Reference in New Issue
Block a user