2

I have a project with multiple sub-projects. One sub-project for executable and the rest for shared libraries. Each sub-project has its own *.pro file.

I need to define a compiler preprocessing macro, but I don't want to repeat defining it in each *.pro file. Is it possible to share a macro definition among multiple sub-projects?


My sample preprocessing macro:

#define PI 3.1415926

Adding to *.pro files:

DEFINES += "PI=\"3.1415926\""
Megidd
  • 7,089
  • 6
  • 65
  • 142

1 Answers1

3

You can define your macro in a .pri file (config.pri, for example) and include this .pri file in each .pro files for your sub-projects.

config.pri

DEFINES += "PI=\"3.1415926\""

sub_project.pro

include (/path/to/config.pri)

This forces you to modify each sub-projects .pro files though.

R0m1
  • 240
  • 1
  • 11
  • As @vahancho suggested in a comment, the `*.pri` files are usually used for this purpose, right? – Megidd May 20 '19 at 10:14
  • 1
    Well, [looks like](https://stackoverflow.com/q/8358627/3405291) there is not much technical difference between `*.pro` and `*.pri` – Megidd May 20 '19 at 10:16
  • still it is a convention to use .pri instead of pro for `include` directives – UmNyobe May 20 '19 at 10:19
  • 1
    Yes indeed. I was not aware of this .pri naming convention (https://wiki.qt.io/Including_.pro_Files). I'm editing the answer. – R0m1 May 20 '19 at 10:19