【问题标题】:QMake: execute script after buildQMake:构建后执行脚本
【发布时间】:2014-02-03 12:56:07
【问题描述】:

这用于设置 MacOSX 应用程序的应用程序包。我有一个脚本,它复制一些文件并做一些其他事情。所以我想在构建之后执行脚本(即在链接步骤之后)。我希望它每次都执行,因为无法指定它的依赖关系。

我知道有QMAKE_POST_LINK(例如描述herehere)但它仅在目标不存在时运行,即需要完成链接时。但是,我希望脚本每次都运行,即使目标已经存在。

还有QMAKE_EXTRA_TARGETSPOST_TARGETDEPS(例如描述here),但这会一直强制重新链接,但我实际上只希望脚本重新运行,它会在链接之前运行脚本。 (目前,这就是我正在使用的东西,因为我没有看到更好的方法。Here 是我的 QMake 源。)

【问题讨论】:

    标签: makefile qmake


    【解决方案1】:

    有相关问题therethere。我首先引用我的答案:

    按给定顺序制作事物的另一种方法是使用空的“super” 目标:

    super.depends = target_pre first target_post
    QMAKE_EXTRA_TARGETS += super
    

    first - 是默认的 qmake 目标,target_pretarget_post 一些自定义目标。现在make super 去做吧。

    编辑:看起来在 Qt 的最新版本中,依赖项构建是并行运行的,所以这个解决方案不起作用。

    【讨论】:

    • 我认为这里有一个好主意。使target_post 依赖于first 等,并使super 依赖于target_post 不是可行吗?
    【解决方案2】:

    在过去的几个月里,我已经为此苦苦思索了几个工作日,但我还没有找到“纯粹”的解决方案。但是,FWIW,如果您不介意每次都强制重新链接,请按以下方法操作:

    (“构建后事件”的这种实现类似于“构建前事件”的this 实现。)

    注意事项:

    • 每次强制重新链接
    • 仅适用于具有链接步骤的项目,因此,不 TEMPLATE=auxTEMPLATE=subdirs

      FORCELINK_CPP_FILE = force_link.cpp
      
      #This batch of statements causes the dummy file to be touched each build.
      forcelink.target = $$FORCELINK_CPP_FILE
      #FORCE is a nonexistent target, which will cause Make to always re-execute the recipe.
      forcelink.depends = FORCE
      forcelink.commands = touch $$FORCELINK_CPP_FILE
      QMAKE_EXTRA_TARGETS += forcelink
      
      #This statement ensures that touching the above file at Make time will force relinking.
      SOURCES += $$FORCELINK_CPP_FILE
      
      #QMake will complain unless the file actually exists at QMake time,
      # too, so we make sure it does.
      #I used to touch this on QMake build_pass runs, too,
      # but it caused transient access-denied errors.
      # I guess the release and debug makefiles are generated in parallel.
      !build_pass : write_file($$FORCELINK_CPP_FILE)
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-08
      • 2016-10-26
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多