-
Notifications
You must be signed in to change notification settings - Fork 103
/
premake5.lua
238 lines (191 loc) · 6.34 KB
/
premake5.lua
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
newoption { trigger = "verbose", description = "Build efsw with verbose mode." }
newoption { trigger = "strip-symbols", description = "Strip debugging symbols in other file ( only for relwithdbginfo configuration )." }
newoption { trigger = "thread-sanitizer", description ="Compile with ThreadSanitizer" }
efsw_major_version = "1"
efsw_minor_version = "0"
efsw_patch_version = "2"
efsw_version = efsw_major_version .. "." .. efsw_minor_version .. "." .. efsw_patch_version
function get_include_paths()
local function _insert_include_paths( file )
local function _trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
local paths = { }
local lines = file:read('*all')
for line in string.gmatch(lines, '([^\n]+)')
do
table.insert( paths, _trim( line ) )
end
file:close()
return paths
end
local file = io.popen( "echo | gcc -Wp,-v -x c++ - -fsyntax-only 2>&1 | grep -v '#' | grep '/'", 'r' )
local include_paths = _insert_include_paths( file )
if next(include_paths) == nil then
file = io.popen( "echo | clang++ -Wp,-v -x c++ - -fsyntax-only 2>&1 | grep -v '#' | grep '/' | grep -v 'nonexistent'", 'r' )
include_paths = _insert_include_paths( file )
if next(include_paths) == nil then
table.insert( include_paths, "/usr/include" )
table.insert( include_paths, "/usr/local/include" )
end
end
return include_paths
end
function inotify_header_exists()
local efsw_include_paths = get_include_paths()
for _,v in pairs( efsw_include_paths )
do
local cur_path = v .. "/sys/inotify.h"
if os.isfile( cur_path ) then
return true
end
end
return false
end
function string.starts(String,Start)
if ( _ACTION ) then
return string.sub(String,1,string.len(Start))==Start
end
return false
end
function is_vs()
return ( string.starts(_ACTION,"vs") )
end
function conf_warnings()
if not is_vs() then
buildoptions{ "-Wall -Wno-long-long" }
if not os.istarget("windows") then
buildoptions{ "-fPIC" }
end
else
defines { "_SCL_SECURE_NO_WARNINGS" }
end
if _OPTIONS["thread-sanitizer"] then
buildoptions { "-fsanitize=thread" }
linkoptions { "-fsanitize=thread" }
if not os.istarget("macosx") then
links { "tsan" }
end
end
end
function conf_links()
if not os.istarget("windows") and not os.istarget("haiku") then
links { "pthread" }
end
if os.istarget("macosx") then
links { "CoreFoundation.framework", "CoreServices.framework" }
end
end
function conf_excludes()
if os.istarget("windows") then
excludes { "src/efsw/WatcherKqueue.cpp", "src/efsw/WatcherFSEvents.cpp", "src/efsw/WatcherInotify.cpp", "src/efsw/FileWatcherKqueue.cpp", "src/efsw/FileWatcherInotify.cpp", "src/efsw/FileWatcherFSEvents.cpp" }
elseif os.istarget("linux") then
excludes { "src/efsw/WatcherKqueue.cpp", "src/efsw/WatcherFSEvents.cpp", "src/efsw/WatcherWin32.cpp", "src/efsw/FileWatcherKqueue.cpp", "src/efsw/FileWatcherWin32.cpp", "src/efsw/FileWatcherFSEvents.cpp" }
elseif os.istarget("macosx") then
excludes { "src/efsw/WatcherInotify.cpp", "src/efsw/WatcherWin32.cpp", "src/efsw/FileWatcherInotify.cpp", "src/efsw/FileWatcherWin32.cpp" }
elseif os.istarget("bsd") then
excludes { "src/efsw/WatcherInotify.cpp", "src/efsw/WatcherWin32.cpp", "src/efsw/WatcherFSEvents.cpp", "src/efsw/FileWatcherInotify.cpp", "src/efsw/FileWatcherWin32.cpp", "src/efsw/FileWatcherFSEvents.cpp" }
end
if os.istarget("linux") and not inotify_header_exists() then
defines { "EFSW_INOTIFY_NOSYS" }
end
end
workspace "efsw"
location("./make/" .. os.target() .. "/")
targetdir("./bin")
configurations { "debug", "release", "relwithdbginfo" }
platforms { "x86_64", "x86", "ARM", "ARM64" }
if os.istarget("windows") then
osfiles = "src/efsw/platform/win/*.cpp"
else
osfiles = "src/efsw/platform/posix/*.cpp"
end
-- Activates verbose mode
if _OPTIONS["verbose"] then
defines { "EFSW_VERBOSE" }
end
cppdialect "C++11"
objdir("obj/" .. os.target() .. "/")
filter "platforms:x86"
architecture "x86"
filter "platforms:x86_64"
architecture "x86_64"
filter "platforms:arm"
architecture "ARM"
filter "platforms:arm64"
architecture "ARM64"
project "efsw-static-lib"
kind "StaticLib"
language "C++"
targetdir("./lib")
includedirs { "include", "src" }
files { "src/efsw/*.cpp", osfiles }
conf_excludes()
filter "configurations:debug"
defines { "DEBUG" }
symbols "On"
targetname "efsw-static-debug"
conf_warnings()
filter "configurations:release"
defines { "NDEBUG" }
optimize "On"
targetname "efsw-static-release"
conf_warnings()
filter "configurations:relwithdbginfo"
defines { "NDEBUG" }
symbols "On"
optimize "On"
targetname "efsw-static-reldbginfo"
conf_warnings()
project "efsw-test"
kind "ConsoleApp"
language "C++"
links { "efsw-static-lib" }
files { "src/test/*.cpp" }
includedirs { "include", "src" }
conf_links()
filter "configurations:debug"
defines { "DEBUG" }
symbols "On"
targetname "efsw-test-debug"
conf_warnings()
filter "configurations:release"
defines { "NDEBUG" }
optimize "On"
targetname "efsw-test-release"
conf_warnings()
filter "configurations:relwithdbginfo"
defines { "NDEBUG" }
symbols "On"
optimize "On"
targetname "efsw-test-reldbginfo"
conf_warnings()
project "efsw-shared-lib"
kind "SharedLib"
language "C++"
targetdir("./lib")
includedirs { "include", "src" }
files { "src/efsw/*.cpp", osfiles }
defines { "EFSW_DYNAMIC", "EFSW_EXPORTS" }
conf_excludes()
conf_links()
filter "configurations:debug"
defines { "DEBUG" }
symbols "On"
targetname "efsw-debug"
conf_warnings()
filter "configurations:release"
defines { "NDEBUG" }
optimize "On"
targetname "efsw"
conf_warnings()
filter "configurations:relwithdbginfo"
defines { "NDEBUG" }
symbols "On"
optimize "On"
targetname "efsw"
conf_warnings()
if os.istarget("linux") or os.istarget("bsd") or os.istarget("haiku") then
targetextension ( ".so." .. efsw_version )
postbuildcommands { "sh ../../project/build.reldbginfo.sh " .. efsw_major_version .. " " .. efsw_minor_version .. " " .. efsw_patch_version .. " " .. iif( _OPTIONS["strip-symbols"], "strip-symbols", "" ) }
end