What’s the best general practice for creating installation where Release and Debug binaries can coexist?
Simplest way would be to have them in separate folders,
but that requires changing path prefix/roots when you want to switch between Debug and Release builds.
Another option is to install both builds into the same folder - which works when debug binaries
have either d or _d suffixes, but that is not always the case.
There’s a vcpkg-way - vcpkg installs Relase and Debug to separate folders - e.g. install and install/debugand then is moving cmake configs from debug/lib/cmake/pkg (or whatever name package has) to debug/lib/cmake/pkg and patches them to make sure they work correcrly from the new location (script for reference). But that requires vcpkg environment and package to be vcpkg port.
Inspired by vcpkg approach - I came up with another one (example powershell script is below):
- installing Release build to
install - installing Debug to
install/debug, but installing debug binaries todebug/debug - move cmake files from
install/debug/lib/cmake/pkgtoinstall/lib/cmake/pkg- there’s no need to patch them, since we prefixed our debug binaries with anotherdebugfolder. - move all files from
debug/debugtodebug
So now in install/lib/cmake/pkg we have pkgTargets-debug.cmake and mypkgTargets-release.cmake pointing to existing binaries, so should be all good.
Any idea if there are caveats to this approach or it should indeed work for the most cases?
$INSTALLATION_PATH="L:/install"
$CMAKE_CONFIG_LOCATION="lib/cmake/mypkg"
cmake .. -G Ninja `
-DCMAKE_INSTALL_PREFIX="$INSTALLATION_PATH" `
-DCMAKE_BUILD_TYPE=Release
cmake --build . --target install
cmake .. -G Ninja `
-DCMAKE_INSTALL_PREFIX="$INSTALLATION_PATH/debug" `
-DCMAKE_BUILD_TYPE=Debug `
-DCMAKE_INSTALL_LIBDIR="debug/lib" `
-DCMAKE_INSTALL_BINDIR="debug/bin"
cmake --build . --target install
cp -Verbose -Recurse "$INSTALLATION_PATH/debug/$CMAKE_CONFIG_LOCATION/*" "$INSTALLATION_PATH/$CMAKE_CONFIG_LOCATION"
rm -Verbose -Recurse "$INSTALLATION_PATH/debug/$CMAKE_CONFIG_LOCATION"
rm -Verbose -Recurse "$INSTALLATION_PATH/debug/lib"
rm -Verbose -Recurse "$INSTALLATION_PATH/debug/include"
cp -Verbose -Recurse "$INSTALLATION_PATH/debug/debug/*" "$INSTALLATION_PATH/debug"
rm -Verbose -Recurse "$INSTALLATION_PATH/debug/debug"