4

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 build (i.e. after the linking step). I want it to be executed just every time because it is not possible to specify its dependencies.

I know there is QMAKE_POST_LINK (e.g. described here or here) but it runs only when the target does not exists, i.e. when linking needs to be done. However, I want the script to run every time, also when the target already exists.

There is also QMAKE_EXTRA_TARGETS and POST_TARGETDEPS (e.g. described here) but that forces a relink all the time but I actually only want the script to rerun and it runs the script before the linking. (Currently, that's what I'm using using anyway, because I don't see a better way. Here is my QMake source.)

Community
  • 1
  • 1
Albert
  • 65,406
  • 61
  • 242
  • 386

2 Answers2

1

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.

ephemerr
  • 1,833
  • 19
  • 22
  • 1
    I think there's a good idea here. Wouldn't it work to make `target_post` depend on `first`, etc, and make `super` depend on `target_post`? – Keith Russell Apr 22 '20 at 19:52
0

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)
    
Keith Russell
  • 560
  • 4
  • 12