1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
--!A cross-toolchain 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, Xmake Open Source Community.
--
-- @author ruki
-- @file load.lua
--
-- imports
import("private.utils.toolchain", {alias = "toolchain_utils"})
-- set toolset programs from xcode toolchain bindir/arch/appledev
function _set_toolset(toolchain, appledev)
local bindir = toolchain:bindir()
local arch = toolchain:arch()
local xc_clang = bindir and path.join(bindir, "clang") or "clang"
local xc_clangxx = bindir and path.join(bindir, "clang++") or "clang++"
local xc_ar = bindir and path.join(bindir, "ar") or "ar"
local xc_strip = bindir and path.join(bindir, "strip") or "strip"
local xc_swift_frontend = bindir and path.join(bindir, "swift-frontend") or "swift-frontend"
local xc_swiftc = bindir and path.join(bindir, "swiftc") or "swiftc"
local xc_dsymutil = bindir and path.join(bindir, "dsymutil") or "dsymutil"
toolchain:set("toolset", "cc", xc_clang)
toolchain:set("toolset", "cxx", xc_clangxx, xc_clang)
toolchain:set("toolset", "ld", xc_clangxx, xc_clang)
toolchain:set("toolset", "sh", xc_clangxx, xc_clang)
toolchain:set("toolset", "ar", xc_ar)
toolchain:set("toolset", "strip", xc_strip)
toolchain:set("toolset", "dsymutil", xc_dsymutil, "dsymutil")
toolchain:set("toolset", "mm", xc_clang)
toolchain:set("toolset", "mxx", xc_clangxx, xc_clang)
toolchain:set("toolset", "sc", xc_swift_frontend, "swift_frontend", xc_swiftc, "swiftc")
toolchain:set("toolset", "scld", xc_swiftc, "swiftc")
toolchain:set("toolset", "scsh", xc_swiftc, "swiftc")
toolchain:set("toolset", "scar", xc_swiftc, "swiftc")
if arch then
toolchain:set("toolset", "cpp", xc_clang .. " -arch " .. arch .. " -E")
end
if toolchain:is_plat("macosx") then
toolchain:set("toolset", "as", xc_clang)
elseif appledev == "simulator" or appledev == "catalyst" then
toolchain:set("toolset", "as", xc_clang)
else
toolchain:set("toolset", "as", path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. xc_clang))
end
end
-- add platform-independent flags for xcode toolchain
function _add_common_flags(toolchain, xcode_sysroot)
-- init target triple flags
local targetflag = {"-target", toolchain_utils.get_xcode_target_triple(toolchain)}
-- init flags for c/c++
toolchain:add("cxflags", targetflag, "-isysroot", xcode_sysroot)
if toolchain:is_plat("macosx") then
toolchain:add("ldflags", targetflag, "-isysroot", xcode_sysroot, "-lz")
toolchain:add("shflags", targetflag, "-isysroot", xcode_sysroot, "-lz")
else
toolchain:add("ldflags", targetflag, "-isysroot", xcode_sysroot, "-ObjC", "-fobjc-link-runtime")
toolchain:add("shflags", targetflag, "-isysroot", xcode_sysroot, "-ObjC", "-fobjc-link-runtime")
end
-- init flags for objc/c++
toolchain:add("mxflags", targetflag, "-isysroot", xcode_sysroot)
-- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua
toolchain:add("mxflags", "-fobjc-arc")
-- init flags for asm
toolchain:add("asflags", targetflag, "-isysroot", xcode_sysroot)
-- init flags for swift
toolchain:add("scflags", {"-sdk", xcode_sysroot}, targetflag)
toolchain:add("scshflags", {"-sdk", xcode_sysroot}, targetflag, "-emit-library")
toolchain:add("scarflags", {"-sdk", xcode_sysroot}, targetflag, "-emit-library", "-static")
toolchain:add("scldflags", {"-sdk", xcode_sysroot}, targetflag, "-emit-executable")
end
-- add extra headers/libs/frameworks for catalyst (macosx + appledev=catalyst)
function _add_catalyst_support(toolchain, xcode_sysroot)
toolchain:add("cxflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
toolchain:add("mxflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
toolchain:add("asflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
toolchain:add("ldflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
toolchain:add("shflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
toolchain:add("scflags", {"-I", path.join(xcode_sysroot, "System/iOSSupport/usr/include")})
toolchain:add("scldflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
toolchain:add("scshflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
toolchain:add("scarflags", {"-L", path.join(xcode_sysroot, "System/iOSSupport/usr/lib")})
toolchain:add("cxflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("mxflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("asflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("ldflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("shflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("scflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("scshflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("scarflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
toolchain:add("scldflags", {"-iframework", path.join(xcode_sysroot, "System/iOSSupport/System/Library/Frameworks")})
end
-- main entry
function main(toolchain)
local appledev = toolchain:config("appledev")
local xcode_sysroot = toolchain:config("xcode_sysroot")
if toolchain:is_plat("macosx") then
assert(appledev ~= "simulator")
end
-- init toolset
_set_toolset(toolchain, appledev)
-- init flags
_add_common_flags(toolchain, xcode_sysroot)
-- init extra flags for catalyst
if toolchain:is_plat("macosx") and xcode_sysroot and appledev == "catalyst" then
_add_catalyst_support(toolchain, xcode_sysroot)
end
end
|