summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-04 13:01:11 +0800
committerruki <[email protected]>2020-04-04 13:04:06 +0800
commitdadee422f340ce6e96a7adbd64aa3941a2d31707 (patch)
tree899503fb7a2625eaaf12945259d809c3af684735
parentcc80eac1312bc54f4d6564f2a517a86aeccf5e8d (diff)
improve objc/objc++ build rules
-rw-r--r--tests/projects/objc++/console/xmake.lua10
-rw-r--r--tests/projects/objc/bundle/src/main.m11
-rw-r--r--tests/projects/objc/bundle/src/test.h3
-rw-r--r--tests/projects/objc/bundle/src/test.m6
-rw-r--r--tests/projects/objc/bundle/xmake.lua22
-rw-r--r--tests/projects/objc/console/xmake.lua10
-rw-r--r--tests/projects/objc/framework/src/main.m11
-rw-r--r--tests/projects/objc/framework/src/test.h3
-rw-r--r--tests/projects/objc/framework/src/test.m6
-rw-r--r--tests/projects/objc/framework/xmake.lua15
-rw-r--r--xmake/rules/objc++/xmake.lua20
-rw-r--r--xmake/templates/objc++/console/project/xmake.lua8
-rw-r--r--xmake/templates/objc/console/project/xmake.lua8
13 files changed, 97 insertions, 36 deletions
diff --git a/tests/projects/objc++/console/xmake.lua b/tests/projects/objc++/console/xmake.lua
index d701c3723..f47df3288 100644
--- a/tests/projects/objc++/console/xmake.lua
+++ b/tests/projects/objc++/console/xmake.lua
@@ -1,16 +1,6 @@
-- add rules
add_rules("mode.debug", "mode.release")
--- add frameworks
-add_frameworks("Foundation", "CoreFoundation")
-
--- for macosx or ios
-if is_os("macosx", "ios") then
-
- -- enable arc?
- add_mxflags("-fobjc-arc")
-end
-
-- add target
target("console_objc++")
diff --git a/tests/projects/objc/bundle/src/main.m b/tests/projects/objc/bundle/src/main.m
new file mode 100644
index 000000000..e3fa72dbf
--- /dev/null
+++ b/tests/projects/objc/bundle/src/main.m
@@ -0,0 +1,11 @@
+#import <Foundation/Foundation.h>
+#import <test/test.h>
+
+int main(int argc, char** argv)
+{
+ @autoreleasepool
+ {
+ NSLog(@"add(1, 2): %d", add(1, 2));
+ }
+ return 0;
+}
diff --git a/tests/projects/objc/bundle/src/test.h b/tests/projects/objc/bundle/src/test.h
new file mode 100644
index 000000000..d882546d1
--- /dev/null
+++ b/tests/projects/objc/bundle/src/test.h
@@ -0,0 +1,3 @@
+#import <Foundation/Foundation.h>
+
+FOUNDATION_EXPORT int add(int a, int b);
diff --git a/tests/projects/objc/bundle/src/test.m b/tests/projects/objc/bundle/src/test.m
new file mode 100644
index 000000000..84422f6a7
--- /dev/null
+++ b/tests/projects/objc/bundle/src/test.m
@@ -0,0 +1,6 @@
+#include "test.h"
+
+int add(int a, int b)
+{
+ return a + b;
+}
diff --git a/tests/projects/objc/bundle/xmake.lua b/tests/projects/objc/bundle/xmake.lua
new file mode 100644
index 000000000..5073b3b0f
--- /dev/null
+++ b/tests/projects/objc/bundle/xmake.lua
@@ -0,0 +1,22 @@
+-- add rules
+add_rules("mode.debug", "mode.release")
+
+-- add frameworks
+add_frameworks("Foundation", "CoreFoundation")
+
+-- for macosx or ios
+if is_os("macosx", "ios") then
+
+ -- enable arc?
+ add_mxflags("-fobjc-arc")
+end
+
+-- add target
+target("console_objc")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add files
+ add_files("src/*.m")
+
diff --git a/tests/projects/objc/console/xmake.lua b/tests/projects/objc/console/xmake.lua
index 5073b3b0f..23686095e 100644
--- a/tests/projects/objc/console/xmake.lua
+++ b/tests/projects/objc/console/xmake.lua
@@ -1,16 +1,6 @@
-- add rules
add_rules("mode.debug", "mode.release")
--- add frameworks
-add_frameworks("Foundation", "CoreFoundation")
-
--- for macosx or ios
-if is_os("macosx", "ios") then
-
- -- enable arc?
- add_mxflags("-fobjc-arc")
-end
-
-- add target
target("console_objc")
diff --git a/tests/projects/objc/framework/src/main.m b/tests/projects/objc/framework/src/main.m
new file mode 100644
index 000000000..e3fa72dbf
--- /dev/null
+++ b/tests/projects/objc/framework/src/main.m
@@ -0,0 +1,11 @@
+#import <Foundation/Foundation.h>
+#import <test/test.h>
+
+int main(int argc, char** argv)
+{
+ @autoreleasepool
+ {
+ NSLog(@"add(1, 2): %d", add(1, 2));
+ }
+ return 0;
+}
diff --git a/tests/projects/objc/framework/src/test.h b/tests/projects/objc/framework/src/test.h
new file mode 100644
index 000000000..d882546d1
--- /dev/null
+++ b/tests/projects/objc/framework/src/test.h
@@ -0,0 +1,3 @@
+#import <Foundation/Foundation.h>
+
+FOUNDATION_EXPORT int add(int a, int b);
diff --git a/tests/projects/objc/framework/src/test.m b/tests/projects/objc/framework/src/test.m
new file mode 100644
index 000000000..84422f6a7
--- /dev/null
+++ b/tests/projects/objc/framework/src/test.m
@@ -0,0 +1,6 @@
+#include "test.h"
+
+int add(int a, int b)
+{
+ return a + b;
+}
diff --git a/tests/projects/objc/framework/xmake.lua b/tests/projects/objc/framework/xmake.lua
new file mode 100644
index 000000000..2e1de864c
--- /dev/null
+++ b/tests/projects/objc/framework/xmake.lua
@@ -0,0 +1,15 @@
+add_rules("mode.debug", "mode.release")
+add_frameworks("Foundation", "CoreFoundation")
+
+if is_os("macosx", "ios") then
+ add_mxflags("-fobjc-arc")
+end
+
+target("test")
+ set_kind("shared")
+ add_files("src/test.m")
+
+target("demo")
+ set_kind("binary")
+ add_deps("test")
+ add_files("src/main.m")
diff --git a/xmake/rules/objc++/xmake.lua b/xmake/rules/objc++/xmake.lua
index 248745b86..61cb590bc 100644
--- a/xmake/rules/objc++/xmake.lua
+++ b/xmake/rules/objc++/xmake.lua
@@ -22,12 +22,32 @@
rule("objc.build")
set_sourcekinds("mm")
add_deps("c.build.pcheader")
+ after_load(function (target)
+ if target:values("objc.build.arc") ~= false then
+ target:add("mflags", "-fobjc-arc")
+ else
+ target:add("mflags", "-fno-objc-arc")
+ end
+ if is_plat("macosx", "iphoneos", "watchos") then
+ target:add("frameworks", "Foundation", "CoreFoundation")
+ end
+ end)
on_build_files("private.action.build.object", {batch = true})
-- define rule: objc++.build
rule("objc++.build")
set_sourcekinds("mxx")
add_deps("c++.build.pcheader")
+ after_load(function (target)
+ if target:values("objc++.build.arc") ~= false then
+ target:add("mxxflags", "-fobjc-arc")
+ else
+ target:add("mxxflags", "-fno-objc-arc")
+ end
+ if is_plat("macosx", "iphoneos", "watchos") then
+ target:add("frameworks", "Foundation", "CoreFoundation")
+ end
+ end)
on_build_files("private.action.build.object", {batch = true})
-- define rule: objc
diff --git a/xmake/templates/objc++/console/project/xmake.lua b/xmake/templates/objc++/console/project/xmake.lua
index dda69c1f7..f99120596 100644
--- a/xmake/templates/objc++/console/project/xmake.lua
+++ b/xmake/templates/objc++/console/project/xmake.lua
@@ -10,12 +10,4 @@ target("${TARGETNAME}")
-- add files
add_files("src/*.mm")
- -- for macosx or ios
- if is_os("macosx", "ios") then
- add_mxflags("-fobjc-arc")
- end
-
- -- add frameworks
- add_frameworks("Foundation", "CoreFoundation")
-
${FAQ}
diff --git a/xmake/templates/objc/console/project/xmake.lua b/xmake/templates/objc/console/project/xmake.lua
index 9658f9486..75496210f 100644
--- a/xmake/templates/objc/console/project/xmake.lua
+++ b/xmake/templates/objc/console/project/xmake.lua
@@ -10,12 +10,4 @@ target("${TARGETNAME}")
-- add files
add_files("src/*.m")
- -- add frameworks
- add_frameworks("Foundation", "CoreFoundation")
-
- -- for macosx or ios
- if is_os("macosx", "ios") then
- add_mxflags("-fobjc-arc")
- end
-
${FAQ}