<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Passing QMake variable to a script]]></title><description><![CDATA[<p dir="auto">Hello everyone,</p>
<p dir="auto">I have a python script that helps me manage versioning, I pass it some QMake variables from QMake.</p>
<p dir="auto">For example:</p>
<pre><code class="language-qMake">CONFIG(debug, debug|release) {
    CURRENT_BUILD = DEBUG
} else {
    CURRENT_BUILD = RELEASE
}
message(CURRENT_BUILD = $${CURRENT_BUILD})
PYTHON_SCRIPT_SUCCESS = $$system(python "$${PWD}\compile_helper_2.py" CURRENT_BUILD_MODE=$${CURRENT_BUILD})
message(CURRENT_BUILD = $${CURRENT_BUILD})
</code></pre>
<p dir="auto">When I'm running QMake from QtCreator, the 'General Messages' output says:</p>
<pre><code>Project MESSAGE: CURRENT_BUILD = DEBUG
Project MESSAGE: CURRENT_BUILD = DEBUG
</code></pre>
<p dir="auto">But My script gets CURRENT_BUILD_MODE = RELEASE</p>
<p dir="auto">I tried to pass just some string to see if my script doesn't mess up what it receives, like so:</p>
<pre><code>message(CURRENT_BUILD = $${CURRENT_BUILD})
PYTHON_SCRIPT_SUCCESS = $$system(python "$${PWD}\compile_helper_2.py" CURRENT_BUILD_MODE=JUST_SOME_RANDOM_TEXT
message(CURRENT_BUILD = $${CURRENT_BUILD})

</code></pre>
<p dir="auto">And my script sees: <code>CURRENT_BUILD_MODE = JUST_SOME_RANDOM_TEXT</code> So the data passes correctly.<br />
I have no idea why it prints 'DEBUG' in the 'general messages' tab but in the script it sees 'RELEASE',</p>
<p dir="auto">Anyone has any ideas?</p>
<p dir="auto">I also pass other variables such as <code>QT_VERSION</code> and <code>OUT_PWD</code> which seem to be working as expected. When I change the build from 32 to 64 bit, the output dir changes accordingly and my script sees it.</p>
<p dir="auto">This also happens when I try to determine the current build bitness like so:</p>
<pre><code>contains(QT_ARCH, i386) {
    CURRENT_BITNESS = 32-bit
} else {
    CURRENT_BITNESS = 64-bit
}
</code></pre>
<p dir="auto">In the 'general messages' tab it says 32-bit, but in the script it sees 64-bit.</p>
]]></description><link>https://forum.qt.io/topic/136924/passing-qmake-variable-to-a-script</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 23:20:56 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/136924.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 01 Jun 2022 12:17:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Passing QMake variable to a script on Thu, 09 Jun 2022 07:55:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/curtwagner1984">@<bdi>Curtwagner1984</bdi></a> said in <a href="/post/716586">Passing QMake variable to a script</a>:</p>
<blockquote>
<p dir="auto">How do you make sure that a command in qMake such as system(python <a href="http://myscript.py" target="_blank" rel="noopener noreferrer nofollow ugc">myscript.py</a>) is executed only once? Can QMAKE_POST_LINK be useful here, as described in this answer?</p>
</blockquote>
<p dir="auto">Yes, QMAKE_POST_LINK or a custom compiler should do the trick.</p>
]]></description><link>https://forum.qt.io/post/716981</link><guid isPermaLink="true">https://forum.qt.io/post/716981</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Thu, 09 Jun 2022 07:55:01 GMT</pubDate></item><item><title><![CDATA[Reply to Passing QMake variable to a script on Mon, 06 Jun 2022 06:57:46 GMT]]></title><description><![CDATA[<p dir="auto">Ok, I made some headway, but am not really closer to a solution.</p>
<p dir="auto">The general idea of what I'm making is this. My python script gets QT variables from qMake such as build type, build bitness, qt version etc and creates an <code>ini</code> file with this information. It also puts other useful info in the ini such as compile date and the latest git commit hash. The script later uses this ini file to generate a header file with macros that I use in the code (Such as writing the compile date and release mode in the 'about' section of the app)</p>
<p dir="auto">The generated '.h' file looks like this:</p>
<pre><code>#ifndef COMPILE_INFO_H
#define COMPILE_INFO_H
        
#define APP_NAME             "Tester APP"
#define APP_VERSION          "V1.21"
#define APP_COMPILE_DATE     "06-June-2022"
#define APP_GIT_HASH         "1500079"
#define QT_VERSION_STR       "5.15.2"
#define CURRENT_BUILD_MODE   "RELEASE"
#define CURRENT_BITNESS      "64-bit"

