Search code examples
c++qtbuildqmake

Defining a global macro for all projects in Qt project tree


Suppose, I have a project with structure like this:

/project
|--- root.pro
   |--- app
   |    |--- app.pro
   |    `--- ... (source files of app)
   |--- test
   |    |--- test.pro
   |    `--- ... (source files of test)

The root.pro contains SUBDIRS += project test. I want to test code that uses conditional inclusion. So I want to add my own global define in root project to compile application and test the same way. I assume that I can do that via DEFINES += MY_DEFINE in my root.pro, but it doesn't work.

So the question is: how to define global macro to use it in application project and test project?


Solution

  • You should create a file that you include from all your projects. For example in include.mk in the root directory:

    DEFINES += MY_DEFINE
    

    Then in each project:

    include("../include.mk")