📜 ⬆️ ⬇️

How to make qmake always rebuild a project from scratch when changing macros

If suddenly someone does not know, then I hasten to inform you that qmake does not. This sad fact can lead to extremely unpleasant build bugs, if you forget to make a complete rebuild after changing the project's macros.

To solve this problem, I drew myself the following script, which is most conveniently placed in my own feature. I cannot explain in detail what is happening here, the volume will not be on a thick, but a book. Who cares - welcome to my blog , I wrote there everything I know about qmake.

# ,      defineReplace(checkDefinesForChanges) { old_def = $$cat($$OUT_PWD/defines.txt) curr_def = $$DEFINES curr_def -= $$old_def old_def -= $$DEFINES diff = $$old_def $$curr_def #   ,      OUT_PWD !isEmpty(diff) { A = $$system(del /F /Q /S $$system_path($${OUT_PWD}/*.*)) message(DEFINES WERE CHANGED) } write_file($$OUT_PWD/defines.txt, DEFINES); return(???) } #  QMAKE_EXTRA_COMPILERS,   # checkDefinesForChanges    _defines_check_ = ??? defines_check.name = check on defines being changed defines_check.input = _defines_check_ defines_check.CONFIG += no_link ignore_no_exist defines_check.depends = ??? defines_check.commands = ??? defines_check.output_function = checkDefinesForChanges QMAKE_EXTRA_COMPILERS += defines_check #   Makefile,    defines.txt  qmake recompile_on_defines_txt_not_existsing.target = $(MAKEFILE) recompile_on_defines_txt_not_existsing.depends = $$OUT_PWD/defines.txt recompile_on_defines_txt_not_existsing2.target = $$OUT_PWD/defines.txt recompile_on_defines_txt_not_existsing2.depends = qmake QMAKE_EXTRA_TARGETS += recompile_on_defines_txt_not_existsing recompile_on_defines_txt_not_existsing2 

The essence of what is happening: I bend over QMAKE_EXTRA_COMPILERS to call my function after processing all the features. Thus, I can get the final value of the variable DEFINES, which I use to determine the fact of changing macros. If the change was - delete all files in OUT_PWD (command for Windows, under Linux, change what you need).

As a bonus sometimes useful, in the file defines.txt you can always see the macros with which the project was compiled.

')

Source: https://habr.com/ru/post/182518/


All Articles