QMake: execute script after build

后端 未结 2 1250
心在旅途
心在旅途 2021-01-19 15:29

This is for setting up the application bundle of a MacOSX app. I have a script which copies a few files and does some other things. So I want to execute the script after the

相关标签:
2条回答
  • 2021-01-19 15:58

    I've scratched my head about this for a few man-days over the past several months, and I haven't yet found a "pure" solution. However, FWIW, if you don't mind the hack of forcing relink every time, here's how to do that:

    (This implementation of "post-build-events" is similar to this implementation of "pre-build-events".)

    Caveats:

    • Forces relink every time
    • Works only for projects that have a linking step, so, not TEMPLATE=aux or TEMPLATE=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)
      
    0 讨论(0)
  • 2021-01-19 16:03

    There is related questions there and there. I quote my answer for first of them:

    Another way to make things in given order is to use empty "super" target:

    super.depends = target_pre first target_post
    QMAKE_EXTRA_TARGETS += super
    

    Where first - is default qmake target, and target_pre and target_post some custom targets. Now make super just do the thing.

    EDIT: looks like in last versions of Qt build of dependencies is running in paralell so this solution wouldn't work.

    0 讨论(0)
提交回复
热议问题