diff options
| author | ruki <[email protected]> | 2023-07-04 23:02:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-07-04 23:02:05 +0800 |
| commit | 6b5f9eca01dfa8cd654014ba537e59a8f2eceeb6 (patch) | |
| tree | 8a467b656d8eadc481698225e9c2dda1c48df424 /xmake | |
| parent | 92f26e98978d36475e49762114fd92c0a2324767 (diff) | |
add objc pch header support #3912
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/core/project/target.lua | 12 | ||||
| -rw-r--r-- | xmake/languages/objc++/load.lua | 4 | ||||
| -rw-r--r-- | xmake/languages/objc++/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 31 | ||||
| -rw-r--r-- | xmake/rules/objc++/precompiled_header/xmake.lua | 36 | ||||
| -rw-r--r-- | xmake/rules/objc++/xmake.lua | 4 |
6 files changed, 75 insertions, 16 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index befb589a2..c5e92e499 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2092,11 +2092,7 @@ end -- @param langkind c/cxx -- function _instance:pcoutputfile(langkind) - - -- init cache self._PCOUTPUTFILES = self._PCOUTPUTFILES or {} - - -- get it from the cache first local pcoutputfile = self._PCOUTPUTFILES[langkind] if pcoutputfile then return pcoutputfile @@ -2108,7 +2104,9 @@ function _instance:pcoutputfile(langkind) -- is gcc? local is_gcc = false - local _, toolname = self:tool(langkind == "c" and "cc" or "cxx") + local sourcekinds = {c = "cc", cxx = "cxx", m = "mm", mxx = "mxx"} + local sourcekind = assert(sourcekinds[langkind], "unknown language kind: " .. langkind) + local _, toolname = self:tool(sourcekind) if toolname and (toolname == "gcc" or toolname == "gxx") then is_gcc = true end @@ -2118,9 +2116,7 @@ function _instance:pcoutputfile(langkind) -- @note gcc has not -include-pch option to set the pch file path -- pcoutputfile = self:objectfile(pcheaderfile) - pcoutputfile = path.join(path.directory(pcoutputfile), path.basename(pcoutputfile) .. (is_gcc and ".gch" or ".pch")) - - -- save to cache + pcoutputfile = path.join(path.directory(pcoutputfile), path.basename(pcoutputfile) .. "." .. sourcekind .. (is_gcc and ".gch" or ".pch")) self._PCOUTPUTFILES[langkind] = pcoutputfile return pcoutputfile end diff --git a/xmake/languages/objc++/load.lua b/xmake/languages/objc++/load.lua index cbd729283..97cfca2c4 100644 --- a/xmake/languages/objc++/load.lua +++ b/xmake/languages/objc++/load.lua @@ -92,8 +92,8 @@ function _get_apis() -- target.set_xxx "target.set_headerdir" -- TODO deprecated , "target.set_config_header" - , "target.set_pcheader" - , "target.set_pcxxheader" + , "target.set_pmheader" + , "target.set_pmxxheader" -- target.add_xxx , "target.add_headers" -- TODO deprecated , "target.add_headerfiles" diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua index e503ba264..b40ab52e6 100644 --- a/xmake/languages/objc++/xmake.lua +++ b/xmake/languages/objc++/xmake.lua @@ -66,8 +66,8 @@ language("objc++") , "target.undefines" , "target.frameworkdirs" , "target.frameworks" - , "target.pcheader" - , "target.pcxxheader" + , "target.pmheader" + , "target.pmxxheader" , "toolchain.includedirs" , "toolchain.defines" , "toolchain.undefines" diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index b33bf0677..35b296ef0 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -335,7 +335,7 @@ end -- make the c precompiled header flag function nf_pcheader(self, pcheaderfile, target) - if self:kind() == "cc" or self:kind() == "mm" then + if self:kind() == "cc" then local pcoutputfile = target:pcoutputfile("c") if self:name() == "clang" then return {"-include", pcheaderfile, "-include-pch", pcoutputfile} @@ -347,7 +347,7 @@ end -- make the c++ precompiled header flag function nf_pcxxheader(self, pcheaderfile, target) - if self:kind() == "cxx" or self:kind() == "mxx" then + if self:kind() == "cxx" then local pcoutputfile = target:pcoutputfile("cxx") if self:name() == "clang" then return {"-include", pcheaderfile, "-include-pch", pcoutputfile} @@ -357,6 +357,30 @@ function nf_pcxxheader(self, pcheaderfile, target) end end +-- make the objc precompiled header flag +function nf_pmheader(self, pcheaderfile, target) + if self:kind() == "mm" then + local pcoutputfile = target:pcoutputfile("m") + if self:name() == "clang" then + return {"-include", pcheaderfile, "-include-pch", pcoutputfile} + else + return {"-include", path.filename(pcheaderfile), "-I", path.directory(pcoutputfile)} + end + end +end + +-- make the objc++ precompiled header flag +function nf_pmxxheader(self, pcheaderfile, target) + if self:kind() == "mxx" then + local pcoutputfile = target:pcoutputfile("mxx") + if self:name() == "clang" then + return {"-include", pcheaderfile, "-include-pch", pcoutputfile} + else + return {"-include", path.filename(pcheaderfile), "-I", path.directory(pcoutputfile)} + end + end +end + -- add the special flags for the given source file of target -- -- @note only it called when fileconfig is set @@ -631,6 +655,9 @@ function _compargv_pch(self, pcheaderfile, pcoutputfile, flags) if self:kind() == "cxx" then table.insert(pchflags, "-x") table.insert(pchflags, "c++-header") + elseif self:kind() == "mxx" then + table.insert(pchflags, "-x") + table.insert(pchflags, "objective-c++-header") end -- make the compile arguments list diff --git a/xmake/rules/objc++/precompiled_header/xmake.lua b/xmake/rules/objc++/precompiled_header/xmake.lua new file mode 100644 index 000000000..db2d9f036 --- /dev/null +++ b/xmake/rules/objc++/precompiled_header/xmake.lua @@ -0,0 +1,36 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +rule("objc.build.pcheader") + on_config(function (target, opt) + import("private.action.build.pcheader").config(target, "m", opt) + end) + before_build(function (target, opt) + import("private.action.build.pcheader").build(target, "m", opt) + end) + +rule("objc++.build.pcheader") + on_config(function (target, opt) + import("private.action.build.pcheader").config(target, "mxx", opt) + end) + before_build(function (target, opt) + import("private.action.build.pcheader").build(target, "mxx", opt) + end) + diff --git a/xmake/rules/objc++/xmake.lua b/xmake/rules/objc++/xmake.lua index 447c12176..bd93bfa82 100644 --- a/xmake/rules/objc++/xmake.lua +++ b/xmake/rules/objc++/xmake.lua @@ -21,7 +21,7 @@ -- define rule: objc.build rule("objc.build") set_sourcekinds("mm") - add_deps("c.build.pcheader", "c.build.optimization") + add_deps("objc.build.pcheader", "c.build.optimization") after_load(function (target) -- deprecated, we need only use `add_mflags("-fno-objc-arc")` to override it if target:values("objc.build.arc") == false then @@ -36,7 +36,7 @@ rule("objc.build") -- define rule: objc++.build rule("objc++.build") set_sourcekinds("mxx") - add_deps("c++.build.pcheader", "c++.build.optimization") + add_deps("objc++.build.pcheader", "c++.build.optimization") after_load(function (target) -- deprecated, we need only use `add_mxxflags("-fno-objc-arc")` to override it if target:values("objc++.build.arc") == false then |
