4

Currently, I have a file which contains some version tagging information which is used by the .pro file and parsed by qmake, but the problem is that when that file changes qmake is not re-run.

Is it possible to add something to the .pro file so that qmake will treat this file as a dependency for the Makefile?

Dave Johansen
  • 889
  • 1
  • 7
  • 23
  • There are certainly ways to make qmake rerun if you edit an arbitrary file, but if the file that you're editing isn't an actual source code file (referenced by the HEADERS and SOURCES variables) then it won't cause anything to recompile. – Chris Dec 08 '11 at 17:31
  • Yes, that is my question. If there's a way in the .pro file to tell qmake that a non-source file (not a header or source file) is a dependency of the generate Makefile. – Dave Johansen Dec 08 '11 at 23:50
  • Yes but what good is regenerating your makefile if it doesn't do anything? – Chris Dec 09 '11 at 02:45
  • 1
    Sorry, maybe I didn't describe this clearly enough. There are source and header files, but one of the commands in the .pro file makes a call to a script that parses a text file to extract version number information which it then create #defines used in the source to "know" that version information. When that text file changes the Makefile needs to be regenerated so the source file will have the proper #define values. I'm looking for a way to tell qmake that that needs to happen. – Dave Johansen Dec 09 '11 at 17:27
  • I think I understand. But I also think this approach still isn't going to work for you. The problem you're going to have with the described approach is that your project is going to get built, and then when you update the version in your script the Makefile could get regenerated, but the Make system will not cause any of your source files to be recompiled unless you modify the actual files that are using your #defines. Just changing the flags used to create the #defines in the Makefile is not sufficient to cause any source code to be recompiled in and of itself. – Chris Dec 10 '11 at 00:01
  • That is true. I would also need to add the file as a dependency to the source file that uses the #define generated by the .pro file. But I think the question as to whether there is a way to manually specify a dependency still stands. – Dave Johansen Dec 12 '11 at 20:19

1 Answers1

1

Sometheing like this should work:

depend_on_file.target = depend_on_file
depend_on_file.depends = path_to_your_txt_file
depend_on_file.CONFIG += recursive
QMAKE_EXTRA_TARGETS += depend_on_file
PRE_TARGETDEPS += depend_on_file

Rebuild will be triggered if file path_to_your_txt_file changes but keep in mind that if your qmake script that parses the file changes DEFINES variable then you out of luck. Defines are not listed in dependencies, you see. If defines are changed you have to do full rebuild by hand.

Sergey Skoblikov
  • 5,811
  • 6
  • 40
  • 49
  • 1
    Thanks for the solution. I ended up just making an additional target along the lines of [this](http://stackoverflow.com/questions/3776476/how-to-add-custom-targets-in-a-qmake-generated-makefile) that was run all the time and then having it update a .h file when a change was necessary. This would cause the normal dependency stuff to kick in and rebuild the files that depended on the values when they changed. – Dave Johansen Feb 25 '13 at 03:50