QMake precompiled headers in *.pri files. How?
-
Hello all!
The project contain many modules that descibed in *.pri files. Each of them has some headers for being precompiled. Trying to find the correct way of using precompiled headers in case of multiple *.pri files. In all of official documentation nothing about it. The example described in it just with one *.pro file without any includes *.pri
The questions is:
-- the QMake variable named PRECOMPILED_HEADER, does it mean one header file or it could be using for multiple files in different places or in different *.pri files, something like this:
PRECOMPILED_HEADER += header1.h ... PRECOMPILED_HEADER += header2.h-- Some of examples from KDAB contain "#pragma once" and it's about CMake. Official documentation is nothing about it? Should it be using with pragma in QMake too? Something like this:
// Add C includes here #if defined __cplusplus #pragma once // Add C++ includes here #include <stdlib> #include <iostream> #include <vector> #include <QApplication> // Qt includes #include <QPushButton> #include <QLabel> #include "thirdparty/include/libmain.h" #include "my_stable_class.h" ... #endif -
does it mean one header file or it could be using for multiple files in different places
Unfortunately qmake doesn't support multiple precompiled headers in a single project. Only the first file in
PRECOMPILED_HEADERwill be used. You can have different precompiled headers if you use a subdirs project, where each subdir would be its own library with its own header, or you can make a single header and include all the rest in it.Some of examples from KDAB contain "#pragma once" and it's about CMake. Official documentation is nothing about it? Should it be using with pragma in QMake too?
It has nothing to do with CMake or qmake.
#pragma onceis a compiler extension that replaces include guards i.e. in a standard C++ you would create headers like this:#ifndef MYHEADER_H #define MYHEADER_H //something something #endifwith this extension you can simplify this to
#pragma once //something somethingThere are small differences in the behavior of these two in some corner cases, but for normal usage they are equivalent. Whether you use one or the other is up to you. All major compilers support this, so it's just your decision if you're ok with using language extension.
-
does it mean one header file or it could be using for multiple files in different places
Unfortunately qmake doesn't support multiple precompiled headers in a single project. Only the first file in
PRECOMPILED_HEADERwill be used. You can have different precompiled headers if you use a subdirs project, where each subdir would be its own library with its own header, or you can make a single header and include all the rest in it.Some of examples from KDAB contain "#pragma once" and it's about CMake. Official documentation is nothing about it? Should it be using with pragma in QMake too?
It has nothing to do with CMake or qmake.
#pragma onceis a compiler extension that replaces include guards i.e. in a standard C++ you would create headers like this:#ifndef MYHEADER_H #define MYHEADER_H //something something #endifwith this extension you can simplify this to
#pragma once //something somethingThere are small differences in the behavior of these two in some corner cases, but for normal usage they are equivalent. Whether you use one or the other is up to you. All major compilers support this, so it's just your decision if you're ok with using language extension.
@Chris-Kawa said in QMake precompiled headers in *.pri files. How?:
It has nothing to do with CMake or qmake. #pragma once is a compiler extension that replaces include guards i.e. in a standard C++
That's interesting about #pragma once. Never been using it. For the more than 10 years of Qt developing got it from you for the first time. Definetly need to refresh reading of compiler reference. Thanks a lot for explanation.
Issue closed.