I do cmake . && make all install
. This works, but installs to /usr/local
.
I need to install to a different prefix (for example, to /usr
).
What is the cmake
and make
command line to install to /usr
instead of /usr/local
?
As of CMake 3.15 you can run the --install
version of CMake after building:
$ cmake --install /path/to/build --prefix /path/to/install [--config <CONFIG>]
Include --config
if you're using a multi-config generator like Visual Studio.
In prior versions, you could execute the cmake_install.cmake
script:
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX=/path/to/install -P cmake_install.cmake
Finally, you can specify the install prefix at configure-time, and then build and install in one step as follows:
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/path/to/install /path/to/src
$ cmake --build . --target install
You would either add --config Release
to the third command or -DCMAKE_BUILD_TYPE=Release
to the second command, depending on whether you were using a multi-config generator or a single-config generator, respectively.
The type (PATH) is not strictly necessary, but causes the Qt based cmake-gui to present the directory chooser dialog.