使用qmake将dll安装到2个目标(路径)中

时间:2016-04-11 14:40:00

标签: c++ qt dll install qmake

有以下qt专业档案:

public static int GetAge( DateTime dob, DateTime today, out int days, out int months ) {
        DateTime dt = today;
        if( dt.Day < dob.Day ) {
            dt = dt.AddMonths( -1 );
        }

        months = dt.Month - dob.Month;
        if( months < 0 ) {
            dt = dt.AddYears( -1 );
            months += 12;
        }

        int years = dt.Year - dob.Year;
        var offs = dob.AddMonths( years * 12 + months );
        days = (int)( ( today.Ticks - offs.Ticks ) / TimeSpan.TicksPerDay );
        return years;
    }

结果dll文件被复制到2个路径(目标)。现在由于某种原因它不起作用:qmake不为第二个目标生成安装(复制)脚本(设置了QTCREATOR_BIN_PATH)。如何正确编写第二次安装,以便将dll安装到2个目的地?

完整项目:https://github.com/akontsevich/WidgetBox

2 个答案:

答案 0 :(得分:1)

  

如何正确编写项目目标的副本,以便安装dll   进入2个目的地?

您可以尝试使用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

另一种也许更简单的方法是始终尝试复制后期构建,但使用xcopy / D / Y命令语法,如果目标存在,我们可以避免复制:

QMAKE_POST_LINK += xcopy /d/y $$qtLibraryTarget(WidgetBoxPlugin) ${QTCREATOR_BIN_PATH}/plugins/designer

此命令的问题是正确地转义输入,但它在SO上更广为人知:https://stackoverflow.com/search?q=QMAKE_POST_LINK

答案 1 :(得分:0)

这里有建议: 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

只有奇怪的原因[]括号仅适用于target和()是creator_target必需的吗?