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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
--!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 check.lua
--
-- imports
import("core.base.option")
import("core.project.config")
import("detect.sdks.find_xcode")
import("private.utils.executable_path")
-- main entry
function main(toolchain)
-- get apple device
local simulator
local appledev = toolchain:config("appledev") or config.get("appledev")
if appledev and appledev == "simulator" then
simulator = true
appledev = "simulator"
elseif not toolchain:is_plat("macosx") and toolchain:is_arch("i386", "x86_64") then
simulator = true
appledev = "simulator"
end
-- find xcode
local xcode_sdkver = toolchain:config("xcode_sdkver") or config.get("xcode_sdkver")
local xcode = find_xcode(config.get("xcode"), {force = true, verbose = true,
find_codesign = toolchain:is_global(),
sdkver = xcode_sdkver,
appledev = appledev,
plat = toolchain:plat(),
arch = toolchain:arch()})
if not xcode then
cprint("checking for Xcode directory ... ${color.nothing}${text.nothing}")
return false
end
-- xcode found
xcode_sdkver = xcode.sdkver
if toolchain:is_global() then
config.set("xcode", xcode.sdkdir, {force = true, readonly = true})
config.set("xcode_mobile_provision", xcode.mobile_provision, {force = true, readonly = true})
config.set("xcode_codesign_identity", xcode.codesign_identity, {force = true, readonly = true})
if xcode.sdkdir then
cprint("checking for Xcode directory ... ${color.success}%s", xcode.sdkdir)
else
cprint("checking for Xcode directory ... ${color.nothing}${text.nothing}")
end
if option.get("verbose") then
if xcode.codesign_identity then
cprint("checking for Codesign Identity of Xcode ... ${color.success}%s", xcode.codesign_identity)
else
cprint("checking for Codesign Identity of Xcode ... ${color.nothing}${text.nothing}")
end
if toolchain:is_plat("iphoneos") then
if xcode.mobile_provision then
cprint("checking for Mobile Provision of Xcode ... ${color.success}%s", xcode.mobile_provision)
else
cprint("checking for Mobile Provision of Xcode ... ${color.nothing}${text.nothing}")
end
end
end
end
-- get xcode bin directory
local cross
if xcode.sdkdir and os.isdir(xcode.sdkdir) then
local bindir = path.join(xcode.sdkdir, "Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin")
toolchain:config_set("bindir", bindir)
else
if toolchain:is_plat("macosx") then
cross = "xcrun -sdk macosx "
elseif toolchain:is_plat("iphoneos") then
cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos "
elseif toolchain:is_plat("watchos") then
cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos "
elseif toolchain:is_plat("appletvos") then
cross = simulator and "xcrun -sdk appletvsimulator " or "xcrun -sdk appletvos "
elseif toolchain:is_plat("applexros") then
cross = simulator and "xcrun -sdk xrsimulator " or "xcrun -sdk xros "
else
raise("unknown platform for xcode!")
end
local xc_clang = executable_path(cross .. "clang")
if xc_clang then
toolchain:config_set("bindir", path.directory(xc_clang))
end
end
-- save xcode sysroot directory
local xcode_sysroot
if xcode.sdkdir and xcode_sdkver then
if toolchain:is_plat("macosx") then
xcode_sysroot = xcode.sdkdir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk"
elseif toolchain:is_plat("iphoneos") then
local platname = simulator and "iPhoneSimulator" or "iPhoneOS"
xcode_sysroot = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode.sdkdir, platname, platname, xcode_sdkver)
elseif toolchain:is_plat("watchos") then
local platname = simulator and "WatchSimulator" or "WatchOS"
xcode_sysroot = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode.sdkdir, platname, platname, xcode_sdkver)
elseif toolchain:is_plat("appletvos") then
local platname = simulator and "AppleTVSimulator" or "AppleTVOS"
xcode_sysroot = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode.sdkdir, platname, platname, xcode_sdkver)
elseif toolchain:is_plat("applexros") then
local platname = simulator and "XRSimulator" or "XROS"
xcode_sysroot = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode.sdkdir, platname, platname, xcode_sdkver)
end
else
-- maybe it is from CommandLineTools, e.g. /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
-- @see https://github.com/xmake-io/xmake/issues/3686
local sdkpath = try { function () return os.iorun(cross .. "--show-sdk-path") end }
if sdkpath then
xcode_sysroot = sdkpath:trim()
end
end
if xcode_sysroot then
toolchain:config_set("xcode_sysroot", xcode_sysroot)
end
toolchain:config_set("simulator", simulator)
-- save target minver
--
-- @note we need to differentiate the version for the system,
-- because the xcode toolchain of iphoneos/macosx may need to be used at the same time.
--
-- e.g.
--
-- target("test")
-- set_toolchains("xcode", {plat = os.host(), arch = os.arch()})
--
local target_minver = toolchain:config("target_minver") or config.get("target_minver")
if xcode_sdkver and not target_minver then
target_minver = xcode.target_minver
end
toolchain:config_set("xcode", xcode.sdkdir)
toolchain:config_set("xcode_sdkver", xcode_sdkver)
toolchain:config_set("target_minver", target_minver)
toolchain:config_set("appledev", appledev)
toolchain:configs_save()
if xcode_sdkver then
cprint("checking for SDK version of Xcode for %s (%s) ... ${color.success}%s", toolchain:plat(), toolchain:arch(), xcode_sdkver)
end
if target_minver then
cprint("checking for Minimal target version of Xcode for %s (%s) ... ${color.success}%s", toolchain:plat(), toolchain:arch(), target_minver)
end
return true
end
|