-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmeson.build
More file actions
197 lines (182 loc) · 5.05 KB
/
meson.build
File metadata and controls
197 lines (182 loc) · 5.05 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
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
project(
'libcppgenerate',
'cpp',
version: '0.2',
default_options: ['warning_level=3', 'cpp_std=c++11', 'default_library=both'],
)
# Version of dynamic library
library_version = '0.0.2'
src = files(
'cppgenerate/argument.cpp',
'cppgenerate/class.cpp',
'cppgenerate/codeblock.cpp',
'cppgenerate/constructor.cpp',
'cppgenerate/cppgenerateutils.cpp',
'cppgenerate/enum.cpp',
'cppgenerate/membervariable.cpp',
'cppgenerate/method.cpp',
'cppgenerate/printer.cpp',
'cppgenerate/variable.cpp',
)
# Set on Windows by default. When enabled, use .lib suffix for static libraries
# and do not build shared ones in Windows.
cmake_compatible_behavior = (
host_machine.system() in ['windows', 'cygwin']
and get_option('cmake-compatible-libraries')
)
shared_lib = []
building_shared_lib = (
not (
cmake_compatible_behavior
or meson.is_subproject()
) and get_option('default_library') in ['shared', 'both']
)
static_lib = []
building_static_lib = (
cmake_compatible_behavior
or meson.is_subproject()
or get_option('default_library') in ['shared', 'both']
)
if meson.is_subproject()
static_lib = static_library(
'cppgenerate',
src,
)
elif cmake_compatible_behavior
if (get_option('default_library') == 'shared')
warning(
'Shared libraries will not be generated on Windows.',
'Set -Dcmake-compatible-libraries=false to override',
)
endif
static_lib = static_library(
'cppgenerate',
src,
name_suffix: 'lib',
install: true,
)
elif building_shared_lib and building_static_lib
both_libs = both_libraries(
'cppgenerate',
src,
version: library_version,
install: true,
)
static_lib = both_libs.get_static_lib()
shared_lib = both_libs.get_shared_lib()
elif building_shared_lib
shared_lib = shared_library(
'cppgenerate',
src,
version: library_version,
install: true,
)
elif building_static_lib
static_lib = static_library(
'cppgenerate',
src,
install: true,
)
endif
if not meson.is_subproject()
install_headers(
'cppgenerate/accessmodifier.h',
'cppgenerate/argument.h',
'cppgenerate/class.h',
'cppgenerate/codeblock.h',
'cppgenerate/constructor.h',
'cppgenerate/cppgenerateutils.h',
'cppgenerate/enum.h',
'cppgenerate/membervariable.h',
'cppgenerate/method.h',
'cppgenerate/printer.h',
'cppgenerate/variable.h',
subdir: 'cppgenerate',
)
endif
# Configure .pc files
fs = import('fs')
# Base configuration object used for shared library
dynamic_lib_cfg = configuration_data()
dynamic_lib_cfg.set('PROJECT_VERSION', meson.project_version())
dynamic_lib_cfg.set('PKG_CONFIG_REQUIRES', '')
dynamic_lib_cfg.set('CMAKE_INSTALL_PREFIX', get_option('prefix'))
if fs.is_absolute(get_option('includedir'))
dynamic_lib_cfg.set('PKG_CONFIG_INCLUDEDIR', get_option('includedir'))
else
dynamic_lib_cfg.set(
'PKG_CONFIG_INCLUDEDIR',
'${prefix}' / get_option('includedir'),
)
endif
if fs.is_absolute(get_option('libdir'))
dynamic_lib_cfg.set('PKG_CONFIG_LIBDIR', get_option('libdir'))
else
dynamic_lib_cfg.set('PKG_CONFIG_LIBDIR', '${prefix}' / get_option('libdir'))
endif
dynamic_lib_cfg.set('PKG_CONFIG_LIBS', '-L${libdir} -lcppgenerate')
dynamic_lib_cfg.set('PKG_CONFIG_CFLAGS', '-I${includedir}')
# Static library configuration object based off of dynamic_lib_cfg
static_lib_cfg = dynamic_lib_cfg
static_lib_cfg.set('PKG_CONFIG_STATIC_LIBS', '-L${libdir} -l:libcppgenerate.a')
# Configure and install pkg-config files if the relevant library is being built
if host_machine.system() not in ['windows', 'cygwin'] and not meson.is_subproject()
if building_shared_lib
configure_file(
input: 'cppgenerate.pc.cmake',
output: 'cppgenerate.pc',
configuration: dynamic_lib_cfg,
format: 'cmake',
install: true,
install_dir: get_option('libdir') / 'pkgconfig',
)
endif
if building_static_lib
configure_file(
input: 'cppgenerate-static.pc.cmake',
output: 'cppgenerate-static.pc',
configuration: static_lib_cfg,
format: 'cmake',
install: true,
install_dir: get_option('libdir') / 'pkgconfig',
)
endif
endif
if meson.is_subproject()
shared_dep = declare_dependency(
link_with: static_lib,
include_directories: '.',
)
meson.override_dependency('cppgenerate-static', shared_dep)
endif
# Pick an appropriate dependency object for building tests and examples
if get_option('default_library') == 'both'
if meson.version().version_compare('>=1.6.0')
if (
get_option('default_both_libraries') in ['shared', 'auto']
and building_shared_lib
)
internal_lib = shared_lib
else
internal_lib = static_lib
endif
elif building_shared_lib
internal_lib = shared_lib
else
internal_lib = static_lib
endif
elif building_shared_lib
internal_lib = shared_lib
elif building_static_lib
internal_lib = static_lib
endif
internal_dep = declare_dependency(
link_with: internal_lib,
include_directories: '.',
)
if get_option('enable-tests')
subdir('tests')
endif
if get_option('enable-examples')
subdir('examples')
endif