AI-generated Key Takeaways
-
This guide provides instructions for building OR-Tools from source with Java support on MacOS, specifically tested on MacOS 13.0.1 Ventura with Intel and M1 processors.
-
Before building, ensure you have Xcode Command Line Tools, Homebrew, C++ tools (cmake, wget, pkg-config), SWIG, Java JDK 8.0 or higher, and Maven installed.
-
Download the stable or main branch of the OR-Tools source code from GitHub, configure the build with CMake, and then build the source code using the provided commands.
-
After building, test the installation by running examples and, if needed, install OR-Tools on your operating system using the install target with CMake.
-
For re-installation, remove the build directory and re-configure and build OR-Tools using the initial commands.
Introduction
This guide explains how to build from source OR-Tools, with support for Java, on MacOS.
Unless you plan to modify the source code or use a third-party solver with OR-Tools, we recommend the package installation.
Although these instructions might also work on other MacOS variants, we have only tested them on machines meeting the following requirements:
- MacOS 13.0.1 (Ventura) Intel 64-bit (x86_64)
- MacOS 13.0.1 (Ventura) M1 (arm64)
Prerequisites
The following sections describe the prerequisites for installing OR-Tools.
Xcode Command Line Tools
You must install the Xcode Command Line Tools. To do so, open the
Terminal, found in /Applications/Utilities/, and enter:
xcode-select --installClick “Install” to download and install Xcode Command Line Tools. You don’t need to "Get Xcode" from the App Store. If you have a slow Internet connection, it may take many minutes.
Verify that you’ve successfully installed Xcode Command Line Tools:
xcode-select -pYou should see:
/Library/Developer/CommandLineTools
Homebrew
To install the remaining prerequisites, we recommend first installing the "missing package manager for macOS" otherwise known as Homebrew. To do so, open a terminal window and enter:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"brew update
To verify that you’ve successfully installed brew:
brew --versionYou should see:
Homebrew 1.6.9-8-g25542d7
Homebrew/homebrew-core (git revision 0e0c84; last commit 2018-06-20)
C++ tools
To install C++ tools, open a terminal window and enter:
brew install cmake wget pkg-configSWIG tool
To install SWIG tool, open a terminal window and enter:
brew install swigJava JDK
You must install the Java JDK 8.0 or higher.
Once you have installed Homebrew, you can install openjdk by opening a terminal window and enter:
brew install openjdksudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Then you need to export the JAVA_HOME variable:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk.jdkMaven
You must install Maven.
Once you have installed Homebrew, you can install maven by opening a terminal window and enter:
brew install mavenYou can test Maven is correctly installed and can find java using the following command:
mvn -vDownload the source code
There are two distinct branches of the OR-Tools source code on
GitHub: stable and main.
The stable branch has been thoroughly tested and should work flawlessly on all
supported platforms.
The main branch is where the latest updates and
improvements have been applied; it's more current, but less stable.
Download the stable source code
You can get the stable source code for OR-Tools in either of the following ways:
Clone the
stablebranch by entering:git clone https://github.com/google/or-toolsDownload the latest release in a compressed file, by clicking the
Clone or downloadbutton in GitHub.
Download the main source code
To retrieve the source code from the main branch, enter:
git clone -b main https://github.com/google/or-toolsDownload previous releases
You can get the source code for previous releases in either of the following ways:
- Download a previous release from the GitHub release page.
Assuming you have already created a local repository (by
git clone), you can check out a specific release using a Git tag. For example, to work with the v9.12 release instead of themainbranch, enter the following commands in your local repo:git fetch --all --tags --prunegit checkout tags/v9.12 -b v9.12
Configure the build
Before building OR-Tools, you'll need to configure the CMake build system generator.
Open a terminal and navigate to the directory where you extracted the files. Then enter:
cmake -S . -B build -DBUILD_DEPS=ON -DBUILD_JAVA=ONCheckout the CMake documentation for details.
Using SCIP
Since v7.8, SCIP is now integrated so you won't have to install it manually.
Using Gurobi
Gurobi is now pre-integrated. When needed, at runtime, OR-Tools will search for
the Gurobi shared library in the default install path of the Gurobi installers
on MAC OS X and Windows, or by using the GUROBI_HOME environment variable.
Using an optional third-party MIP solver
You can also use OR-Tools with any of the following optional third-party MIP solvers whose support is disabled by default:
- CPLEX
- GLPK (Linux and MacOS only)
- XPRESS Solver
Please take a look at this documentation for details.
Build the source code
To build the source code, open a terminal and navigate to the directory where you extracted the files. Then enter the following command to compile OR-Tools:
cmake --build build --config Release --target ALL_BUILD -j -vCheckout the CMake documentation for details.
Test the source code
You can check that everything is running correctly by entering:
cmake --build build --config Release --target RUN_TESTS -vThis runs examples for OR-Tools. If all the examples run successfully, you are ready to get started with OR-Tools.
Cleaning the build files
If you need to re-install OR-Tools, the command:
rm -r buildwill remove all compiled dependencies. This can be useful for resetting to a clean state.
Then re-enter the commands:
cmake -S . -B build -DBUILD_DEPS=ON -DBUILD_JAVA=ON
cmake --build build --config Release --target ALL_BUILD -j -vInstalling OR-Tools on your operating system
You can install OR-Tools for Java on your operating system by entering:
cmake --build build --config Release --target install -v