Skip to content

Install as a Package via CMake

If you have CMake 3.21 or greater, you can use the system build preset to build the package system-wide:

1
2
3
cmake --preset=system
cmake --build --preset=system
sudo cmake --install build/system

Alternatively, if the CMAKE_PREFIX_PATH environment variable is set to $HOME/.local, then you can install it locally. This can be set in /etc/profile or your shell config. This will not affect discovery of packages installed system-wide.

1
export CMAKE_PREFIX_PATH="$HOME/.local"

This has the advantage of not requiring sudo, and matplotplusplus will be installed in $HOME/.local.

1
2
3
cmake --preset=local
cmake --build --preset=local
cmake --install build/local

You can now use it from CMake with find_package:

1
2
3
find_package(Matplot++ REQUIRED)

target_link_libraries(<your target> Matplot++::matplot)

If you're using a version of CMake too old to support presets, then building with the system preset is equivilant to:

1
2
3
4
5
6
7
8
cmake -B build/system         \
    -DMATPLOTPP_BUILD_EXAMPLES=OFF      \
    -DMATPLOTPP_BUILD_SHARED_LIBS=ON    \
    -DMATPLOTPP_BUILD_TESTS=OFF         \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON

cmake --build build/system

While building with the local preset is equivilant to:

1
2
3
4
5
6
7
8
9
cmake -B build/local                      \
    -DMATPLOTPP_BUILD_EXAMPLES=OFF                  \
    -DMATPLOTPP_BUILD_SHARED_LIBS=ON                \
    -DMATPLOTPP_BUILD_TESTS=OFF                     \
    -DCMAKE_BUILD_TYPE=Release            \
    -DCMAKE_INSTALL_PREFIX="$HOME/.local" \
    -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON

cmake --build build/local