7
votes

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

1
I never used, but guess this: $(VAR) => Contents of an Environment variable at the time Makefile (not qmake) is runMohammad Kanan
So, you can't do this in *.pro file exclusively?Ross Rogers
@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 qmakeInnocent Bystander
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

1 Answers

0
votes

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.