QMake -- How to create a user variable, pass it to an included file, add 1 to the number in the included file.
-
I have a subdirs projects that has a number of nested project files.
Main.pro MY_VAR=1 MY_SPACES="" include(mod1.pri.export) message("$$MYSPACES $$MY_VAR some message") mod1.pri.export MY_VAR +=1 MY_SPACES="$$MY_SPACES " include(mod2.pri.export) message("$$MYSPACES $$MY_VAR some other message") mod2.pri.export MY_VAR += 1 MY_SPACES="$$MY_SPACES " include(mod3.pri.export) message("$$MYSPACES $$MY_VAR yet another message") This nesting works very well in keeping the library and includ paths easy to maintain. But, it is a little hard to see where messages are coming. It looks like this: Project MESSAGE: 1 some message Project MESSAGE: 1 some other message Project MESSAGE: 1 yet another message I would like it to look more like the following Project MESSAGE: 1 some message Project MESSAGE: 2 some other message Project MESSAGE: 3 yet another messageI can successfully pass the variable. But, I don't know how to increment it by 1 nor add spaces to the other.
Do you have any suggestions.
-
Your example with messages adjusted to deliberately show which is which, and the typo "MYSPACES" corrected, outputs this for me:
chrisw@newton:/tmp/tt$ qmake Project MESSAGE: 1 1 1 1 from mod3 Project MESSAGE: 1 1 1 1 from mod2 Project MESSAGE: 1 1 1 1 from mod1 Project MESSAGE: 1 1 1 1 some messageIt is a single compound PRO file not a subdirs project. The file is effectively:
MY_VAR=1 MY_SPACES="" # include(mod1.pri.export) MY_VAR +=1 MY_SPACES="$$MY_SPACES " # include(mod2.pri.export) MY_VAR +=1 MY_SPACES="$$MY_SPACES " # include(mod3.pri.export) MY_VAR += 1 MY_SPACES="$$MY_SPACES " message("$$MY_SPACES $$MY_VAR from mod3") message("$$MY_SPACES $$MY_VAR from mod2") message("$$MY_SPACES $$MY_VAR from mod1") message("$$MY_SPACES $$MY_VAR some message")There is no arithmetic ability in qmake. This:
MY_VAR +=1adds another string "1" to the list in MY_VAR. This all happens when parsing the PRO file, and the final MY_VAR value is what makes it into the variable expansions in the message() calls.
If your project was a subdirs project then $$PRO_FILE and/or $$PWD could be used in the messages to identify where they come from.
-
My goal was to create a project display so it's easy to determine where a problem occurs when updating the project files. I have several libraries and the dependencies can be nest quite a bit. I wanted output like:
Project MESSAGE Project.Pro Project MESSAGE include file 1 Project MESSAGE include file 2 Project MESSAGE include file 3 Project MESSAGE include file 3 -- done Project MESSAGE include file 2 -- done Project MESSAGE include file 1 -- done Project MESSAGE Project.pro -- doneTo accomplish that I did the following pattern
Project.pro INDENT_SPACES = "" INDENT_ADD_SPACES = " " message("$$INDENT_SPACESProject.pro") FILE_NAME = include1.pri.export !exists($$FILE_NAME) { message("$${INDENT_SPACES}File does not exist: $$FILE_NAME") error() } ! include(FILE_NAME) { message("$${INDENT_SPACES}Error importing file: $$FILE_NAME") error() } message("$$INDENT_SPACESProject.pro" -- done) include1.pri.export UNIQUE_VARIABLE = $$INDENT_SPACES INDENT_SPACES += INDENT_ADD_SPACES message("$${INDENT_SPACESinclude file 1"} # Follow the pattern described in Project.Pro to import file include2.pri.export message("$${INDENT_SPACESinclude file 1 -- done"} INDENT_SPACES = $$UNIQUE_VARIABLE include2.pri.export UNIQUE_VARIABLE2 = $$INDENT_SPACES INDENT_SPACES += INDENT_ADD_SPACES message("$${INDENT_SPACESinclude file 2"} # Follow the pattern described in Project.Pro to import file includ3.pri.export message("$${INDENT_SPACESinclude file 2 -- done"} INDENT_SPACES = $$UNIQUE_VARIABLE2 include2.pri.export UNIQUE_VARIABLE3 = $$INDENT_SPACES INDENT_SPACES += INDENT_ADD_SPACES message("$${INDENT_SPACESinclude file 3"} # Follow the pattern described in Project.Pro to import file includ3.pri.export message("$${INDENT_SPACESinclude file 3 -- done"} INDENT_SPACES = $$UNIQUE_VARIABLE3I hope it helps!