Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make qmake to do a clean rebuild if DEFINES are changed

Tags:

qmake

... which it should do but does not.

This is one of the major frustration of the qmake for me. qbs is our Qt future but for now we are stuck with qmake. So, what can be done?

like image 461
Sergey Skoblikov Avatar asked Nov 03 '22 20:11

Sergey Skoblikov


1 Answers

I abuse QMAKE_EXTRA_COMPILERS to accompilsh this. I need to use it because I have to get DEFINES value after all features are processed.

# in this function all the work is done
defineReplace(checkDefinesForChanges) {
  old_def = $$cat($$OUT_PWD/defines.txt)
  curr_def = $$DEFINES
  curr_def -= $$old_def
  old_def -= $$DEFINES
  diff = $$old_def $$curr_def
  # delete all files in OUT_PWD if macros were changed
  !isEmpty(diff) {
    A = $$system(del /F /Q /S $$system_path($${OUT_PWD}/*.*))
    message(DEFINES WERE CHANGED)
  }
  write_file($$OUT_PWD/defines.txt, DEFINES);
  return(???)
}

# use QMAKE_EXTRA_COMPILERS to launch function
# checkDefinesForChanges after all features processing
_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
defines_check.clean = 333
QMAKE_EXTRA_COMPILERS += defines_check

# make sure qmake is run if deines.txt is deleted
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    

Source in Russian

like image 163
Sergey Skoblikov Avatar answered Jan 04 '23 15:01

Sergey Skoblikov