LEFT | RIGHT |
1 project('adblockpluscore', license: ['GPL3'], meson_version: '>0.40.0') | 1 project('adblockpluscore', 'cpp', license: ['GPL3'], meson_version: '>0.40.0') |
2 | 2 |
3 # locate emscripten-config | 3 native = get_option('native') |
4 python = import('python3').find_python() | 4 if native |
5 emscripten_config = get_option('emscripten-config') | 5 target_type='native' |
6 command = run_command(python, '-c', 'import os.path, sys;print(os.path.expanduse
r(sys.argv[1]))', emscripten_config) | 6 else |
7 if command.returncode() != 0 | 7 target_type='js' |
8 error(command.stderr().strip()) | 8 endif |
9 endif | 9 |
10 emscripten_config = command.stdout().strip() | 10 if target_type == 'js' |
11 message('Emscripten config file: ' + emscripten_config) | 11 # locate emscripten-config |
12 | 12 python = import('python3').find_python() |
13 # locate emcc | 13 emscripten_config = get_option('emscripten-config') |
14 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());p
rint(EMSCRIPTEN_ROOT)', emscripten_config) | 14 command = run_command(python, '-c', 'import os.path, sys;print(os.path.expandu
ser(sys.argv[1]))', emscripten_config) |
15 if command.returncode() != 0 | 15 if command.returncode() != 0 |
16 error(command.stderr().strip()) | 16 error(command.stderr().strip()) |
17 endif | 17 endif |
18 emcc = join_paths(command.stdout().strip(), 'emcc') | 18 emscripten_config = command.stdout().strip() |
19 emcc = find_program(emcc) | 19 message('Emscripten config file: ' + emscripten_config) |
20 | 20 |
21 # locate node | 21 # locate emcc |
22 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());p
rint(NODE_JS)', emscripten_config) | 22 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read())
;print(EMSCRIPTEN_ROOT)', emscripten_config) |
23 if command.returncode() != 0 | 23 if command.returncode() != 0 |
24 error(command.stderr().strip()) | 24 error(command.stderr().strip()) |
25 endif | 25 endif |
26 nodejs = find_program(command.stdout().strip(), 'node', 'nodejs') | 26 emcc = join_paths(command.stdout().strip(), 'emcc') |
| 27 emcc = find_program(emcc) |
| 28 |
| 29 # locate node |
| 30 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read())
;print(NODE_JS)', emscripten_config) |
| 31 if command.returncode() != 0 |
| 32 error(command.stderr().strip()) |
| 33 endif |
| 34 nodejs = find_program(command.stdout().strip(), 'node', 'nodejs') |
| 35 endif |
27 | 36 |
28 JS_LIBRARY = files(join_paths('compiled', 'library.js')) | 37 JS_LIBRARY = files(join_paths('compiled', 'library.js')) |
29 BINDINGS_JS_LIBRARY = files(join_paths('compiled', 'bindings', 'library.js')) | 38 BINDINGS_JS_LIBRARY = files(join_paths('compiled', 'bindings', 'library.js')) |
30 BINDINGS_GENERATOR = 'bindings.cpp.js' | 39 BINDINGS_GENERATOR = 'bindings.cpp.js' |
31 BINDINGS_OUTPUT = 'bindings.js' | 40 BINDINGS_OUTPUT = 'bindings.js' |
32 COMPILER_OUTPUT = 'compiled.js' | 41 COMPILER_OUTPUT = 'compiled.js' |
33 # params for emcc compilation | 42 # params for emcc compilation |
34 ADDITIONAL_PARAMS = [ '-O3', '-m32', '-std=c++1z', '--memory-init-file', '0', | 43 ADDITIONAL_PARAMS = [ '-O3', '-std=c++1z', '-Wall', '-Werror', |
35 '--emit-symbol-map', '-Wall', '-Werror', | |
36 '-fno-rtti' ] | 44 '-fno-rtti' ] |
| 45 if target_type == 'js' |
| 46 # CXXFLAGS specific to emcc |
| 47 ADDITIONAL_PARAMS += [ '-m32', '--memory-init-file', '0', |
| 48 '--emit-symbol-map' ] |
| 49 else |
| 50 ADDITIONAL_PARAMS += [ '-fsanitize=address' ] |
| 51 endif |
37 # additional params just for core | 52 # additional params just for core |
38 CORE_PARAMS = [ '-fno-exceptions' ] | 53 CORE_PARAMS = [ '-fno-exceptions' ] |
39 | 54 |
40 DEFINES = [] | 55 DEFINES = [] |
41 GENERATION_PARAMS = [ | 56 GENERATION_PARAMS = [ |
42 ['SHELL_FILE', '"' + | 57 ['SHELL_FILE', '"' + |
43 join_paths(meson.source_root(), 'compiled', 'shell.js') + | 58 join_paths(meson.source_root(), 'compiled', 'shell.js') + |
44 '"'], | 59 '"'], |
45 ['ASM_JS', '2'], # "almost asm" | 60 ['ASM_JS', '2'], # "almost asm" |
46 ['TOTAL_MEMORY', 16*1024*1024], | 61 ['TOTAL_MEMORY', 16*1024*1024], |
(...skipping 30 matching lines...) Expand all Loading... |
77 ] | 92 ] |
78 # sources specific to core | 93 # sources specific to core |
79 core_sources = [ | 94 core_sources = [ |
80 'compiled/traceInit.cpp', | 95 'compiled/traceInit.cpp', |
81 ] | 96 ] |
82 # sources for the bindings generator | 97 # sources for the bindings generator |
83 bindings_sources = [ | 98 bindings_sources = [ |
84 'compiled/bindings/generator.cpp', | 99 'compiled/bindings/generator.cpp', |
85 'compiled/bindings/main.cpp', | 100 'compiled/bindings/main.cpp', |
86 ] | 101 ] |
| 102 # native sources |
| 103 native_sources = [ |
| 104 'compiled/library.cpp', |
| 105 'compiled/Utils.cpp', |
| 106 ] |
87 | 107 |
88 defines_args = [] | 108 defines_args = [] |
89 foreach define : DEFINES | 109 foreach define : DEFINES |
90 defines_args += '-D' + define | 110 defines_args += '-D' + define |
91 endforeach | 111 endforeach |
92 | 112 |
93 generation_args = [] | 113 generation_args = [] |
94 foreach param : GENERATION_PARAMS | 114 foreach param : GENERATION_PARAMS |
95 generation_args += '-s' | 115 generation_args += '-s' |
96 generation_args += param[0] + '=' + '@0@'.format(param[1]) | 116 generation_args += param[0] + '=' + '@0@'.format(param[1]) |
97 endforeach | 117 endforeach |
98 | 118 |
99 optional_args = [] | 119 optional_args = [] |
100 buildtype = get_option('buildtype') | 120 buildtype = get_option('buildtype') |
101 if buildtype.startswith('debug') | 121 if buildtype.startswith('debug') |
102 optional_args += '-DDEBUG' | 122 optional_args += '-DDEBUG' |
103 optional_args += '-g3' | 123 optional_args += '-g3' |
| 124 if target_type == 'native' |
| 125 ADDITIONAL_PARAMS += [ '-fsanitize=address' ] |
| 126 LINK_PARAMS = [ '-fsanitize=address' ] |
| 127 endif |
104 endif | 128 endif |
105 tracing = get_option('tracing') | 129 tracing = get_option('tracing') |
106 if tracing | 130 if tracing |
107 optional_args += '--tracing' | 131 optional_args += '--tracing' |
108 endif | 132 endif |
109 | 133 |
110 compiler_args = defines_args + generation_args + ADDITIONAL_PARAMS | 134 compiler_args = defines_args + generation_args + ADDITIONAL_PARAMS |
111 | 135 |
112 # build objects. | 136 if target_type == 'js' |
113 core_objects = [] | 137 # build objects. |
114 bindings_objects = [] | 138 core_objects = [] |
115 shared_objects = [] | 139 bindings_objects = [] |
116 foreach group : ['core', 'bindings', 'shared'] | 140 shared_objects = [] |
117 objects = [] | 141 foreach group : ['core', 'bindings', 'shared'] |
118 foreach source_file : get_variable(group + '_sources') | 142 objects = [] |
119 output_file = source_file.underscorify() + '.o' | 143 foreach source_file : get_variable(group + '_sources') |
120 command = [ emcc, '-MD', '-MF', '@DEPFILE@', '-c', '-o', '@OUTPUT@', | 144 output_file = source_file.underscorify() + '.o' |
121 '@INPUT@' ] + compiler_args | 145 command = [ emcc, '-MD', '-MF', '@DEPFILE@', '-c', '-o', '@OUTPUT@', |
122 if group != 'bindings' | 146 '@INPUT@' ] + compiler_args |
123 command += CORE_PARAMS + optional_args | 147 if group != 'bindings' |
124 endif | 148 command += CORE_PARAMS + optional_args |
125 objects += custom_target(output_file, | 149 endif |
126 input: files(source_file), | 150 objects += custom_target(output_file, |
127 output: output_file, | 151 input: files(source_file), |
128 depfile: output_file + '.deps', | 152 output: output_file, |
129 command: command) | 153 depfile: output_file + '.deps', |
| 154 command: command) |
| 155 endforeach |
| 156 # Ideally, we would call set_variable() here but that doesn't work |
| 157 # with arrays (see |
| 158 # https://github.com/mesonbuild/meson/issues/1481). So we have to |
| 159 # do this shifting dance instead. |
| 160 core_objects = bindings_objects |
| 161 bindings_objects = shared_objects |
| 162 shared_objects = objects |
130 endforeach | 163 endforeach |
131 # Ideally, we would call set_variable() here but that doesn't work with arrays | 164 |
132 # (see https://github.com/mesonbuild/meson/issues/1481). So we have to do this | 165 # link the binding generator |
133 # shifting dance instead. | 166 bindings_generator = custom_target(BINDINGS_GENERATOR, |
134 core_objects = bindings_objects | 167 input: bindings_objects + shared_objects, |
135 bindings_objects = shared_objects | 168 output: BINDINGS_GENERATOR, |
136 shared_objects = objects | 169 depend_files: [ JS_LIBRARY, BINDINGS_JS_LIB
RARY ], |
137 endforeach | 170 command: [ |
138 | 171 emcc, '-o', '@OUTPUT@', |
139 # link the binding generator | 172 '--js-library', JS_LIBRARY, |
140 bindings_generator = custom_target(BINDINGS_GENERATOR, | 173 '--js-library', BINDINGS_JS_LIBRARY, |
141 input: bindings_objects + shared_objects, | 174 '@INPUT@' |
142 output: BINDINGS_GENERATOR, | 175 ]) |
143 depend_files: [ JS_LIBRARY, BINDINGS_JS_LIBRA
RY ], | 176 # run the binding generator |
144 command: [ | 177 bindings_output = custom_target(BINDINGS_OUTPUT, |
145 emcc, '-o', '@OUTPUT@', | 178 input: bindings_generator, |
146 '--js-library', JS_LIBRARY, | 179 output: BINDINGS_OUTPUT, |
147 '--js-library', BINDINGS_JS_LIBRARY, | 180 capture: true, |
148 '@INPUT@' | 181 command: [nodejs, '@INPUT@']) |
149 ]) | 182 # link the core |
150 # run the binding generator | 183 output_file = join_paths(meson.source_root(), 'lib', COMPILER_OUTPUT) |
151 bindings_output = custom_target(BINDINGS_OUTPUT, | 184 compiler_output = custom_target(COMPILER_OUTPUT, |
152 input: bindings_generator, | 185 build_by_default: true, |
153 output: BINDINGS_OUTPUT, | 186 input: core_objects + shared_objects, |
154 capture: true, | 187 output: COMPILER_OUTPUT, |
155 command: [nodejs, '@INPUT@']) | 188 depend_files: [ JS_LIBRARY ], |
156 | 189 command: [ |
157 # link the core | 190 emcc, '-o', output_file, |
158 output_file = join_paths(meson.source_root(), 'lib', COMPILER_OUTPUT) | 191 '--post-js', bindings_output, |
159 compiler_output = custom_target(COMPILER_OUTPUT, | 192 '--js-library', JS_LIBRARY, |
160 build_by_default: true, | 193 '@INPUT@' |
161 input: core_objects + shared_objects, | 194 ] + compiler_args + optional_args) |
162 output: COMPILER_OUTPUT, | 195 else |
163 depend_files: [ JS_LIBRARY ], | 196 GTEST_DIR = join_paths('third_party', 'googletest', 'googletest') |
164 command: [ | 197 GTEST_PARAMS = [] |
165 emcc, '-o', output_file, | 198 compiler = meson.get_compiler('cpp') |
166 '--post-js', bindings_output, | 199 if compiler.has_argument('-pthread') |
167 '--js-library', JS_LIBRARY, | 200 GTEST_PARAMS += '-pthread' |
168 '@INPUT@' | 201 LINK_PARAMS += '-lpthread' |
169 ] + compiler_args + optional_args) | 202 endif |
| 203 |
| 204 test_sources = [ |
| 205 'test/compiled/abptest.cpp', |
| 206 'test/compiled/String.cpp', |
| 207 'test/compiled/StringMap.cpp', |
| 208 'test/compiled/RegExp.cpp', |
| 209 ] |
| 210 |
| 211 adblockpluscore = library('adblockpluscore', shared_sources, |
| 212 native_sources, |
| 213 cpp_args: ADDITIONAL_PARAMS + CORE_PARAMS, |
| 214 link_args: LINK_PARAMS) |
| 215 gtest = static_library('gtest', files(join_paths(GTEST_DIR, 'src', 'gtest-all.
cc')), |
| 216 include_directories: [ |
| 217 include_directories(join_paths(GTEST_DIR, 'include'
), is_system: true), |
| 218 include_directories(GTEST_DIR) |
| 219 ], |
| 220 cpp_args: GTEST_PARAMS) |
| 221 abptest = executable('abptest', test_sources, |
| 222 cpp_args: ADDITIONAL_PARAMS + CORE_PARAMS, |
| 223 include_directories: include_directories(join_paths(GTEST
_DIR, 'include')), |
| 224 link_args: LINK_PARAMS, |
| 225 link_with: [ adblockpluscore, gtest ]) |
| 226 test('abptest', abptest) |
| 227 endif |
| 228 |
LEFT | RIGHT |