summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-07-04 23:02:05 +0800
committerruki <[email protected]>2023-07-04 23:02:05 +0800
commit6b5f9eca01dfa8cd654014ba537e59a8f2eceeb6 (patch)
tree8a467b656d8eadc481698225e9c2dda1c48df424
parent92f26e98978d36475e49762114fd92c0a2324767 (diff)
add objc pch header support #3912
-rw-r--r--tests/projects/c++/precompiled_header/test.lua3
-rw-r--r--tests/projects/c/precompiled_header/test.lua3
-rw-r--r--tests/projects/objc++/precompiled_header/src/header.h27
-rw-r--r--tests/projects/objc++/precompiled_header/src/header2.h0
-rw-r--r--tests/projects/objc++/precompiled_header/src/main.mm8
-rw-r--r--tests/projects/objc++/precompiled_header/src/test.c4
-rw-r--r--tests/projects/objc++/precompiled_header/src/test.mm8
-rw-r--r--tests/projects/objc++/precompiled_header/src/test2.mm8
-rw-r--r--tests/projects/objc++/precompiled_header/src/test4.mm8
-rw-r--r--tests/projects/objc++/precompiled_header/src/test5.mm8
-rw-r--r--tests/projects/objc++/precompiled_header/src/test6.mm8
-rw-r--r--tests/projects/objc++/precompiled_header/src/test7.mm8
-rw-r--r--tests/projects/objc++/precompiled_header/src/test8.mm8
-rw-r--r--tests/projects/objc++/precompiled_header/test.lua5
-rw-r--r--tests/projects/objc++/precompiled_header/test3.mm8
-rw-r--r--tests/projects/objc++/precompiled_header/xmake.lua8
-rw-r--r--xmake/core/project/target.lua12
-rw-r--r--xmake/languages/objc++/load.lua4
-rw-r--r--xmake/languages/objc++/xmake.lua4
-rw-r--r--xmake/modules/core/tools/gcc.lua31
-rw-r--r--xmake/rules/objc++/precompiled_header/xmake.lua36
-rw-r--r--xmake/rules/objc++/xmake.lua4
22 files changed, 191 insertions, 22 deletions
diff --git a/tests/projects/c++/precompiled_header/test.lua b/tests/projects/c++/precompiled_header/test.lua
index b76241be2..b57362078 100644
--- a/tests/projects/c++/precompiled_header/test.lua
+++ b/tests/projects/c++/precompiled_header/test.lua
@@ -1,6 +1,3 @@
--- main entry
function main(t)
-
- -- build project
t:build()
end
diff --git a/tests/projects/c/precompiled_header/test.lua b/tests/projects/c/precompiled_header/test.lua
index b76241be2..b57362078 100644
--- a/tests/projects/c/precompiled_header/test.lua
+++ b/tests/projects/c/precompiled_header/test.lua
@@ -1,6 +1,3 @@
--- main entry
function main(t)
-
- -- build project
t:build()
end
diff --git a/tests/projects/objc++/precompiled_header/src/header.h b/tests/projects/objc++/precompiled_header/src/header.h
new file mode 100644
index 000000000..affda55ca
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/src/header.h
@@ -0,0 +1,27 @@
+// header.h
+#ifndef HEADER_H
+#define HEADER_H
+
+#include <algorithm>
+#include <deque>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <set>
+//#include <thread>
+#include <utility>
+#include <vector>
+#include <string>
+#include <queue>
+#include <cstdlib>
+#include <utility>
+#include <exception>
+#include <list>
+#include <stack>
+#include <complex>
+#include <fstream>
+#include <cstdio>
+#include <iomanip>
+
+#endif
+
diff --git a/tests/projects/objc++/precompiled_header/src/header2.h b/tests/projects/objc++/precompiled_header/src/header2.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/src/header2.h
diff --git a/tests/projects/objc++/precompiled_header/src/main.mm b/tests/projects/objc++/precompiled_header/src/main.mm
new file mode 100644
index 000000000..27d41ee50
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/src/main.mm
@@ -0,0 +1,8 @@
+#include "header.h"
+
+int main(int argc, char** argv)
+{
+ std::string s("xmake");
+ printf("hello %s!\n", s.c_str());
+ return 0;
+}
diff --git a/tests/projects/objc++/precompiled_header/src/test.c b/tests/projects/objc++/precompiled_header/src/test.c
new file mode 100644
index 000000000..7f0aa2bf4
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/src/test.c
@@ -0,0 +1,4 @@
+
+void test_c(void)
+{
+}
diff --git a/tests/projects/objc++/precompiled_header/src/test.mm b/tests/projects/objc++/precompiled_header/src/test.mm
new file mode 100644
index 000000000..e9d6c83d9
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/src/test.mm
@@ -0,0 +1,8 @@
+
+// main.cpp
+#include "header.h"
+
+int test()
+{
+ return 0;
+}
diff --git a/tests/projects/objc++/precompiled_header/src/test2.mm b/tests/projects/objc++/precompiled_header/src/test2.mm
new file mode 100644
index 000000000..596359cd2
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/src/test2.mm
@@ -0,0 +1,8 @@
+
+// main.cpp
+#include "header.h"
+
+int test2()
+{
+ return 0;
+}
diff --git a/tests/projects/objc++/precompiled_header/src/test4.mm b/tests/projects/objc++/precompiled_header/src/test4.mm
new file mode 100644
index 000000000..a92803eb7
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/src/test4.mm
@@ -0,0 +1,8 @@
+
+// main.cpp
+#include "header.h"
+
+int test4()
+{
+ return 0;
+}
diff --git a/tests/projects/objc++/precompiled_header/src/test5.mm b/tests/projects/objc++/precompiled_header/src/test5.mm
new file mode 100644
index 000000000..2a3e7066c
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/src/test5.mm
@@ -0,0 +1,8 @@
+
+// main.cpp
+#include "header.h"
+
+int test5()
+{
+ return 0;
+}
diff --git a/tests/projects/objc++/precompiled_header/src/test6.mm b/tests/projects/objc++/precompiled_header/src/test6.mm
new file mode 100644
index 000000000..efbd7c6c1
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/src/test6.mm
@@ -0,0 +1,8 @@
+
+// main.cpp
+#include "header.h"
+
+int test6()
+{
+ return 0;
+}
diff --git a/tests/projects/objc++/precompiled_header/src/test7.mm b/tests/projects/objc++/precompiled_header/src/test7.mm
new file mode 100644
index 000000000..24aeff619
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/src/test7.mm
@@ -0,0 +1,8 @@
+
+// main.cpp
+#include "header.h"
+
+int test7()
+{
+ return 0;
+}
diff --git a/tests/projects/objc++/precompiled_header/src/test8.mm b/tests/projects/objc++/precompiled_header/src/test8.mm
new file mode 100644
index 000000000..6ad5680a6
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/src/test8.mm
@@ -0,0 +1,8 @@
+
+// main.cpp
+#include "header.h"
+
+int test8()
+{
+ return 0;
+}
diff --git a/tests/projects/objc++/precompiled_header/test.lua b/tests/projects/objc++/precompiled_header/test.lua
new file mode 100644
index 000000000..d45624c55
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/test.lua
@@ -0,0 +1,5 @@
+function main(t)
+ if is_host("macosx") then
+ t:build()
+ end
+end
diff --git a/tests/projects/objc++/precompiled_header/test3.mm b/tests/projects/objc++/precompiled_header/test3.mm
new file mode 100644
index 000000000..7daf91dd7
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/test3.mm
@@ -0,0 +1,8 @@
+
+#include "src/header.h"
+#include "src/header2.h"
+
+int test3()
+{
+ return 0;
+}
diff --git a/tests/projects/objc++/precompiled_header/xmake.lua b/tests/projects/objc++/precompiled_header/xmake.lua
new file mode 100644
index 000000000..55382962d
--- /dev/null
+++ b/tests/projects/objc++/precompiled_header/xmake.lua
@@ -0,0 +1,8 @@
+add_rules("mode.debug", "mode.release")
+
+target("main")
+ set_kind("binary")
+ set_languages("cxx11")
+ set_pmxxheader("src/header.h")
+ add_files("src/*.mm", "src/*.c", "*.mm")
+
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