8

When building, I want to speed up the build with environment variable:

MAKEFLAGS=-j12

I know how to set this in Qt Creator:

  1. Projects → Build → Build Environment Details → Add

  2. Add MAKEFLAGS with a value of -j12

This shows up in the *.pro.user file as:

<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges">
  <value type="QString">MAKEFLAGS=-j12</value>
</valuelist>

The process works great and really speeds up the compile, but I have to go through this step for each kit and debug/release combo. When I upgrade Qt releases, I have to do this process all over for each combination.

How can I set that environment variable in the *.pro file and have the environment variable propagate into every build flow?

Per the comments and the linked question, I have tried the *.pro.shared as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<qtcreator>
  <data>
  <variable>ProjectExplorer.Project.Target.0</variable>
  <valuemap type="QVariantMap">
   <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
    <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges">
     <value type="QString">MAKEFLAGS=-j12</value>
    </valuelist>
   </valuemap>
  </valuemap>
 </data>
 <data>
  <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
  <value type="int">18</value>
 </data>
 <data>
  <variable>Version</variable>
  <value type="int">18</value>
 </data>
</qtcreator>

The 18 matches that generated when I nuke and then Qt Creator recreates the *.pro.user file on restart of Qt Creator

Ross Rogers
  • 23,523
  • 27
  • 108
  • 164
  • 1
    I never used, but guess this: `$(VAR) => Contents of an Environment variable at the time Makefile (not qmake) is run` – Mohammad Kanan Jan 18 '18 at 17:50
  • 2
    Possible duplicate of [MAKEFLAGS in Qt Creator via .pro project file](https://stackoverflow.com/questions/38457212/makeflags-in-qt-creator-via-pro-project-file) – eyllanesc Jan 18 '18 at 17:57
  • So, you can't do this in *.pro file exclusively? – Ross Rogers Jan 18 '18 at 18:05
  • Alternatively, care to elucidate how you put that flag in every build using a *.pro.shared? RTFM isn't an answer. – Ross Rogers Jan 18 '18 at 18:21
  • @MohammadKanan , care to expand on what you're saying? – Ross Rogers Jan 18 '18 at 19:37
  • 1
    @RossRogers _"Per the comments and the linked question, I have tried the *.pro.shared as follows: ..."_ And it didn't work? Which OS? Maybe just run QtCreator and/or qmake with modified env. Eg in bash you can do: `MAKEFLAGS=-j12 qmake` – Super-intelligent Shade Jan 18 '18 at 19:43
  • @RossRogers, check this, could be useful https://stackoverflow.com/questions/7754218/qmake-how-to-add-and-use-a-variable-into-the-pro-file – Mohammad Kanan Jan 18 '18 at 19:48
  • @MohammadKanan , I don't want to read environment variables; I want to write them. Thanks anyways. – Ross Rogers Jan 18 '18 at 20:56
  • @InnocentBystander , I'm running inside of Qt Creator and yes I could do `MAKEFLAGS=-j12 ~/Qt/Tools/QtCreator/bin/qtcreator` , but I was hoping to make the solution work within the repo. I know this isn't a huge problem and now I've spent more time on this question than I'll ever spend setting that environment variable through Qt Creator for each new build type. This problem has been around for years and googling it shows other people having been trying to do this exact thing, to no avail for years. What a shame. – Ross Rogers Jan 18 '18 at 21:00
  • 1
    Doggone it, you're right @InnocentBystander . I'm just going to modify all my entry points to Qt Creator to set that environment variable. Easier than doing anything inside of Qt Creator. – Ross Rogers Jan 18 '18 at 21:17

1 Answers1

0

You can set default environment variables for each kit. You don't need to regenerate the .pro or .pro.user file for it to happen. When you add the definition, it'll make it available to the project automatically.

Just go to Tools | Options | Kits and select your kit. Then, scroll down to where it has the Environment label on the left, and a "Change" button on the right. Click it. Then, paste MAKEFLAGS=-j4 in that window. If you then close out of preferences and go to Projects and select the "Build" entry for your compiler on the left, and scroll down to your Build Environment at right, you'll find it there. Then, every project you make with that toolset will have the environment variable. Of course, you'll have to redefine it every time you update the compiler.

CodeLurker
  • 1,248
  • 13
  • 22
  • I've done it that way, but how do you set it in the pro file so that when you compile it on different machines, you get the edits? I don't want to go into the kit and change it on 5.10, 5.11.1, 5.12.0, 5.13.1, 5.13.2, 5.13.3 and on each release/debug/profile and android/windows/linux combo and then on every machine. I wish there were an easy way to do this in the pro file of the repo. – Ross Rogers Jan 19 '20 at 23:53