[CMake] Mark Qt include directories as system
-
Hi,
I'm building my application with clang. During compilation I see plenty of warnings refering to Qt includes and autogenerated files. Like/var/run/tc_studio/src/data/communication.h(20,3): warning: 'nullptr' is incompatible with C++98 [-Wc++98-compat] Q_OBJECT ^ /var/qt_dir/include/QtCore/qobjectdefs.h(182,5): note: expanded from macro 'Q_OBJECT' QT_TR_FUNCTIONS \ ^ /var/qt_dir/include/QtCore/qobjectdefs.h(140,61): note: expanded from macro 'QT_TR_FUNCTIONS' static inline QString tr(const char *s, const char *c = nullptr, int n = -1) \
or
In file included from /var/cmake-build-cross/src/teco_studio_lib_autogen/mocs_compilation.cpp:2: /var/cmake-build-cross/src/tc_studio_lib_autogen/QYFM2Z2WYQ/moc_communication.cpp(43,1): warning: constructor call from initializer list is incompatible with C++98 [-Wc++98-compat] QT_MOC_LITERAL(9, 179, 19), // "nodePropertyChanged" ^~~~~~~~~~~~~~~~~~~~~~~~~~ /var/cmake-build-cross/src/teco_studio_lib_autogen/QYFM2Z2WYQ/moc_communication.cpp(28,5): note: expanded from macro 'QT_MOC_LITERAL' Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /var/qt_dir/include/QtCore/qbytearray.h(137,5): note: expanded from macro 'Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET' Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /var/qt_dir/include/QtCore/qarraydata.h(293,7): note: expanded from macro 'Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET' { Q_REFCOUNT_INITIALIZE_STATIC, size, 0, 0, offset } \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /var/qt_dir/include/QtCore/qrefcount.h(113,40): note: expanded from macro 'Q_REFCOUNT_INITIALIZE_STATIC' #define Q_REFCOUNT_INITIALIZE_STATIC { Q_BASIC_ATOMIC_INITIALIZER(-1) } ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /var/qt_dir/include/QtCore/qatomic_cxx11.h(466,45): note: expanded from macro 'Q_BASIC_ATOMIC_INITIALIZER' # define Q_BASIC_ATOMIC_INITIALIZER(a) { a } ^~~~~
For SDK includes I easily use include_directories(SYSTEM /var/win10_sdk/).
In Qt cmake files I didn't find anything usefull. For all I understand - with this target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Widgets) I add include directories to my application.
And those folders are added with set_property(TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${_Qt5Core_OWN_INCLUDE_DIRS}).So ... don't know how to change it....
get_property(prop TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES) set_property(TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES "") set_property(TARGET Qt5::Core PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${prop})
before adding library to application didn't helped. In result - library include dirs aren't added to application (as expected), but INTERFACE_SYSTEM_INCLUDE_DIRECTORIES aren't added to application (as stated in cmake property.
I don't know HOW adding include directories as standard, not system, is better. Maybe some prefix or parameter in find_package?
-
Qt include dirs are already marked as system includes dirs when using imported targets - at least on windows and linux. So make sure to use a recent Qt and CMake version.
-
Hi,
I'm building my application with clang. During compilation I see plenty of warnings refering to Qt includes and autogenerated files. Like/var/run/tc_studio/src/data/communication.h(20,3): warning: 'nullptr' is incompatible with C++98 [-Wc++98-compat] Q_OBJECT ^ /var/qt_dir/include/QtCore/qobjectdefs.h(182,5): note: expanded from macro 'Q_OBJECT' QT_TR_FUNCTIONS \ ^ /var/qt_dir/include/QtCore/qobjectdefs.h(140,61): note: expanded from macro 'QT_TR_FUNCTIONS' static inline QString tr(const char *s, const char *c = nullptr, int n = -1) \
or
In file included from /var/cmake-build-cross/src/teco_studio_lib_autogen/mocs_compilation.cpp:2: /var/cmake-build-cross/src/tc_studio_lib_autogen/QYFM2Z2WYQ/moc_communication.cpp(43,1): warning: constructor call from initializer list is incompatible with C++98 [-Wc++98-compat] QT_MOC_LITERAL(9, 179, 19), // "nodePropertyChanged" ^~~~~~~~~~~~~~~~~~~~~~~~~~ /var/cmake-build-cross/src/teco_studio_lib_autogen/QYFM2Z2WYQ/moc_communication.cpp(28,5): note: expanded from macro 'QT_MOC_LITERAL' Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /var/qt_dir/include/QtCore/qbytearray.h(137,5): note: expanded from macro 'Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET' Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /var/qt_dir/include/QtCore/qarraydata.h(293,7): note: expanded from macro 'Q_STATIC_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET' { Q_REFCOUNT_INITIALIZE_STATIC, size, 0, 0, offset } \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /var/qt_dir/include/QtCore/qrefcount.h(113,40): note: expanded from macro 'Q_REFCOUNT_INITIALIZE_STATIC' #define Q_REFCOUNT_INITIALIZE_STATIC { Q_BASIC_ATOMIC_INITIALIZER(-1) } ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /var/qt_dir/include/QtCore/qatomic_cxx11.h(466,45): note: expanded from macro 'Q_BASIC_ATOMIC_INITIALIZER' # define Q_BASIC_ATOMIC_INITIALIZER(a) { a } ^~~~~
For SDK includes I easily use include_directories(SYSTEM /var/win10_sdk/).
In Qt cmake files I didn't find anything usefull. For all I understand - with this target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Widgets) I add include directories to my application.
And those folders are added with set_property(TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${_Qt5Core_OWN_INCLUDE_DIRS}).So ... don't know how to change it....
get_property(prop TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES) set_property(TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES "") set_property(TARGET Qt5::Core PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${prop})
before adding library to application didn't helped. In result - library include dirs aren't added to application (as expected), but INTERFACE_SYSTEM_INCLUDE_DIRECTORIES aren't added to application (as stated in cmake property.
I don't know HOW adding include directories as standard, not system, is better. Maybe some prefix or parameter in find_package?
@SebastianM said in [CMake] Mark Qt include directories as system:
During compilation I see plenty of warnings refering to Qt includes and autogenerated files
These relate to the C++ standard. Basically C++11 is a requirement.
You should be able to fix this by adding (MyApp should be replaced with the name of your target):set_target_properties(MyApp PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON )
And those folders are added with set_property(TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${_Qt5Core_OWN_INCLUDE_DIRS}).
This is the correct way to do it. From the CMake doc page you liked:
When target dependencies are specified using target_link_libraries(), CMake will read this property from all target dependencies to mark the same include directories as containing system headers.
For SDK includes I easily use include_directories(SYSTEM /var/win10_sdk/).
this is deprecated in modern CMake