Is there a possibility to pass includes via -isystem when using qmake

大憨熊 提交于 2019-11-30 09:31:09

Easiest way I found is including directly via QMAKE_CXXFLAGS e.g. for Boost this looks like the following in the project file

QMAKE_CXXFLAGS += -isystem /usr/local/boost_1_44_0

I just added this to my macx-clang/qmake.conf:

QMAKE_CXXFLAGS += $$join(QMAKE_INCDIR_QT, " -isystem", "-isystem")

works nicely now.

Since many settings are hardcoded into spec files, I think you need to create your own. Start with reading mkspecs/linux-g++/qmake.conf or mkspecs/win32-g++/qmake.conf

You will see that by default CONFIG uses warn_on setting. and in mkspecs/common/g++ you have

QMAKE_CFLAGS_WARN_ON    += -Wall -W
QMAKE_CFLAGS_WARN_OFF   += -w
QMAKE_CXXFLAGS_WARN_ON  += $$QMAKE_CFLAGS_WARN_ON
QMAKE_CXXFLAGS_WARN_OFF += $$QMAKE_CFLAGS_WARN_OFF

so you can change the spec file and make new settings default for every project, or you can set this variables in your project file.

CONFIG += warn_on
QMAKE_CFLAGS_WARN_ON    = -Wall -Werror -Wundef -Wextra -pedantic
QMAKE_CXXFLAGS_WARN_ON  = $$QMAKE_CFLAGS_WARN_ON

qt include path is hardcoded in mkspecs/features/qt.prf as

#handle includes
INCLUDEPATH = $$QMAKE_INCDIR_QT $$INCLUDEPATH #prepending prevents us from picking up "stale" includes

You don't want QMAKE_INCDIR_QT to be a part of INCLUDEPATH since its components are joined with -I. You want to expand it as $$join(QMAKE_INCDIR_QT, " -isystem", "-isystem") somewhere else...

Came up with a workaround: manually changing Makefile.

Add this line to .pro file

system(./suppress_system_warnings.sh)

And then create an executable file suppress_system_warnings.sh

#!/bin/bash
run_in_background() {
    pidof qmake > /dev/null
    while [ $? -eq 0 ]
    do
        sleep 0.2
        pidof qmake > /dev/null
    done

    file=Makefile
    new_line=$( grep ^INCPATH $file | sed 's:-I\/:-isystem\/:g' | sed  's:-I\$:-isystem\$:' )
    line_num=$( grep -n ^INCPATH $file | cut -d':' -f1 )

    head -n $(expr $line_num - 1) $file > __tmp
    echo $new_line >> __tmp
    tail -n +$(expr $line_num + 1) $file >> __tmp

    mv __tmp $file
    exit 0; 
}

run_in_background &
exit 0;
Alexis Wilke

Note that the correct answer to this one is to use the SYSTEM keyword in the include_target() macro:

include_directories(SYSTEM ${QT_INCLUDES})

This works for many libraries, not just Qt which I could use without too much problems. But the Magic++.h is really a horrible piece of work in comparison and I had to have this capability.

You can find more information on this question:

Use -isystem instead of -I with CMake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!