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

David Cole DLRdave at aol.com
Mon Jul 13 13:45:21 EDT 2015


A few more ideas:


The other "no need to modify CMake" way to achieve this (although it
may be considered "too ugly" or non-ideal by some) would be to force
the use of a single configuration per build tree, and use the proper
value for CMAKE_INSTALL_PREFIX in each build tree.

Your developers may not like that, but it would sure make the problem
at hand disappear.


The other thing to consider is that the file cmake_install.cmake,
generated at the top of your build tree contains code like the
following:

    # Set the install prefix
    if(NOT DEFINED CMAKE_INSTALL_PREFIX)
      set(CMAKE_INSTALL_PREFIX "C:/Program Files (x86)/Tutorial")
    endif()

In the end, installing your project is ultimately a call of some sort
to "cmake -P cmake_install.cmake" -- you could simply install your
project with a custom call to that script which passes in the proper
value for CMAKE_INSTALL_PREFIX using -D... The above generated code
allows you to override it by passing it in when the script is called.

The Visual Studio command for the INSTALL project looks like this:

    "C:\Program Files (x86)\CMake\bin\cmake.exe"
-DBUILD_TYPE=$(Configuration) -P cmake_install.cmake

You could easily write a custom target / custom command that is an
alternate "configuration-prefixed" install as:

    "C:\Program Files (x86)\CMake\bin\cmake.exe"
-DBUILD_TYPE=$(Configuration)
-DCMAKE_INSTALL_PREFIX=config-specific-value-here -P
cmake_install.cmake


HTH,
David C.


On Mon, Jul 13, 2015 at 12:29 PM, Clifford Yapp <cliffyapp at gmail.com> wrote:
> On Mon, Jul 13, 2015 at 12:05 PM, David Cole <DLRdave at aol.com> wrote:
>> I think this should be achievable somehow with CMAKE_INSTALL_PREFIX
>> set to "/parent_dirs" and then using appropriate DESTINATION and
>> CONFIGURATIONS arguments to the CMake install commands.
>>
>> Have you tried using the CONFIGURATIONS args to the install command?
>
> We haven't tried altering the install commands, but there's a
> difficulty there - we don't always control all the CMake code in our
> build.  We include some 3rd party libraries and try to keep their code
> as close to "vanilla" as possible, which means it would be vastly
> preferable not to need to track down and redo all the install commands
> in that code whenever we needed to re-sync.
>
> Thanks,
> CY


More information about the CMake mailing list