【发布时间】:2021-11-13 17:33:11
【问题描述】:
CMake 新手,我很难理解如何使用生成器表达式。我正在尝试使用add_custom_command 创建一个构建后命令以将 Qt DLL 复制到可执行目录。
在Qt5WidgetsConfig.cmake 中,我可以看到它为 Qt5::Widgets 目标创建了不同的属性来引用 DLL,具体取决于当前活动的配置。 IMPORTED_LOCATION_DEBUG 或 IMPORTED_LOCATION_RELEASE。我希望能够使用$<CONFIG:Debug> 生成器表达式作为if() 中的条件,但这不起作用。
我的 CMakeLists.txt:
# minimum version required for proper support of C++11 features in Qt
cmake_minimum_required(VERSION 3.1.0)
set(CMAKE_CONFIGURATION_TYPES Debug;Release)
# project name and version
project(TPBMon VERSION 0.0.0.1)
# Qt5 libs
find_package(Qt5Widgets REQUIRED)
# run Qt's MOC when needed
set(CMAKE_AUTOMOC ON)
add_executable(
tpbmon
src/main.cpp
src/mainwindow.hpp
src/mainwindow.cpp
)
target_link_libraries(tpbmon Qt5::Widgets)
set_target_properties(
tpbmon
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin
)
if(WIN32)
if($<CONFIG:Debug>)
get_target_property(WIDGETDLL Qt5::Widgets IMPORTED_LOCATION_DEBUG)
else($<CONFIG:Debug>)
get_target_property(WIDGETDLL Qt5::Widgets IMPORTED_LOCATION_RELEASE)
endif($<CONFIG:Debug>)
add_custom_command(
TARGET tpbmon POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${WIDGETDLL} $<TARGET_FILE_DIR:tpbmon>
)
endif(WIN32)
【问题讨论】: