2018-02-21 14:20:23 +01:00
# OR-Tools CMake Build Instructions
2021-06-18 15:02:56 +02:00
| OS | C++ | Python | Java | .NET |
|:-------- | :---: | :------: | :----: | :----: |
| Linux | [![Status][linux_cpp_svg]][linux_cpp_link] | [![Status][linux_python_svg]][linux_python_link] | [![Status][linux_java_svg]][linux_java_link] | [![Status][linux_dotnet_svg]][linux_dotnet_link] |
| MacOS | [![Status][macos_cpp_svg]][macos_cpp_link] | [![Status][macos_python_svg]][macos_python_link] | [![Status][macos_java_svg]][macos_java_link] | [![Status][macos_dotnet_svg]][macos_dotnet_link] |
| Windows | [![Status][windows_cpp_svg]][windows_cpp_link] | [![Status][windows_python_svg]][windows_python_link] | [![Status][windows_java_svg]][windows_java_link] | [![Status][windows_dotnet_svg]][windows_dotnet_link] |
[linux_cpp_svg]: https://github.com/google/or-tools/actions/workflows/cmake_linux_cpp.yml/badge.svg?branch=master
[linux_cpp_link]: https://github.com/google/or-tools/actions/workflows/cmake_linux_cpp.yml
[linux_python_svg]: https://github.com/google/or-tools/actions/workflows/cmake_linux_python.yml/badge.svg?branch=master
[linux_python_link]: https://github.com/google/or-tools/actions/workflows/cmake_linux_python.yml
[linux_java_svg]: https://github.com/google/or-tools/actions/workflows/cmake_linux_java.yml/badge.svg?branch=master
[linux_java_link]: https://github.com/google/or-tools/actions/workflows/cmake_linux_java.yml
[linux_dotnet_svg]: https://github.com/google/or-tools/actions/workflows/cmake_linux_dotnet.yml/badge.svg?branch=master
[linux_dotnet_link]: https://github.com/google/or-tools/actions/workflows/cmake_linux_dotnet.yml
[macos_cpp_svg]: https://github.com/google/or-tools/actions/workflows/cmake_macos_cpp.yml/badge.svg?branch=master
[macos_cpp_link]: https://github.com/google/or-tools/actions/workflows/cmake_macos_cpp.yml
[macos_python_svg]: https://github.com/google/or-tools/actions/workflows/cmake_macos_python.yml/badge.svg?branch=master
[macos_python_link]: https://github.com/google/or-tools/actions/workflows/cmake_macos_python.yml
[macos_java_svg]: https://github.com/google/or-tools/actions/workflows/cmake_macos_java.yml/badge.svg?branch=master
[macos_java_link]: https://github.com/google/or-tools/actions/workflows/cmake_macos_java.yml
[macos_dotnet_svg]: https://github.com/google/or-tools/actions/workflows/cmake_macos_dotnet.yml/badge.svg?branch=master
[macos_dotnet_link]: https://github.com/google/or-tools/actions/workflows/cmake_macos_dotnet.yml
[windows_cpp_svg]: https://github.com/google/or-tools/actions/workflows/cmake_windows_cpp.yml/badge.svg?branch=master
[windows_cpp_link]: https://github.com/google/or-tools/actions/workflows/cmake_windows_cpp.yml
[windows_python_svg]: https://github.com/google/or-tools/actions/workflows/cmake_windows_python.yml/badge.svg?branch=master
[windows_python_link]: https://github.com/google/or-tools/actions/workflows/cmake_windows_python.yml
[windows_java_svg]: https://github.com/google/or-tools/actions/workflows/cmake_windows_java.yml/badge.svg?branch=master
[windows_java_link]: https://github.com/google/or-tools/actions/workflows/cmake_windows_java.yml
[windows_dotnet_svg]: https://github.com/google/or-tools/actions/workflows/cmake_windows_dotnet.yml/badge.svg?branch=master
[windows_dotnet_link]: https://github.com/google/or-tools/actions/workflows/cmake_windows_dotnet.yml
Dockers [Alpine, Archlinux, Centos, Debian, Fedora, OpenSuse, Ubuntu]x[C++, Python, Java, .Net]: [![Status][docker_svg]][docker_link]
[docker_svg]: https://github.com/google/or-tools/actions/workflows/cmake_docker.yml/badge.svg?branch=master
[docker_link]: https://github.com/google/or-tools/actions/workflows/cmake_docker.yml
2020-04-01 14:27:33 +02:00
2020-03-06 16:16:52 +01:00
## Introduction
2020-02-28 17:12:42 +01:00
< nav for = "cmake" > |
< a href = " #deps " > Dependencies</ a > |
2021-03-31 12:24:15 +02:00
< a href = " #options " > Options</ a > |
2020-03-04 17:42:26 +01:00
< a href = "doc/cpp.md" > C++< / a > |
< a href = "doc/swig.md" > Swig< / a > |
< a href = "doc/python.md" > Python 3< / a > |
< a href = "doc/dotnet.md" > .Net Core< / a > |
< a href = "doc/java.md" > Java< / a > |
2020-02-28 17:12:42 +01:00
< a href = " #integration " > Integration</ a > |
2020-03-30 12:48:21 +02:00
< a href = "doc/ci.md" > CI< / a > |
2020-02-28 17:12:42 +01:00
< / nav >
OR-Tools comes with a CMake based build ([CMakeLists.txt ](../CMakeLists.txt ))
2018-02-21 14:20:23 +01:00
that can be used on a wide range of platforms (the "C" stands for
cross-platform). If you don't have CMake installed already, you can download it
for free from < http: / / www . cmake . org / > .
CMake works by generating native Makefiles or build projects that can be used in
the compiler environment of your choice.< br > You can either build OR-Tools with
CMake as a standalone project or it can be incorporated into an existing CMake
project.
2021-03-31 12:24:15 +02:00
< a name = "deps" > < / a >
2021-04-02 09:59:27 +02:00
2021-03-31 12:24:15 +02:00
## Dependencies
2018-02-21 14:20:23 +01:00
2020-02-28 17:12:42 +01:00
OR-Tools depends on severals mandatory libraries. You can compile them all at
configure time using the option `-DBUILD_DEPS=ON` (`OFF` by default) or you can
compile few of them using the options below.
2018-02-21 14:20:23 +01:00
2020-04-01 14:27:33 +02:00
* ZLIB (`BUILD_ZLIB` ),
* Google Abseil-cpp (`BUILD_absl` ),
* Google Protobuf (`BUILD_Protobuf` ),
2020-11-09 10:22:31 +01:00
* SCIP (`BUILD_SCIP` ),< br >
note: You can disable the support of SCIP solvers
by using `-DUSE_SCIP=OFF` (`ON` by default).
* COIN-OR solvers,
* COIN-OR CoinUtils (`BUILD_CoinUtils` ),
* COIN-OR Osi (`BUILD_Osi` ),
* COIN-OR Clp (`BUILD_Clp` ),
* COIN-OR Cgl (`BUILD_Cgl` ),
* COIN-OR Cbc (`BUILD_Cbc` ),< br >
note: You can disable the support of COIN-OR solvers (i.e. Cbc and Clp solver)
by using `-DUSE_COINOR=OFF` (`ON` by default).
2020-02-28 17:12:42 +01:00
2020-03-06 16:16:52 +01:00
OR-Tools also have few (ed compile time) optional solvers support (disabled by
default):
2018-02-21 14:20:23 +01:00
2020-11-09 10:22:31 +01:00
* CPLEX (`USE_CPLEX` ),
* XPRESS (`USE_XPRESS` )
2020-02-28 17:12:42 +01:00
2020-03-06 16:16:52 +01:00
**warning: Since these solvers require license and are proprietary, we can't
test it on public CI and support can be broken.**
2021-03-31 12:24:15 +02:00
< a name = "options" > < / a >
2021-04-02 09:59:27 +02:00
2021-03-31 12:24:15 +02:00
## CMake Options
2021-04-02 09:59:27 +02:00
2021-03-31 12:24:15 +02:00
There are several options that can be passed to CMake to modify how the code is built.< br >
For all of these options and parameters you have to use `-D<Parameter_name>=<value>` .< br >
2021-07-16 16:31:47 -04:00
For example, to generate build files including dependencies in a new subdirectory called 'build', run:
```sh
cmake -DBUILD_DEPS:BOOL=ON -H. -Bbuild
```
and then build with:
```sh
cd build
cmake --build .
```
Following is a list of available options, for the full list run:
2021-04-02 09:59:27 +02:00
2021-03-31 12:24:15 +02:00
```sh
cmake -S. -Bbuild -LH
```
| CMake Option | Default Value | Note |
|-|-|-|
| `BUILD_DEPS` | OFF* | Default to ON if `BUILD_JAVA=ON` or `BUILD_PYTHON=ON` or `BUILD_DOTNET=ON` |
| `BUILD_ZLIB` | OFF* | Static build the zlib library< br > **Forced** to ON if `BUILD_JAVA=ON` or `BUILD_PYTHON=ON` or `BUILD_DOTNET=ON` |
| `BUILD_absl` | OFF* | Static build the abseil-cpp libraries< br > **Forced** to ON if `BUILD_JAVA=ON` or `BUILD_PYTHON=ON` or `BUILD_DOTNET=ON` |
| `BUILD_Protobuf` | OFF* | Static build the protobuf libraries< br > **Forced** to ON if `BUILD_JAVA=ON` or `BUILD_PYTHON=ON` or `BUILD_DOTNET=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_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` |
| `BUILD_Clp` | OFF\* | Static build the Clp library< br > **Forced** to ON if `USE_COINOR=ON` **and** `BUILD_DEPS=ON` |
| `BUILD_Cgl` | OFF\* | Static build the Cgl library< br > **Forced** to ON if `USE_COINOR=ON` **and** `BUILD_DEPS=ON` |
| `BUILD_Cbc` | OFF\* | Static build the Cbc library< br > **Forced** to ON if `USE_COINOR=ON` **and** `BUILD_DEPS=ON` |
| `USE_CPLEX` | OFF | Enable CPLEX support |
| `USE_XPRESS` | OFF | Enable XPRESS support |
| | | |
| `CMAKE_BUILD_TYPE` | Release | see CMake documentation [here ](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html ) |
| `BUILD_CXX` | ON | Build C++ |
| `BUILD_PYTHON` | OFF | Build Python wrapper and package |
| `BUILD_JAVA` | OFF | Build Java wrapper and packages |
| `BUILD_DOTNET` | OFF | Build .Net wrapper and packages |
| `BUILD_FLATZINC` | ON\* | Build the flatzinc library< br > **Forced** to OFF if `BUILD_CXX=OFF` |
| `BUILD_GLOP` | OFF\* | Build the standalone Glop library< br > **Forced** to OFF if `BUILD_CXX=ON` , otherwise default to ON |
| | | |
| `BUILD_SAMPLES` | OFF\* | Build all samples< br > Default to ON if `BUILD_DEPS=ON` |
| `BUILD_CXX_SAMPLES` | ON\* | Build all C++ samples< br > **Forced** to OFF if `BUILD_CXX=OFF` or `BUILD_SAMPLE=OFF` |
| `BUILD_PYTHON_SAMPLES` | ON\* | Build all Python samples< br > **Forced** to OFF if `BUILD_PYTHON=OFF` or `BUILD_SAMPLE=OFF` |
| `BUILD_JAVA_SAMPLES` | ON\* | Build all Java samples< br > **Forced** to OFF if `BUILD_JAVA=OFF` or `BUILD_SAMPLE=OFF` |
| `BUILD_DOTNET_SAMPLES` | ON\* | Build all .Net samples< br > **Forced** to OFF if `BUILD_DOTNET=OFF` or `BUILD_SAMPLE=OFF` |
| | | |
| `BUILD_EXAMPLES` | OFF\* | Build all examples< br > Default to ON if `BUILD_DEPS=ON` |
| `BUILD_CXX_EXAMPLES` | ON\* | Build all C++ examples< br > **Forced** to OFF if `BUILD_CXX=OFF` or `BUILD_SAMPLE=OFF` |
| `BUILD_PYTHON_EXAMPLES` | ON\* | Build all Python examples< br > **Forced** to OFF if `BUILD_PYTHON=OFF` or `BUILD_SAMPLE=OFF` |
| `BUILD_JAVA_EXAMPLES` | ON\* | Build all Java examples< br > **Forced** to OFF if `BUILD_JAVA=OFF` or `BUILD_SAMPLE=OFF` |
| `BUILD_DOTNET_EXAMPLES` | ON\* | Build all .Net examples< br > **Forced** to OFF if `BUILD_DOTNET=OFF` or `BUILD_SAMPLE=OFF` |
| | | |
| `SKIP_GPG` | OFF | Disable GPG sign< br > Only available if `BUILD_JAVA=ON` |
| `UNIVERSAL_JAVA_PACKAGE` | OFF | Build a multi platform package (i.e. `ortools-java` will depends on all native packages)< br > Only available if `BUILD_JAVA=ON` |
| | | |
< a name = "integration" > < / a >
2021-04-02 09:59:27 +02:00
2021-03-31 12:24:15 +02:00
## Integrating OR-Tools in your CMake Project
2020-02-28 17:12:42 +01:00
You should be able to integrate OR-Tools in your C++ CMake project following one
of these methods.
For API/ABI compatibility reasons, if you will be using OR-Tools inside a larger
C++ project, we recommend using CMake and incorporate OR-Tools as a CMake
subproject (i.e. using `add_sudirectory()` or `FetchContent` ).
2020-03-06 16:16:52 +01:00
### Consuming OR-Tools in a CMake Project
2018-02-21 14:20:23 +01:00
2020-03-06 16:16:52 +01:00
If you already have OR-Tools installed in your system, you can use the CMake
command
2018-02-21 14:20:23 +01:00
[`find_package()` ](https://cmake.org/cmake/help/latest/command/find_package.html )
to include OR-Tools in your C++ CMake Project.
2020-03-06 16:16:52 +01:00
note: You may need to set
[`CMAKE_PREFIX_PATH` ](https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure )
2020-02-28 17:12:42 +01:00
in order for CMake to find your OR-Tools installation.
2018-02-21 14:20:23 +01:00
```cmake
2020-11-19 16:42:41 +01:00
cmake_minimum_required(VERSION 3.14)
2018-02-21 14:20:23 +01:00
project(myproj VERSION 1.0)
find_package(ortools CONFIG REQUIRED)
add_executable(myapp main.cpp)
target_link_libraries(myapp ortools::ortools)
```
Include directories, compile definitions and compile options will be added
automatically to your target as needed.
2020-03-06 16:16:52 +01:00
### Incorporating OR-Tools into a CMake Super Project
#### Using add_subdirectory
2018-02-21 14:20:23 +01:00
The recommendations below are similar to those for using CMake within the
googletest framework
(< https: // github . com / google / googletest / blob / master / googletest / README . md #incorporating -into-an-existing-cmake-project > )
Thus, you can use the CMake command
[`add_subdirectory()` ](https://cmake.org/cmake/help/latest/command/add_subdirectory.html )
to include OR-Tools directly from a subdirectory of your C++ CMake project.< br >
Note: The **ortools::ortools** target is in this case an ALIAS library target
for the **ortools** library target.
```cmake
2020-11-19 16:42:41 +01:00
cmake_minimum_required(VERSION 3.14)
2018-02-21 14:20:23 +01:00
project(myproj VERSION 1.0)
add_subdirectory(or-tools)
add_executable(myapp main.cpp)
target_link_libraries(myapp ortools::ortools)
```
Again, include directories, compile definitions and compile options will be
added automatically to your target as needed.
2020-02-28 17:12:42 +01:00
2020-03-06 16:16:52 +01:00
#### Using FetchContent
2020-03-26 18:02:07 +01:00
If you have `CMake >= 3.14.7` you can use the built-in module
2020-03-06 16:16:52 +01:00
[FetchContent ](https://cmake.org/cmake/help/latest/module/FetchContent.html )
instead. Note: The **ortools::ortools** target is in this case an ALIAS library
target for the **ortools** library target.
2020-02-28 17:12:42 +01:00
```cmake
2020-11-09 14:04:14 +01:00
cmake_minimum_required(VERSION 3.14)
2020-02-28 17:12:42 +01:00
project(myproj VERSION 1.0 LANGUAGES CXX)
include(FetchContent)
FetchContent_Declare(
or-tools
GIT_REPOSITORY https://github.com/google/or-tools.git
GIT_TAG master
)
# After the following call, the CMake targets defined by or-tools
# will be defined and available to the rest of the build
FetchContent_MakeAvailable(or-tools)
add_executable(myapp main.cpp)
target_link_libraries(myapp ortools::ortools)
```
note: You may need to use the option `-DBUILD_DEPS=ON` to get all or-tools
dependencies as well.