aboutsummaryrefslogtreecommitdiff
path: root/mk/precompiled-headers.mk
blob: 1a727ba1b70d17aad489842ac04e05fd358e9b44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
PRECOMPILE_HEADERS ?= 1

print-var-help += \
  echo "  PRECOMPILE_HEADERS ($(PRECOMPILE_HEADERS)): Whether to use precompiled headers to speed up the build";

GCH = $(buildprefix)precompiled-headers.h.gch

$(GCH): precompiled-headers.h
	@rm -f $@
	@mkdir -p "$(dir $@)"
	$(trace-gen) $(CXX) -x c++-header -o $@ $< $(GLOBAL_CXXFLAGS)

PCH = $(buildprefix)precompiled-headers.h.pch

$(PCH): precompiled-headers.h
	@rm -f $@
	@mkdir -p "$(dir $@)"
	$(trace-gen) $(CXX) -x c++-header -o $@ $< $(GLOBAL_CXXFLAGS)

clean-files += $(GCH) $(PCH)

ifeq ($(PRECOMPILE_HEADERS), 1)

  ifeq ($(CXX), g++)

    GLOBAL_CXXFLAGS_PCH += -include $(buildprefix)precompiled-headers.h -Winvalid-pch

    GLOBAL_ORDER_AFTER += $(GCH)

  else ifeq ($(CXX), clang++)

    GLOBAL_CXXFLAGS_PCH += -include-pch $(PCH) -Winvalid-pch

    GLOBAL_ORDER_AFTER += $(PCH)

  else

    $(error Don't know how to precompile headers on $(CXX))

  endif

endif