Create a directory based on Release/Debug build type in CMake

百般思念 提交于 2019-12-18 18:03:06

问题


I am working on post build, INSTALL command. After I build my project, I build INSTALL project,which copies directories to User Specified location. I have that working fine using

install(TARGETS EXECTUABLE RUNTIME DESTINATION CMAKE_INSTALL_PREFIX/USERSPECIFIEDLOCATION).

I would like to change this to
install(TARGETS EXECTUABLE RUNTIME DESTINATION CMAKE_INSTALL_PREFIX/DEBUG or RELEASE).

So, if I build using debug in VS2012, it should copy executable to CMAKE_INSTALL_PREFIX/DEBUG instead of CMAKE_INSTALL_PREFIX/USERSPECIFIEDLOCATION.

Thanks in advance.


回答1:


You'll find an answer to your question if you look closer to documentation:

The CONFIGURATIONS argument specifies a list of build configurations
for which the install rule applies (Debug, Release, etc.).

Example:

add_executable(boo boo.cpp)

install(
    TARGETS
    boo
    CONFIGURATIONS
    Debug
    DESTINATION
    bin/Debug
)

install(
    TARGETS
    boo
    CONFIGURATIONS
    Release
    DESTINATION
    bin/Release
)

DEBUG_POSTFIX

But I think that all you need is CONFIG_POSTFIX target property:

add_executable(bar bar.cpp)
add_library(baz baz.cpp)

set_target_properties(bar baz PROPERTIES DEBUG_POSTFIX d)

install(TARGETS bar DESTINATION bin)
install(TARGETS baz DESTINATION lib)

Building install target with Release configuration produce: bar.exe and baz.lib. Building install target with Debug configuration produce: bard.exe and bazd.lib.

Note

Note that for libraries you can use CMAKE_DEBUG_POSTFIX (I don't know why, but CMAKE_DEBUG_POSTFIX not applyed to executables):

set(CMAKE_DEBUG_POSTFIX d)

add_library(baz baz.cpp)
install(TARGETS baz DESTINATION lib)

Related

target_link_libraries. See debug and optimized.



来源:https://stackoverflow.com/questions/20767436/create-a-directory-based-on-release-debug-build-type-in-cmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!