Files
ortools-clone/cmake/docs/cpp.md

83 lines
2.3 KiB
Markdown
Raw Normal View History

2022-03-24 17:19:17 +01:00
Linux | macOS | Windows
------------------------------------------ | ------------------------------------------ | -------
[![Status][linux_cpp_svg]][linux_cpp_link] | [![Status][macos_cpp_svg]][macos_cpp_link] | [![Status][windows_cpp_svg]][windows_cpp_link]
2020-03-04 17:42:26 +01:00
[linux_cpp_svg]: https://github.com/google/or-tools/actions/workflows/cmake_linux_cpp.yml/badge.svg?branch=main
2021-10-27 17:42:45 +02:00
[linux_cpp_link]: https://github.com/google/or-tools/actions/workflows/cmake_linux_cpp.yml
[macos_cpp_svg]: https://github.com/google/or-tools/actions/workflows/cmake_macos_cpp.yml/badge.svg?branch=main
2021-10-27 17:42:45 +02:00
[macos_cpp_link]: https://github.com/google/or-tools/actions/workflows/cmake_macos_cpp.yml
[windows_cpp_svg]: https://github.com/google/or-tools/actions/workflows/cmake_windows_cpp.yml/badge.svg?branch=main
2021-10-27 17:42:45 +02:00
[windows_cpp_link]: https://github.com/google/or-tools/actions/workflows/cmake_windows_cpp.yml
2020-03-04 17:42:26 +01:00
# Introduction
2022-03-24 17:19:17 +01:00
For building OR-Tools as a CMake standalone project, you can read the following
instructions.
2020-03-04 17:42:26 +01:00
This project should run on GNU/Linux, MacOS and Windows.
2022-03-24 17:19:17 +01:00
## C++ Project Build
2020-03-04 17:42:26 +01:00
1. Get the source code and change to it.
2022-03-24 17:19:17 +01:00
```sh
git clone https://github.com/google/or-tools.git
cd or-tools
```
2020-03-04 17:42:26 +01:00
2. Run CMake to configure the build tree.
2022-03-24 17:19:17 +01:00
```sh
cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -DBUILD_DEPS=ON
```
note: To get the list of available generators (e.g. Visual Studio), use `-G`
2020-03-04 17:42:26 +01:00
3. Afterwards, generated files can be used to compile the project.
2022-03-24 17:19:17 +01:00
```sh
cmake --build build --config Release -v
```
2020-03-04 17:42:26 +01:00
4. Test the build software (optional).
2022-03-24 17:19:17 +01:00
```sh
cmake --build build --target test
```
2020-03-04 17:42:26 +01:00
5. Install the built files (optional).
2022-03-24 17:19:17 +01:00
```sh
cmake --build build --target install
```
## Testing
2020-09-19 17:21:22 +02:00
To list tests:
2022-03-24 17:19:17 +01:00
2020-09-19 17:21:22 +02:00
```sh
cd build
ctest -N
```
2022-03-24 17:19:17 +01:00
To only run C++ tests:
2020-09-19 17:21:22 +02:00
```sh
cd build
ctest -R "cxx_.*"
```
2022-03-24 17:19:17 +01:00
## Technical Notes
### Managing RPATH
Since we want to use the
[CMAKE_BINARY_DIR](https://cmake.org/cmake/help/latest/variable/CMAKE_BINARY_DIR.html)
to generate the wrapper package (e.g. python wheel package) as well as be able
to test from the build directory. \
2020-03-04 17:42:26 +01:00
We need to enable:
2022-03-24 17:19:17 +01:00
2020-03-04 17:42:26 +01:00
```cmake
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
```
And have a finely tailored rpath for each library.