Multi-configurations is a bit complex to handle regarding install directories 
but it is doable.

Here is my solution:

  1.  Handle various possibilities (multi-configs or mono-config). In case of 
multi-config, you have to rely on variable CMAKE_CFG_INTDIR which be contains 
information enabling to instantiate the current configuration at runtime. I 
also force definition of a default config (Debug) if none is specified (in case 
of mono config) to avoid bad behaviours.

if (DEFINED CMAKE_CONFIGURATION_TYPES)
  # multi-config handling
  set (CMAKE_BUILD_CONFIG \${BUILD_TYPE})
  set (CMAKE_CFG_BUILD_CONFIG ${CMAKE_CFG_INTDIR})
else()
  # mono config handling
  if (CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of 
build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release 
RelWithDebInfo MinSizeRel" FORCE)
  else()
set (CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options 
are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo 
MinSizeRel" FORCE)
  endif()
  set (CMAKE_BUILD_CONFIG ${CMAKE_BUILD_TYPE})
  set (CMAKE_CFG_BUILD_CONFIG ${CMAKE_BUILD_TYPE})
endif()

2. Now you can use variables CMAKE_BUILD_CONFIG or CMAKE_CFG_BUILD_CONFIG  to 
define your install prefix. There is two different variables because depending 
of the context of use, one or the other must be used. Here is an example:
add_custom_command (OUTPUT 
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_BUILD_CONFIG}/output_file"
                    COMMAND "${CMAKE_COMMAND}" -DBUILD_TYPE=$<CONFIG> -P 
script.cmake
                    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
                    COMMENT "Generating output_file")

OUTPUT parameter does not support generator expressions so pattern $<CONFIG> 
cannot be used. You have to rely on CMAKE_CFG_INTDIR in case of multi-config 
but on CMAKE_BUILD_TYPE for mono-config. So use wrapper CMAKE_CFG_BUILD_CONFIG.

install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_CONFIG}/output_file 
DESTINATION ${CMAKE_BUILD_CONFIG})

In case of install command, CMAKE_CFG_INTDIR must not be used in multi-config… 
So use wrapper CMAKE_BUILD_CONFIG.

This is why I have two different variables!

Hope this is helpful.

Marc

From: CMake on behalf of Scott Aron Bloom
Date: Tuesday 19 May 2015 19:42
To: "cmake@cmake.org<mailto:cmake@cmake.org>"
Subject: [CMake] Setting install dir based on Debug or Release

We use the install system, and love it.

However, since our install include copies of 3rd party debug libraries that are 
named the same as the release counterparts (not our call ;() I would like to 
just have a the path be install.deb rather than “install”
We set the CMAKE_INSTLL_PREFIX variable, but all the configurations get set to 
the same install…

The problem I see, is the code only gets executed once, and at that point the 
CMAKE_BUILD_TYPE isn’t set yet..  Yes I realize this for windows, so it is a 
multi-config system.. but I cant believe Im the only one with this issue.

This is is what Im trying…

IF( "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
        SET(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/Install)
        message( STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}" )
    ELSEIF( "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
        SET(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/Install.deb)
        message( STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}" )
    ELSE()
        MESSAGE( STATUS "CMAKE_BUILD_TYPE not set yet ${CMAKE_BUILD_TYPE}" )
    ENDIF()


Any help would be most appreciated
Thanks

Scott
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to