With the cmake generator "Ninja Multi-Config" what is the proper way to handle CMAKE_INSTALL_PREFIX
. For instance, if you do:
$ cmake -DCMAKE_INSTALL_PREFIX=../install -G "Ninja Multi-Config" ..
$ cmake --build . --config Release --target install
And then afterwards do
$ cmake --build . --config Debug --target install
will the files in ../install
be overwritten by the Debug
install? What is the normal way to handle the install location in such cases?
By default they will be overwritten- Ie. with multi-config, the configurations' files install to the same locations.
Command-line "manual" approach
If you don't mind having to do this kind of thing manually on the command-line each time you install, you can just use the
--prefix
parameter forcmake --install <...>
.From the docs for
CMAKE_INSTALL_PREFIX
:In that sense,
CMAKE_INSTALL_PREFIX
can be seen as a default value set per-generated buildsystem that can be overridden on the commandline.So you can do something like
cmake --install <build_dir> --config <config> --prefix <install_dir_unique_to_config>
.defaults in CMakeLists.txt approach
See this CMake mailing thread for various workarounds. Summarized here:
You can (with some exceptions- see the docs) use the
<CONFIG>_POSTFIX
target property to append a postfix to an output name of a target.Workaround using
install(DESTINATION)
parameters:If you're using CMake Presets
You can use the
installDir
property of your configuration presets and the${presetName}
variable.Note also that CMake 3.29 adds an environment variable option to set
CMAKE_INSTALL_PREFIX
.