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
|
--
-- swift.lua
-- Provides Swift-specific configuration strings.
--
premake.swift = { }
--
-- Set default tools
--
premake.swift.swiftc = "swiftc"
premake.swift.swift = "swift"
premake.swift.cc = "gcc"
premake.swift.ar = "ar"
premake.swift.ld = "ld"
premake.swift.dsymutil = "dsymutil"
--
-- Translation of Premake flags into Swift flags
--
local swiftcflags =
{
Symbols = "-g", -- Produce debug information
DisableWarnings = "--suppress-warnings", -- Disable warnings
FatalWarnings = "--warnings-as-errors", -- Treat warnings as fatal
Optimize = "-O -whole-module-optimization",
OptimizeSize = "-O -whole-module-optimization",
OptimizeSpeed = "-Ounchecked -whole-module-optimization",
MinimumWarnings = "-minimum-warnings",
}
local swiftlinkflags = {
StaticRuntime = "-static-stdlib",
}
premake.swift.platforms = {
Native = {
swiftcflags = "",
swiftlinkflags = "",
},
x64 = {
swiftcflags = "",
swiftlinkflags = "",
}
}
local platforms = premake.swift.platforms
--
-- Returns a list of compiler flags, based on the supplied configuration.
--
function premake.swift.get_sdk_path(cfg)
return string.trim(os.outputof("xcrun --show-sdk-path"))
end
function premake.swift.get_sdk_platform_path(cfg)
return string.trim(os.outputof("xcrun --show-sdk-platform-path"))
end
function premake.swift.get_toolchain_path(cfg)
return string.trim(os.outputof("xcode-select -p")) .. "/Toolchains/XcodeDefault.xctoolchain"
end
function premake.swift.gettarget(cfg)
return "-target x86_64-apple-macosx10.11"
end
function premake.swift.getswiftcflags(cfg)
local result = table.translate(cfg.flags, swiftcflags)
table.insert(result, platforms[cfg.platform].swiftcflags)
result = table.join(result, cfg.buildoptions_swift)
if cfg.kind == "SharedLib" or cfg.kind == "StaticLib" then
table.insert(result, "-parse-as-library")
end
table.insert(result, premake.swift.gettarget(cfg))
return result
end
function premake.swift.getswiftlinkflags(cfg)
local result = table.translate(cfg.flags, swiftlinkflags)
table.insert(result, platforms[cfg.platform].swiftlinkflags)
result = table.join(result, cfg.linkoptions_swift)
if cfg.kind == "SharedLib" or cfg.kind == "StaticLib" then
table.insert(result, "-emit-library")
else
table.insert(result, "-emit-executable")
end
table.insert(result, premake.swift.gettarget(cfg))
return result
end
function premake.swift.getmodulemaps(cfg)
local maps = {}
if next(cfg.swiftmodulemaps) then
for _, mod in ipairs(cfg.swiftmodulemaps) do
table.insert(maps, string.format("-Xcc -fmodule-map-file=%s", mod))
end
end
return maps
end
function premake.swift.getlibdirflags(cfg)
return premake.gcc.getlibdirflags(cfg)
end
function premake.swift.getldflags(cfg)
local result = { platforms[cfg.platform].ldflags }
local links = premake.getlinks(cfg, "siblings", "basename")
for _,v in ipairs(links) do
if path.getextension(v) == ".framework" then
table.insert(result, "-framework "..v)
else
table.insert(result, "-l"..v)
end
end
return result
end
function premake.swift.getlinkflags(cfg)
return premake.gcc.getlinkflags(cfg)
end
function premake.swift.getarchiveflags(cfg)
return ""
end
|