destination component - What is CMake equivalent of 'configure --prefix=DIR && make all install '?
The ":PATH" part in the accepted answer can be omitted. This syntax may be more memorable:
cmake -DCMAKE_INSTALL_PREFIX=/usr . && make all install
...as used in the answers here.
cmake . && make all install. This works, but installs to
I need to install to a different prefix (for example, to
What is the
make command line to install to
/usr instead of
The way I build CMake projects cross platform is the following:
/project-root> mkdir build /project-root> cd build /project-root/build> cmake -G "<generator>" -DCMAKE_INSTALL_PREFIX=stage .. /project-root/build> cmake --build . --target=install --config=Release
- The first two lines create the out-of-source build directory
- The third line generates the build system specifying where to put the installation result (which I always place in
./project-root/build/stage- the path is always considered relative to the current directory if it is not absolute)
- The fourth line builds the project configured in
.with the buildsystem configured in the line before. It will execute the
installtarget which also builds all necessary dependent targets if they need to be built and then copies the files into the
CMAKE_INSTALL_PREFIX(which in this case is
./project-root/build/stage. For multi-configuration builds, like in Visual Studio, you can also specify the configuration with the optional
- The good part when using the
cmake --buildcommand is that it works for all generators (i.e. makefiles and Visual Studio) without needing different commands.
Afterwards I use the installed files to create packages or include them in other projects...
It is considered bad practice to invoke the actual generator (e.g. via
make) if using CMake. It is highly recommended to do it like this:
cmake -Hfoo -B_builds/foo/debug -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEBUG_POSTFIX=d -DCMAKE_INSTALL_PREFIX=/usr
Build and Install phases
cmake --build _builds/foo/debug --config Debug --target install
When following this approach, the generator can be easily switched (e.g.
-GNinja for Ninja) without having to remember any generator-specific commands.