-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmake.lua
More file actions
87 lines (76 loc) · 2.96 KB
/
xmake.lua
File metadata and controls
87 lines (76 loc) · 2.96 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
-- luajit in xmake repo does not support mingw/x86_64
-- so when mingw, use lua instead
local luadist = is_plat('mingw') and 'lua' or 'luajit'
add_requires(luadist)
rule('copy')
after_build(function(target)
-- try kill keymod if running
try {
function()
os.run('taskkill.exe /im '.. target:filename() .. ' /F')
print('ensure keymod.exe killed before build done!')
end
} catch {}
local prjoutput = path.join(target:targetdir(), target:filename())
print("copy " .. prjoutput .. " to $(projectdir)")
os.trycp(prjoutput, "$(projectdir)")
end)
rule('build_flags')
before_build(function(target)
if is_plat('mingw') then
target:add('ldflags', '-municode -static-libgcc -static-libstdc++ -static', {force=true})
target:add("cxflags", "-O2")
elseif is_plat('windows') then
target:add("cxflags", "/utf-8 /O2")
end
end)
target('keymod')
set_kind('binary')
set_languages('c++17')
add_files('./src/main.cpp', "src/trayicon.cpp","./src/keymod.rc")
add_packages(luadist)
add_defines('MAKE_LIB', 'UNICODE', "_WIN32_WINNT=0x0603")
add_links( "user32", "gdi32", "shell32", "ole32")
add_rules('copy', 'build_flags')
local version_major = "0"
local version_minor = "0"
local version_patch = "1"
on_load(function(target)
import("core.base.text")
local rc_template = path.join(os.projectdir(), "src/keymod.rc.in")
local rc_output = path.join(os.projectdir(), "src/keymod.rc")
local function generate_rc()
local content = io.readfile(rc_template)
content = content:gsub("${VERSION_MAJOR}", version_major)
content = content:gsub("${VERSION_MINOR}", version_minor)
content = content:gsub("${VERSION_PATCH}", version_patch)
content = content:gsub("${FILE_DESCRIPTION}", "keymod powered by " .. luadist)
-- if git command failed, commit_id fallback to '0'
local commit_id = '0'
try { function() commit_id = os.iorun("git rev-parse --short HEAD"):gsub("\n", "") end } catch {}
content = content:gsub("${TAG_SUFFIX}", commit_id)
io.writefile(rc_output, content)
end
local function check_version()
local rc = io.readfile(rc_output)
local commit_id = '0'
-- if git command failed, commit_id fallback to '0'
try { function() commit_id = os.iorun("git rev-parse --short HEAD"):gsub("\n", "") end } catch {}
local version_str = version_major..'.'..version_minor..'.'..version_patch..'.'..commit_id
return string.find(rc, version_str)
end
-- no rc file, or version info not match
if not os.isfile(rc_output) or not check_version() then
print("generate new rc file: " .. rc_output)
generate_rc()
end
end)
target('popup')
set_kind('shared')
set_languages('c++17')
add_files('./src/popup.cpp')
add_packages(luadist)
add_defines('MAKE_LIB', 'UNICODE', "_WIN32_WINNT=0x0603")
add_links( "user32", "shell32", "ole32", "gdi32")
set_filename("popup.dll")
add_rules('copy', 'build_flags')