Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [CMake] Mark Qt include directories as system
Forum Updated to NodeBB v4.3 + New Features

[CMake] Mark Qt include directories as system

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 502 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SebastianMS Offline
    SebastianMS Offline
    SebastianM
    wrote on last edited by
    #1

    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?

    VRoninV 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • SebastianMS SebastianM

        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?

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        @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

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved