[CMake] Is there any way to set a build-type specific install path for multiconfig tools?

Clifford Yapp cliffyapp at gmail.com
Mon Jul 13 10:26:28 EDT 2015


One challenge we've experienced with CMake is properly controlling the
installation path when using multi-config tools like Visual Studio or
Xcode.  Since I'm in the middle of re-examining our more gnarly CMake
logic anyway, I thought I'd raise this one and see if anybody knows of
a good solution.

The problem is as follows - for multi-config build tools, the build
profile (Release, Debug, etc.) is selected at build time, not CMake
configure time.  Consequently, if one wishes to change the
CMAKE_INSTALL_PREFIX based on the current build configuration (our
convention for default install paths is to use
/parent_dirs/rel-<version> for release builds and
/parent_dirs/dev-<version> for development builds) that change has to
happen at build time.

To the best of my knowledge there is no good way to do this in CMake
currently.  The closest I could come when I tried originally was to
insert a variable into the CMAKE_INSTALL_PREFIX path that evaluated to
the current build configuration (IIRC) but that wasn't quite correct
per our convention.  I finally settled on a rather scary trick where I
created a custom build target that would manually rewrite all of the
generated CMake build files (via running a CMake script) to use the
desired path, and that build target becomes flagged for a re-run every
time the build configuration in the build tool is changed.  In
essence, I'm post processing the CMake generated build files.

The "preferred" solution to this (I think) would be to have
CMAKE_${CFG_TYPE}_INSTALL_PREFIX variables that could be set the same
way the C/CXX flag variables have per-configuration versions.  That
way the CMakeLists.txt file could simply specify the target install
paths for each configuration and have then written directly to the
appropriate output build files.  However, to the best of my knowledge
there is no existing CMake feature that currently supports this.

Has anyone else encountered the problem?  If not, would the devs
consider adding a per-config CMAKE_INSTALL_PREFIX feature for the
multi-config tools?

Thanks,
CY


More information about the CMake mailing list