Skip to content

Commit

Permalink
rules/toolkit-cpp-clang_33.ham: Clang PCH precompiled header support ;
Browse files Browse the repository at this point in the history
  • Loading branch information
prenaux committed Dec 16, 2022
1 parent 0ca2782 commit c090b87
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 5 deletions.
101 changes: 101 additions & 0 deletions rules/toolkit-cpp-clang_33.ham
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ if $(BUILD) = da {
CLANG_SANITIZE ?= 1 ;
}

SUFPCH = .h.pch ;

STRICT_ALIASING_FLAGS = -fno-strict-aliasing ;

CLANG_CC_ARGS +=
Expand Down Expand Up @@ -185,3 +187,102 @@ rule tkNoC++RTTI {

rule tkCC++Lint {
}

actions tkPchObjectCpp
{
SRC_ABSPATH="`pwd`/$(>)"
$(C++) -x c++-header -o $(<) $(C++FLAGS) $(OPTIM) $(CCDEFS) $(CCHDRS) "${SRC_ABSPATH}"
}
rule tkPchObjectCpp
{
DEPENDS $(<) : $(>) ;

local objSuf = [ FTargetSuffix $(>) ] ;
local obj = $(>:S=$(objSuf)) ;
C++FLAGS on $(<) += $(C++FLAGS) $(SUBDIRC++FLAGS) [ VarOnGet C++FLAGS : $(obj) ] ;
if $(DEBUG) = 1 {
C++FLAGS on $(<) += $(CLANG_DBG_ARGS) ;
}
else {
C++FLAGS on $(<) += $(CLANG_OPT_ARGS) ;
}
if $(PKGTYPE) = dll {
C++FLAGS on $(<) += $(PICFLAGS) ;
}
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}
rule tkPchObject
{
Clean clean : $(<) ;

MakeLocate $(<) : $(LOCATE_TARGET) ;
SEARCH on $(>) = $(SEARCH_SOURCE) ;

HDRS on $(<) = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ;

HDRRULE on $(>) = HdrRule ;
HDRSCAN on $(>) = $(HDRPATTERN) ;
HDRSEARCH on $(>) = $(SEARCH_SOURCE:E) $(SUBDIRHDRS) $(HDRS) $(STDHDRS) ;

HDRGRIST on $(>) = $(HDRGRIST) ;

DEFINES on $(<) += $(DEFINES) ;

tkPchObjectCpp $(<) : $(>) ;
}

# tkC++Pch TARGET : <pch>.cpp : [pchdep-sources] : [nopchdep-sources]
# cf: https://clang.llvm.org/docs/PCHInternals.html
rule tkC++Pch
{
local _src = ;
local _extrasrc = ;

for _i in $(3) {
if $(_i) = $(>)
{ continue ; }
# PCH is for C++ only
local suf = $(_i:S) ;
if $(suf) = .cpp
|| $(suf) = .cxx
|| $(suf) = .cc
{
_src += [ FGristFiles $(_i) ] ;
}
else {
_extrasrc += [ FGristFiles $(_i) ] ;
}
}
for _i in $(4) {
if $(_i) = $(>) { continue ; }
_extrasrc += [ FGristFiles $(_i) ] ;
}

# ECHO "I/_src:" $(_src) ;
# ECHO "I/_extrasrc:" $(_extrasrc) ;

local _pch = $(>:S=$(SUFPCH)) ;
local _pchTarget = [ FDirName $(LOCATE_TARGET) $(>:S=$(SUFPCH)) ] ;
local _dir = $(_pchTarget:D) ;
local _cpp = [ FGristFiles $(>) ] ;
local _hdr = $(>:S=.h) ;
local _obj = $(_cpp:S=$(SUFOBJ)) ;

MakeLocate $(_pch) : $(_dir) ;
tkPchObject $(_pchTarget) : $(_cpp) ;

INCLUDES $(<) : $(_cpp) ;
DEPENDS $(<) : $(_obj) ;
NotFile $(<) ;
NoUpdate $(<) ;

Clean clean : $(_pchTarget) ;
DEPENDS pch : $(<) ;

ObjectC++Flags $(_src) : -include-pch $(_pchTarget) ;
DEPENDS $(_src:S=$(SUFOBJ)) : $(<) $(_pchTarget) ;

logVerbose "- PCH:" $(_pchTarget) ;
return $(PCH) ;
}
15 changes: 10 additions & 5 deletions rules/toolkit.ham
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,11 @@ rule tkBuildPackage
switch $(_i) {
# Use precompiled header, should be the first option if specified
case pch :
if $(SUFPCH) && ( ! ( $(NO_PCH) = 1 ) ) && ( ( ! $(FLYMAKE) ) || ( $(FLYMAKE_PCH) = 1 ) ) {
# Use _exsrc
_pch = [ tkC++Pch PCH_$(PACKAGE) : stdafx.cpp : $(_src) $(_exsrc) : $(_nopchsrc) : $(>) ] ;
# _exsrc += stdafx.cpp ;
if $(SUFPCH)
&& ( ! ( $(NO_PCH) = 1 ) )
&& ( ( ! $(FLYMAKE) ) || ( $(FLYMAKE_PCH) = 1 ) )
{
_pch = 1 ;
}
# Require exceptions
case exc :
Expand Down Expand Up @@ -876,7 +877,11 @@ rule tkBuildPackage
tkCC++Build $(_exsrc) $(_src) $(_nopchsrc) ;
}
ObjectOptimFlags $(_exsrc) $(_src) $(_nopchsrc) : $(PKGOPTIM) ;
OPTIM on $(_pch) = $(PKGOPTIM) ;

if $(_pch) {
_pch = [ tkC++Pch PCH_$(PACKAGE) : stdafx.cpp : $(_src) $(_exsrc) : $(_nopchsrc) : $(>) ] ;
OPTIM on $(_pch) = $(PKGOPTIM) ;
}

### Main build output ###
_src += $(_nopchsrc) ;
Expand Down

0 comments on commit c090b87

Please sign in to comment.