#endif // COMPILE_INFO_H
        
// THIS FILE IS AUTOMATICALLY GENERATED BY A PYTHON  AND SHOULD NOT BE EDITED MANUALLY.
</code></pre>
<p dir="auto">And this is how the <code>ini</code> file looks:</p>
<pre><code>#Fields inputed manually
[VERSION_INFO] 
APP_NAME =Tester APP
APP_VERSION = V1.21
#name of the header file to generate.
APP_HEADER_FILENAME = compile_info.h  

#Everything else is automatically generated by the script

[GENERATED_SETTINGS]
APP_GIT_HASH = 1500079
APP_COMPILE_DATE = 06-June-2022

[QMAKE_VARIABLES]
QT_VERSION_STR = 5.15.2
QT_INSTALL_LIBEXECS = C:/Qt_NEW_INSTALL/5.15.2/mingw81_32/bin
OUT_PWD = C:/builddir//build-TEST_APP-Desktop_Qt_5_15_2_MinGW_32_bit-Debug
SOURCE_DIR = C:/WorkDir/Development/Source/TEST_APP
INI_FILENAME = app_info.ini
COUNT = 4
CURRENT_BUILD_MODE = RELEASE
CURRENT_BITNESS = 64-bit

</code></pre>
<p dir="auto">I tried to print out the 'CURRENT_BITNESS' value in the script. And I see 32-bit. But the output file still says 64bit. After reading online, I saw that qMake usually makes multiple runs (Executed multiple times). And this is indeed what I saw when I printed out messages in qMake using <code>message(my message)</code>. I saw it repeating multiple times. So I thought maybe qMake runs once with the argument being 32-bit and then again with the argument being 64-bit.</p>
<p dir="auto">To test this I first added a COUNT entry to my ini file. And before each write to the file I incremented the variable. And indeed after each time I run qmake, the COUNT variable is incremented by 3.</p>
<p dir="auto">I tried to limit the amount of times qMake runs the script. I saw in <a href="https://stackoverflow.com/a/19119104/5550624" target="_blank" rel="noopener noreferrer nofollow ugc">this</a> answer that doing something like this:</p>
<pre><code>!build_pass:message("This message should appear only once")
</code></pre>
<p dir="auto">Will limit the printing to only once. I tried it and it indeed worked with printing messages... So I tried it with the execution of the script:</p>
<pre><code>!build_pass:PYTHON_TARGET_STR = $$system(python "$${PWD}\compile_helper_2.py" QT_VERSION_STR=$${QT_VERSION} QT_INSTALL_LIBEXECS=$$[QT_INSTALL_LIBEXECS] OUT_PWD=$${OUT_PWD} CURRENT_BUILD_MODE=$${CURRENT_BUILD} CURRENT_BITNESS=$${CURRENT_BITNESS} SOURCE_DIR=$${PWD} INI_FILENAME=app_info.ini)

!build_pass:message(PYTHON_TARGET_STR = $${PYTHON_TARGET_STR})
</code></pre>
<p dir="auto">And indeed the message printed only once. However the counter in my ini file still incremented by 3.</p>
<p dir="auto">I decided to do something else, in addition to just writing the bitness in the ini file I would keep a history of written bitness, by adding a field to the ini file with the current count. So if the count starts at zero the first time the key CURRENT_BITNESS_1 will be added and then the second time CURRENT_BITNESS_2 etc.</p>
<p dir="auto">And indeed what I got in the ini file was:</p>
<pre><code>COUNT = 3
CURRENT_BUILD_MODE = RELEASE
CURRENT_BITNESS = 64-bit
CURRENT_BITNESS_1 = 32-bit
CURRENT_BITNESS_2 = 32-bit
CURRENT_BITNESS_3 = 64-bit
</code></pre>
<p dir="auto">So the suspicion was correct. The value is indeed overwritten in the final run of qMake and I have no idea how to resolve my issue.</p>
<h1>TL;DR</h1>
<hr />
<p dir="auto">How do you make sure that a command in qMake such as <code>system(python myscript.py)</code> is executed <strong>only once</strong>? Can QMAKE_POST_LINK be useful here, as described in <a href="https://stackoverflow.com/a/3626970/5550624" target="_blank" rel="noopener noreferrer nofollow ugc">this</a> answer?</p>
]]></description><link>https://forum.qt.io/post/716586</link><guid isPermaLink="true">https://forum.qt.io/post/716586</guid><dc:creator><![CDATA[Curtwagner1984]]></dc:creator><pubDate>Mon, 06 Jun 2022 06:57:46 GMT</pubDate></item></channel></rss>