-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmake.lua
More file actions
164 lines (156 loc) · 4.75 KB
/
xmake.lua
File metadata and controls
164 lines (156 loc) · 4.75 KB
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
164
add_rules("mode.debug", "mode.release")
if is_plat("windows") then
set_toolchains("msvc")
if not has_config("vs_runtime") then
set_runtimes("MD")
end
else
set_toolchains("clang")
end
option("kind")
set_default("static")
set_values("static", "shared")
set_showmenu(true)
option_end()
option("enable_test")
set_default(false)
set_values(true, false)
set_showmenu(true)
option_end()
target("jsonc")
set_kind("$(kind)")
set_languages("c++23")
if is_config("kind", "shared") then
set_prefixname("lib")
add_defines("_JSONC_EXPORT")
end
add_includedirs("include")
add_files("src/**.cpp")
if is_mode("debug") then
set_symbols("debug")
else
set_optimize("aggressive")
set_strip("all")
end
if is_plat("windows") then
add_defines(
"NOMINMAX",
"UNICODE"
)
add_cxflags(
"/EHs-c-",
"/utf-8",
"/W4",
"/GR-"
)
set_exceptions("none")
if is_mode("release") then
add_cxflags(
"/O2",
"/Ob3"
)
end
if is_config("kind", "shared") then
add_cxflags("/GL")
add_shflags("/LGCT")
end
else
add_cxflags(
"-Wall",
"-Wextra",
"-Wconversion",
"-pedantic",
"-fno-exceptions",
"-fPIC",
"-stdlib=libc++",
"-fno-rtti"
)
if is_mode("release") then
add_cxflags(
"-O3"
)
end
if is_config("kind", "shared") then
set_policy("build.optimization.lto", true)
add_cxflags(
"-fvisibility=hidden",
"-fvisibility-inlines-hidden"
)
if is_plat("linux") then
add_shflags(
"-static-libstdc++",
"-static-libgcc",
"-Wl,--no-undefined",
"-Wl,--exclude-libs,ALL"
)
add_syslinks("libc++.a", "pthread")
end
if is_plat("macosx") then
add_shflags("-dynamiclib")
end
end
end
if is_config("kind", "shared") then
after_build(function (target)
local plat = target:plat()
local arch = target:arch()
local name = target:name()
if arch == "x64" then
arch = "x86_64" -- Fix arch name on Windows
end
local target_file = target:targetfile()
local filename = path.filename(target_file)
local output_dir = path.join(os.projectdir(), "bin/" .. name .. "-" .. plat .. "-" .. arch)
os.mkdir(output_dir)
local artifact_dir = path.join(os.projectdir(), "artifacts")
os.mkdir(artifact_dir)
os.cp(target_file, output_dir)
if plat == "macosx" then -- Fix rpath on MacOS
os.run("install_name_tool -id @rpath/" .. filename .. " " .. path.join(output_dir, filename))
end
local zip_file = path.join(os.projectdir(), "bin/" .. name .. "-" .. plat .. "-" .. arch .. ".zip")
os.rm(zip_file)
if plat == "windows" then
local win_src = output_dir:gsub("/", "\\")
local win_dest = zip_file:gsub("/", "\\")
local command = string.format(
'powershell -Command "Compress-Archive -Path \'%s\\*\' -DestinationPath \'%s\'"',
win_src,
win_dest
)
os.exec(command)
else
os.exec("zip -rj -q '%s' '%s'", zip_file, output_dir)
end
os.mv(zip_file, artifact_dir)
cprint("${bright green}[Shared Library]: ${reset}".. filename .. " already generated to " .. output_dir)
end)
end
if is_config("enable_test", true) then
target("test")
set_kind("binary")
set_languages("c++23")
add_includedirs(
"include",
"test"
)
add_files("test/**.cpp")
add_defines("JSONC_USE_EXPECTED")
if is_plat("windows") then
add_defines(
"NOMINMAX",
"UNICODE"
)
add_cxflags("/utf-8", "/W4")
else
add_cxflags("-Wall", "-Wextra", "-stdlib=libc++")
add_syslinks("c++")
end
after_build(function (target)
local file = target:targetfile()
local output_dir = path.join(os.projectdir(), "bin")
os.mkdir(output_dir)
os.cp(file, output_dir)
cprint("${bright green}[Shared Library]: ${reset}Shared Library file already generated to " .. output_dir)
end)
end