Skip to content

Commit 31bcb90

Browse files
committed
Add base support for Include-What-You-Use
1 parent ae726f3 commit 31bcb90

File tree

7 files changed

+421
-1
lines changed

7 files changed

+421
-1
lines changed

3rdparty/basic/basic.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ TEMPLATE = lib
33
TARGET = basic
44
CONFIG += staticlib
55

6+
USE -= check_iwyu
7+
68
include(../../common.pri)
79

810
HEADERS += basic_interpreter.h

3rdparty/kdiff3/kdiff3.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ TEMPLATE = lib
44
TARGET = kdiff3
55
CONFIG += staticlib
66

7+
USE -= check_iwyu
8+
79
include(../../common.pri)
810

911
QT *= widgets

3rdparty/qtsingleapplication/qtsingleapplication.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ TEMPLATE = lib
44
TARGET = qtsingleapplication
55
CONFIG += staticlib
66

7+
USE -= check_iwyu
8+
79
include(../../common.pri)
810

911
QT *= widgets network

common.pri

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ contains(MODULES, qtsingleapplication) {
4747
LIBS += -L$$shadowed($${PROJECT_ROOT_PATH}/3rdparty/qtsingleapplication)
4848
LIBS += -lqtsingleapplication
4949
}
50-
50+
5151
contains(MODULES, addons) {
5252
MODULES *= basic
5353
INCLUDEPATH += $${PROJECT_ROOT_PATH}/addons/include
@@ -82,6 +82,29 @@ contains(MODULES, basic) {
8282
}
8383

8484

85+
#------------------#
86+
# iwyu support #
87+
#------------------#
88+
89+
contains(USE, check_iwyu) {
90+
linux*:IWYU_FLAGS += -fPIE
91+
92+
IWYU_FLAGS += $(DEFINES) -w $(INCPATH)
93+
94+
for(include, IWYU_INCLUDES) {
95+
IWYU_FLAGS += -I$$include
96+
}
97+
98+
IWYU_EXTRA_FLAGS += -Xiwyu --max_line_length=120 -Xiwyu --mapping_file=$${PROJECT_ROOT_PATH}/tools/iwyu.imp
99+
100+
iwyu.output = ${QMAKE_FILE_BASE}.cpp.log
101+
iwyu.commands = $${PROJECT_ROOT_PATH}/tools/iwyu_comp.sh $${IWYU_EXTRA_FLAGS} $${IWYU_FLAGS} ${QMAKE_FILE_NAME}
102+
iwyu.input = SOURCES
103+
iwyu.CONFIG += no_link target_predeps
104+
QMAKE_EXTRA_COMPILERS += iwyu
105+
}
106+
107+
85108
#
86109
# function findFiles(dir, basename)
87110
# Returns a list of files with this basename.

tools/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,30 @@ Usage (from source root):
1414
or
1515

1616
astyle --project=tools/astyle.cfg -I -r 'module/*.cpp' 'module/*.h'
17+
18+
19+
Include-What-You-Use
20+
--------------------
21+
22+
https://include-what-you-use.org
23+
24+
To use IWYU, run qmake with the optional USE flag:
25+
26+
qmake -r USE+=check_iwyu path/to/gcodeworkshop_top.pro
27+
28+
The following additional parameters are possible:
29+
30+
* `IWYU_INCLUDES` specifies additional paths to search for header files,
31+
this comes in handy in Debian:
32+
33+
IWYU_INCLUDES=/usr/lib/llvm-13/include/c++/v1
34+
35+
* `IWYU_EXTRA_FLAGS` additional options specifically IWYU:
36+
37+
IWYU_EXTRA_FLAGS='-Xiwyu --update_comments'
38+
39+
40+
Additional links:
41+
42+
* https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUMappings.md
43+
* https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUPragmas.md

tools/iwyu.imp

Lines changed: 360 additions & 0 deletions
Large diffs are not rendered by default.

tools/iwyu_comp.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
include-what-you-use $* 2>&1 | tee $(basename -- "${!#}").log
4+
exit 0

0 commit comments

Comments
 (0)