diff --git a/modules/codelite/codelite_project.lua b/modules/codelite/codelite_project.lua
index 7c5a2283..d427fe41 100755
--- a/modules/codelite/codelite_project.lua
+++ b/modules/codelite/codelite_project.lua
@@ -188,7 +188,6 @@
}
end
-
function m.compiler(cfg)
if configuration_iscustombuild(cfg) or configuration_isfilelist(cfg) then
_p(3, '')
@@ -201,9 +200,14 @@
local cxxflags = table.concat(table.join(sysincludedirs, toolset.getcxxflags(cfg), forceincludes, cfg.buildoptions), ";")
local cflags = table.concat(table.join(sysincludedirs, toolset.getcflags(cfg), forceincludes, cfg.buildoptions), ";")
local asmflags = ""
- local pch = ""
+ local pch = p.tools.gcc.getpch(cfg)
+ local usepch = "yes"
+ if pch == nil then
+ pch = "";
+ usepch = "no"
+ end
- _x(3, '', cxxflags, cflags, asmflags, pch)
+ _x(3, '', cxxflags, cflags, asmflags, pch, usepch)
for _, includedir in ipairs(cfg.includedirs) do
_x(4, '', project.getrelative(cfg.project, includedir))
diff --git a/modules/codelite/tests/test_codelite_config.lua b/modules/codelite/tests/test_codelite_config.lua
index fc839da0..e98c8b88 100644
--- a/modules/codelite/tests/test_codelite_config.lua
+++ b/modules/codelite/tests/test_codelite_config.lua
@@ -93,6 +93,16 @@
]]
end
+ function suite.OnProjectCfg_Pch()
+ pchheader "pch.h"
+ prepare()
+ codelite.project.compiler(cfg)
+ test.capture [[
+
+
+ ]]
+ end
+
function suite.OnProjectCfg_Linker()
prepare()
codelite.project.linker(cfg)
diff --git a/modules/gmake/gmake_cpp.lua b/modules/gmake/gmake_cpp.lua
index 3814b695..e1e561ef 100644
--- a/modules/gmake/gmake_cpp.lua
+++ b/modules/gmake/gmake_cpp.lua
@@ -567,51 +567,16 @@ end
function make.pch(cfg, toolset)
+ local pch = p.tools.gcc.getpch(cfg)
-- If there is no header, or if PCH has been disabled, I can early out
- if not cfg.pchheader or cfg.flags.NoPCH then
+ if pch == nil then
return
end
- -- Visual Studio requires the PCH header to be specified in the same way
- -- it appears in the #include statements used in the source code; the PCH
- -- source actual handles the compilation of the header. GCC compiles the
- -- header file directly, and needs the file's actual file system path in
- -- order to locate it.
-
- -- To maximize the compatibility between the two approaches, see if I can
- -- locate the specified PCH header on one of the include file search paths
- -- and, if so, adjust the path automatically so the user doesn't have
- -- add a conditional configuration to the project script.
-
- local pch = cfg.pchheader
- local found = false
-
- -- test locally in the project folder first (this is the most likely location)
- local testname = path.join(cfg.project.basedir, pch)
- if os.isfile(testname) then
- pch = project.getrelative(cfg.project, testname)
- found = true
- else
- -- else scan in all include dirs.
- for _, incdir in ipairs(cfg.includedirs) do
- testname = path.join(incdir, pch)
- if os.isfile(testname) then
- pch = project.getrelative(cfg.project, testname)
- found = true
- break
- end
- end
- end
-
- if not found then
- pch = project.getrelative(cfg.project, path.getabsolute(pch))
- end
-
_x(' PCH = %s', pch)
_p(' GCH = $(OBJDIR)/$(notdir $(PCH)).gch')
end
-
function make.pchRules(prj)
_p('ifneq (,$(PCH))')
_p('$(OBJECTS): $(GCH) $(PCH) | $(OBJDIR)')
diff --git a/modules/gmake2/gmake2_cpp.lua b/modules/gmake2/gmake2_cpp.lua
index 11c202dd..bc45cbd2 100644
--- a/modules/gmake2/gmake2_cpp.lua
+++ b/modules/gmake2/gmake2_cpp.lua
@@ -368,46 +368,12 @@
function cpp.pch(cfg, toolset)
+ local pch = p.tools.gcc.getpch(cfg)
-- If there is no header, or if PCH has been disabled, I can early out
- if not cfg.pchheader or cfg.flags.NoPCH then
+ if pch == nil then
return
end
- -- Visual Studio requires the PCH header to be specified in the same way
- -- it appears in the #include statements used in the source code; the PCH
- -- source actual handles the compilation of the header. GCC compiles the
- -- header file directly, and needs the file's actual file system path in
- -- order to locate it.
-
- -- To maximize the compatibility between the two approaches, see if I can
- -- locate the specified PCH header on one of the include file search paths
- -- and, if so, adjust the path automatically so the user doesn't have
- -- add a conditional configuration to the project script.
-
- local pch = cfg.pchheader
- local found = false
-
- -- test locally in the project folder first (this is the most likely location)
- local testname = path.join(cfg.project.basedir, pch)
- if os.isfile(testname) then
- pch = project.getrelative(cfg.project, testname)
- found = true
- else
- -- else scan in all include dirs.
- for _, incdir in ipairs(cfg.includedirs) do
- testname = path.join(incdir, pch)
- if os.isfile(testname) then
- pch = project.getrelative(cfg.project, testname)
- found = true
- break
- end
- end
- end
-
- if not found then
- pch = project.getrelative(cfg.project, path.getabsolute(pch))
- end
-
p.outln('PCH = ' .. pch)
p.outln('PCH_PLACEHOLDER = $(OBJDIR)/$(notdir $(PCH))')
p.outln('GCH = $(PCH_PLACEHOLDER).gch')
diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua
index c30233a1..d7942747 100644
--- a/src/tools/gcc.lua
+++ b/src/tools/gcc.lua
@@ -297,9 +297,47 @@
return result
end
+ -- relative pch file path if any
+ function gcc.getpch(cfg)
+ -- If there is no header, or if PCH has been disabled, I can early out
+ if not cfg.pchheader or cfg.flags.NoPCH then
+ return nil
+ end
+
+ -- Visual Studio requires the PCH header to be specified in the same way
+ -- it appears in the #include statements used in the source code; the PCH
+ -- source actual handles the compilation of the header. GCC compiles the
+ -- header file directly, and needs the file's actual file system path in
+ -- order to locate it.
+
+ -- To maximize the compatibility between the two approaches, see if I can
+ -- locate the specified PCH header on one of the include file search paths
+ -- and, if so, adjust the path automatically so the user doesn't have
+ -- add a conditional configuration to the project script.
+
+ local pch = cfg.pchheader
+ local found = false
+
+ -- test locally in the project folder first (this is the most likely location)
+ local testname = path.join(cfg.project.basedir, pch)
+ if os.isfile(testname) then
+ return project.getrelative(cfg.project, testname)
+ else
+ -- else scan in all include dirs.
+ for _, incdir in ipairs(cfg.includedirs) do
+ testname = path.join(incdir, pch)
+ if os.isfile(testname) then
+ return project.getrelative(cfg.project, testname)
+ end
+ end
+ end
+
+ return project.getrelative(cfg.project, path.getabsolute(pch))
+ end
+
--
-- Return a list of decorated rpaths
---
+--
-- @param cfg
-- The configuration to query.
-- @param dirs
@@ -328,10 +366,10 @@
rpath = "$$ORIGIN" .. rpath
end
- if mode == "linker" then
+ if mode == "linker" then
rpath = "-Wl,-rpath,'" .. rpath .. "'"
end
-
+
table.insert(result, rpath)
end