Collectives™ on Stack Overflow
  
  
   Find centralized, trusted content and collaborate around the technologies you use most.
  
  Learn more about Collectives
  
   
    Teams
   
  
  
   Q&A for work
  
  
   Connect and share knowledge within a single location that is structured and easy to search.
  
  Learn more about Teams
  
   I have to deal with CMake 3.x, Qt Creator 3.3.0, Qt 4.8.6, Visual Studio 2008 in Windows (and rarely Qt Creator + GCC in Debian).
  
  
   This instruction
  
  
   install(TARGETS ${PROJECT} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
  
  
   is not comfortable because of mixing debug and release
   
    *.lib
   
   files in the same directory. I'd like to save
   
    libs
   
   in the corresponding subfolder.
  
  
   I've tried the following instruction from
   
    here
   
   :
  
  
   install(TARGETS ${PROJECT} DESTINATION
  ${CMAKE_INSTALL_PREFIX}/lib/\${BUILD_TYPE})
  
  
   It works fine for Visual Studio, as it is a multi-configuration solution and we pass
   
    ${BUILD_TYPE}
   
   , protected by backslash
   
    '\'
   
   for further propagation.
But how can I achieve the same output for
   
    Qt Creator + MS C++ compiler
   
   ? Should I assign
   
    Debug
   
   (for example) to
   
    ${CMAKE_BUILD_TYPE}
   
   (via command-line interface) and special custom flag, which tells CMake that we deal with nmake/make? I mean conditional install instruction which will work fine in Windows and Linux and require minimal differences in the command-line arguments for
   
    CMake
   
   . I don't want to reinvent the wheel if there is a standard solution.
  
  
   You saw that you can use
   
    BUILD_TYPE
   
   variable
   
    set at compile time
   
   to configure the target folder of your library at installation. This is specific to Visual Studio.
  
  
   In other build systems (make, nmake, ninja, etc.) you have to use
   
    CMAKE_BUILD_TYPE
   
   variable,
   
    set at configuration time
   
   to retrieve the same information. In such case, as you felt, different configurations (Debug and Release) have to be generated in separated build folders. In these folders, CMake generation step is done with the right value in
   
    CMAKE_BUILD_TYPE
   
   variable. Example:
  
  cd /home/user/project/xx_project/build_release
cmake -DCMAKE_BUILD_TYPE=Release /home/user/project/xx_project/src
cd /home/user/project/xx_project/build_debug
cmake -DCMAKE_BUILD_TYPE=Debug /home/user/project/xx_project/src
To detect if the user is building from Visual Studio or from command line, "there is a variable for that": The MSVC_IDE Cmake variable
A solution can be something like
if(MSVC_IDE)
  install(TARGETS ${PROJECT} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/\${BUILD_TYPE})
else()
  install(TARGETS ${PROJECT} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_BUILD_TYPE})
endif()
I am not completely sure of the necessity of the backslash before ${CMAKE_BUILD_TYPE}. You should test that by yourself
        Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
 
But avoid …
- Asking for help, clarification, or responding to other answers.
 - Making statements based on opinion; back them up with references or personal experience.
 
To learn more, see our tips on writing great answers.