使用 qmake 将 dll 安装到 2 个目标(路径)中
Install dll into 2 targets (paths) with qmake
有以下qt pro文件:
CONFIG += plugin debug_and_release
TARGET = $$qtLibraryTarget(WidgetBoxPlugin)
TEMPLATE = lib
...
target.path = $$[QT_INSTALL_PLUGINS]/designer
creator_target.path = $$[QTCREATOR_BIN_PATH]/plugins/designer
INSTALLS += target creator_target
结果 dll 文件被复制到 2 个路径(目标)中。现在由于某些原因它不起作用:qmake 不会为第二个目标生成安装(复制)脚本(QTCREATOR_BIN_PATH 已设置)。如何正确编写第二次安装以便将 dll 安装到 2 个目的地?
How to write a copy of my project target correctly so dll being installed
into 2 destinations?
您可以尝试使用QMAKE_EXTRA_COMPILERS
创建一个新的目标路径:
http://blog.qt.io/blog/2008/04/16/the-power-of-qmake/
creator_target.name = Copying the target dll to Qt Creator plugins directory as well
creator_target.input = $$qtLibraryTarget(WidgetBoxPlugin)
creator_target.path = $$[QTCREATOR_BIN_PATH]/plugins/designer
creator_target.CONFIG += target_predeps no_link
creator_target.output = WidgetBoxPlugin.dll
QMAKE_EXTRA_COMPILERS += creator_target
INSTALLS += creator_target
另一种可能更简单的方法是始终尝试复制 post 构建,但使用 xcopy /D/Y 命令语法,如果目标存在,我们可以避免复制:
QMAKE_POST_LINK += xcopy /d/y $$qtLibraryTarget(WidgetBoxPlugin) ${QTCREATOR_BIN_PATH}/plugins/designer
此命令的问题是正确转义输入,但在 SO 上更广为人知:https://whosebug.com/search?q=QMAKE_POST_LINK
这里有建议:
https://forum.qt.io/topic/66090/qmake-does-not-generate-2nd-install-target-in-makefile/3#
根据文档 (https://wiki.qt.io/QMake-top-level-srcdir-and-builddir) 正确的构建目录宏是 $$OUT_PWD,因此正确的安装代码是:
target.path = $$[QT_INSTALL_PLUGINS]/designer
creator_target.name = Copying the target dll to Qt Creator plugins directory as well
creator_target.input = $qtLbraryTarget(WidgetBoxPlugin)
creator_target.path = $$(QTCREATOR_BIN_PATH)/plugins/designer
creator_target.CONFIG += no_check_exist
creator_target.output = WidgetBoxPlugin.dll
creator_target.files = $$OUT_PWD/release/WidgetBoxPlugin.dll
QMAKE_EXTRA_COMPILERS += creator_target
INSTALLS += target creator_target
唯一奇怪的是为什么 [] 括号只适用于目标而 () 对 creator_target 是必需的?
有以下qt pro文件:
CONFIG += plugin debug_and_release
TARGET = $$qtLibraryTarget(WidgetBoxPlugin)
TEMPLATE = lib
...
target.path = $$[QT_INSTALL_PLUGINS]/designer
creator_target.path = $$[QTCREATOR_BIN_PATH]/plugins/designer
INSTALLS += target creator_target
结果 dll 文件被复制到 2 个路径(目标)中。现在由于某些原因它不起作用:qmake 不会为第二个目标生成安装(复制)脚本(QTCREATOR_BIN_PATH 已设置)。如何正确编写第二次安装以便将 dll 安装到 2 个目的地?
How to write a copy of my project target correctly so dll being installed into 2 destinations?
您可以尝试使用QMAKE_EXTRA_COMPILERS
创建一个新的目标路径:
http://blog.qt.io/blog/2008/04/16/the-power-of-qmake/
creator_target.name = Copying the target dll to Qt Creator plugins directory as well
creator_target.input = $$qtLibraryTarget(WidgetBoxPlugin)
creator_target.path = $$[QTCREATOR_BIN_PATH]/plugins/designer
creator_target.CONFIG += target_predeps no_link
creator_target.output = WidgetBoxPlugin.dll
QMAKE_EXTRA_COMPILERS += creator_target
INSTALLS += creator_target
另一种可能更简单的方法是始终尝试复制 post 构建,但使用 xcopy /D/Y 命令语法,如果目标存在,我们可以避免复制:
QMAKE_POST_LINK += xcopy /d/y $$qtLibraryTarget(WidgetBoxPlugin) ${QTCREATOR_BIN_PATH}/plugins/designer
此命令的问题是正确转义输入,但在 SO 上更广为人知:https://whosebug.com/search?q=QMAKE_POST_LINK
这里有建议: https://forum.qt.io/topic/66090/qmake-does-not-generate-2nd-install-target-in-makefile/3#
根据文档 (https://wiki.qt.io/QMake-top-level-srcdir-and-builddir) 正确的构建目录宏是 $$OUT_PWD,因此正确的安装代码是:
target.path = $$[QT_INSTALL_PLUGINS]/designer
creator_target.name = Copying the target dll to Qt Creator plugins directory as well
creator_target.input = $qtLbraryTarget(WidgetBoxPlugin)
creator_target.path = $$(QTCREATOR_BIN_PATH)/plugins/designer
creator_target.CONFIG += no_check_exist
creator_target.output = WidgetBoxPlugin.dll
creator_target.files = $$OUT_PWD/release/WidgetBoxPlugin.dll
QMAKE_EXTRA_COMPILERS += creator_target
INSTALLS += target creator_target
唯一奇怪的是为什么 [] 括号只适用于目标而 () 对 creator_target 是必需的?