generated from ravi688/TemplateRepository
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeson.build
267 lines (241 loc) · 8.3 KB
/
meson.build
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#------------- Generated By Build Master 1.0.0 ------------------
# ------------------------------ DOCUMENTATION ---------------------------------
# Release build
# -------------------------
# $ meson setup --wipe <builddir> # wipe the build artifacts (like object files)
# $ meson setup <builddir> --reconfigure --buildtype=release # reconfigure the build directory for release build
# $ meson compile -C <builddir> # compile the project
#
# Debug build
# -------------------------
# $ meson setup --wipe <buildir> # wipe the build artifacts (like object files)
# $ meson setup <builddir> --reconfigure --buildtype=release # reconfigure the build directory for debug build
# $ meson compile -C <builddir> # compile the project
#
# Static Library
# -------------------------
# $ meson setup --wipe <buildir> # wipe the build artifacts (like object files)
# # NOTE: --buildtype=release or --buildtype=debug options can be added here
# $ meson setup -C <builddir> --reconfigure --default-library=static # reconfigure the build directory for static library
# $ meson compile -C <builddir> # compile the project
# $ meson install -C <builddir> # install the static library
#
# Shared Library
# -------------------------
# $ meson setup --wipe <buildir> # whipe the build artifacts (like object files)
# # NOTE: --buildtype=release or --buildtype=debug options can be added here
# $ meson setup -C <builddir> --reconfigure --default-library=shared # reconfigure the build directory for shared library
# $ meson compile -C <builddir> # compile the project
# $ meson install -C <builddir> # install the shared library
#
# Artifact Installation Directories
# ---------------------------------
# Headers: /include/<ProjectNameInSmallCase>
# Static Libraries: /lib/lib<ProjectNameInSmallCase>.a-
# Shared Libraries: /bin/lib<ProjectNameInSmallCase>.dll
# PkgConfig (.pc) for static library: $PKG_CONFIG_PATH/<ProjectNameInSmallCase>_static.pc
# PkgConfig (.pc) for shared library: $PKG_CONFIG_PATH/<ProjectNameInSmallCase>_shared.pc
#
# -------------------------------- PROJECT CONFIGS -----------------------------
project('BufferLib', 'c', 'cpp',
version : '1.0.0',
meson_version: '>=1.1',
default_options : [
'warning_level=3',
'buildtype=debug',
'c_std=c17',
'cpp_std=c++20'
]
)
# Release Build Defines
release_defines = [
'-DBUF_RELEASE'
]
# Debug Build Defines
debug_defines = [
'-DBUF_DEBUG'
]
# Source files (common to all targets)
sources = files(
'source/buffer.c', 'source/buffer_test.c'
)
# Include directories
inc = include_directories(
'include'
)
# Library Install Directory
lib_install_dir = get_option('libdir')/'bufferlib'
# Dependencies
dependencies = [
dependency('calltrace')
]
# Linker Arguments
windows_link_args = [
]
linux_link_args = [
]
darwin_link_args = [
]
# -------------------------------------------------------------------------------
# ------------------------------ FIXTURE ----------------------------------------
# Compiler configuration
add_project_arguments('-m64', language : 'c')
add_project_arguments('-m64', language : 'cpp')
# Linker configuration
link_args = []
os_name = host_machine.system()
if os_name == 'windows'
link_args += windows_link_args
elif os_name == 'linux'
link_args += linux_link_args
elif os_name == 'darwin'
link_args += darwin_link_args
endif
add_project_link_arguments('-m64', link_args, language : 'c')
add_project_link_arguments('-m64', link_args, language : 'cpp')
# Build type specific defines
build_mode_defines = []
if get_option('buildtype') == 'release'
add_project_arguments(release_defines, language : 'c')
add_project_arguments(release_defines, language : 'cpp')
build_mode_defines += release_defines
else
add_project_arguments(debug_defines, language : 'c')
add_project_arguments(debug_defines, language : 'cpp')
build_mode_defines += debug_defines
endif
# pkg-config package installation
python = find_program('python')
# Try PKG_CONFIG_PATH first, typicallly it succeeds on MINGW64 (MSYS2)
result = run_command(python, '-c', 'import os; print(os.environ["PKG_CONFIG_PATH"])', check : false)
pkgconfig_install_path = ''
if result.returncode() == 0
str = result.stdout()
# Unix
if str.startswith('/')
pkgconfig_install_path = str.replace(';', ':').split(':')[0]
# Windows
else
pkgconfig_install_path = str.split(';')[0]
endif
endif
if pkgconfig_install_path == ''
# Otherwise use pkg-config to query its lookup directories
message('PKG_CONFIG_PATH seems to be empty, trying another method')
result = run_command('pkg-config', '--variable', 'pc_path', 'pkg-config', check : false)
if result.returncode() == 0
str = result.stdout()
if str.startswith('/')
pkgconfig_install_path = str.replace(';', ':').split(':')[0]
else
pkgconfig_install_path = str.split(';')[0]
endif
# Finally if the above attempts fail, use 'libdir' value
else
pkgconfig_install_path = get_option('libdir')
endif
endif
message('pkg config path: ' + pkgconfig_install_path)
#-------------------------------------------------------------------------------
#--------------------------------BUILD TARGETS----------------------------------
pkgmod = import('pkgconfig')
# -------------- Target: bufferlib_static ------------------
bufferlib_static_sources = [
]
bufferlib_static_link_args = {
'windows' : [],
'linux' : [],
'darwin' : []
}
bufferlib_static_build_defines = [
'-DBUF_BUILD_STATIC_LIBRARY'
]
bufferlib_static_use_defines = [
'-DBUF_USE_STATIC_LIBRARY'
]
bufferlib_static = static_library('bufferlib_static',
bufferlib_static_sources + sources,
dependencies: dependencies,
include_directories: inc,
install: true,
install_dir: lib_install_dir,
c_args: bufferlib_static_build_defines + bufferlib_static_use_defines,
cpp_args: bufferlib_static_build_defines + bufferlib_static_use_defines,
link_args: bufferlib_static_link_args[host_machine.system()],
gnu_symbol_visibility: 'hidden'
)
bufferlib_static_dep = declare_dependency(
link_with: bufferlib_static,
include_directories: inc,
compile_args: bufferlib_static_use_defines + build_mode_defines
)
pkgmod.generate(bufferlib_static,
name: 'BufferLib',
description: 'Static Library for BufferLib',
filebase: 'bufferlib_static',
install_dir: pkgconfig_install_path,
extra_cflags: bufferlib_static_use_defines + build_mode_defines
)
# -------------- Target: bufferlib_shared ------------------
bufferlib_shared_sources = [
]
bufferlib_shared_link_args = {
'windows' : [],
'linux' : [],
'darwin' : []
}
bufferlib_shared_build_defines = [
'-DBUF_BUILD_SHARED_LIBRARY'
]
bufferlib_shared_use_defines = [
'-DBUF_USE_SHARED_LIBRARY'
]
bufferlib_shared = shared_library('bufferlib_shared',
bufferlib_shared_sources + sources,
dependencies: dependencies,
include_directories: inc,
install: true,
install_dir: lib_install_dir,
c_args: bufferlib_shared_build_defines + bufferlib_shared_use_defines,
cpp_args: bufferlib_shared_build_defines + bufferlib_shared_use_defines,
link_args: bufferlib_shared_link_args[host_machine.system()],
gnu_symbol_visibility: 'hidden'
)
bufferlib_shared_dep = declare_dependency(
link_with: bufferlib_shared,
include_directories: inc,
compile_args: bufferlib_shared_use_defines + build_mode_defines
)
pkgmod.generate(bufferlib_shared,
name: 'BufferLib',
description: 'A memory buffer library',
filebase: 'bufferlib_shared',
install_dir: pkgconfig_install_path,
extra_cflags: bufferlib_shared_use_defines + build_mode_defines
)
# -------------- Target: main ------------------
main_sources = [
'source/main.c',
'source/buffer_test.c'
]
main_link_args = {
'windows' : [],
'linux' : [],
'darwin' : []
}
main_defines = [
]
main = executable('main',
main_sources + sources,
dependencies: dependencies,
include_directories: inc,
install: false,
c_args: main_defines,
cpp_args: main_defines,
link_args: main_link_args[host_machine.system()],
gnu_symbol_visibility: 'hidden'
)
#-------------------------------------------------------------------------------
#--------------------------------Header Intallation----------------------------------
# Header installation
install_subdir('include/bufferlib', install_dir : get_option('includedir'))