[英]CMake qt input library postfix for custom debug build
I'm stuck with writing a cmake file for multiconfiguration IDE (Visual Studio).我一直在为多配置 IDE (Visual Studio) 编写一个 cmake 文件。 My goal is to add a custom configuration and tell Visual Studio that I want to use debug libs of Qt (qtcored.lib) as it is done when I pick Debug configuration.
我的目标是添加自定义配置并告诉 Visual Studio 我想使用 Qt (qtcored.lib) 的调试库,因为它在我选择调试配置时完成。 With code below, I have release libraries in a linker input when I pick CustomDebug configuration
使用下面的代码,当我选择 CustomDebug 配置时,我在链接器输入中有发布库
Does anyone know how to achieve that?有谁知道如何实现这一目标?
Thanks谢谢
cmake_minimum_required(VERSION 3.12.0)
project(custom-conf)
find_package(Qt5Core CONFIG REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(SRC main.cpp)
set(QT_LIBS Qt5::Core)
add_executable(custom-conf WIN32 ${SRC})
target_link_libraries(custom-conf ${QT_LIBS})
#
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(isMultiConfig)
set(CMAKE_CONFIGURATION_TYPES "CustomDebug;Debug;Release" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_CUSTOMDEBUG "/debug")
endif()
I want to use debug libs of Qt (qtcored.lib) as it is done when I pick Debug configuration.
我想使用 Qt (qtcored.lib) 的调试库,因为它是在我选择调试配置时完成的。
With the IMPORTED target this can be easiliy achieved by using MAP_IMPORTED_CONFIG<CONFIG> target property :对于 IMPORTED 目标,这可以通过使用MAP_IMPORTED_CONFIG<CONFIG>目标属性轻松实现:
# For CustomDebug configuration of the main project
# use Debug configuration of the IMPORTED target
set_target_properties(Qt5::Core PROPERTIES
MAP_IMPORTED_CONFIG_CUSTOMDEBUG DEBUG)
With setting CMAKE_MAP_IMPORTED_CONFIG<CONFIG> variable you may automatically set the property for all IMPORTED targets:通过设置CMAKE_MAP_IMPORTED_CONFIG<CONFIG>变量,您可以自动为所有 IMPORTED 目标设置属性:
set(CMAKE_MAP_IMPORTED_CONFIG_CUSTOMDEBUG DEBUG)
#...
# This call will create IMPORTED target Qt5::Core which
# MAP_IMPORTED_CONFIG_CUSTOMDEBUG property is already set.
find_package(Qt5Core CONFIG REQUIRED)
(The variable assignment should come before any call like find_package
which creates IMPORTED target.) (变量赋值应该在任何像
find_package
这样创建find_package
目标的调用之前。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.