Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang PCH precompiled header support ; #14

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -813,10 +813,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 @@ -903,7 +904,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