OLD | NEW |
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()) | |
9 endif | 8 endif |
10 emscripten_config = command.stdout().strip() | |
11 message('Emscripten config file: ' + emscripten_config) | |
12 | 9 |
13 # locate emcc | 10 if target_type == 'js' |
14 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());p
rint(EMSCRIPTEN_ROOT)', emscripten_config) | 11 # locate emscripten-config |
15 if command.returncode() != 0 | 12 python = import('python3').find_python() |
16 error(command.stderr().strip()) | 13 emscripten_config = get_option('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 |
| 16 error(command.stderr().strip()) |
| 17 endif |
| 18 emscripten_config = command.stdout().strip() |
| 19 message('Emscripten config file: ' + emscripten_config) |
| 20 |
| 21 # locate emcc |
| 22 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read())
;print(EMSCRIPTEN_ROOT)', emscripten_config) |
| 23 if command.returncode() != 0 |
| 24 error(command.stderr().strip()) |
| 25 endif |
| 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') |
17 endif | 35 endif |
18 emcc = join_paths(command.stdout().strip(), 'emcc') | |
19 emcc = find_program(emcc) | |
20 | |
21 # locate node | |
22 command = run_command(python, '-c', 'import sys;exec(open(sys.argv[1]).read());p
rint(NODE_JS)', emscripten_config) | |
23 if command.returncode() != 0 | |
24 error(command.stderr().strip()) | |
25 endif | |
26 nodejs = find_program(command.stdout().strip(), 'node', 'nodejs') | |
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 ] | 94 ] |
80 # sources specific to core | 95 # sources specific to core |
81 core_sources = [ | 96 core_sources = [ |
82 'compiled/traceInit.cpp', | 97 'compiled/traceInit.cpp', |
83 ] | 98 ] |
84 # sources for the bindings generator | 99 # sources for the bindings generator |
85 bindings_sources = [ | 100 bindings_sources = [ |
86 'compiled/bindings/generator.cpp', | 101 'compiled/bindings/generator.cpp', |
87 'compiled/bindings/main.cpp', | 102 'compiled/bindings/main.cpp', |
88 ] | 103 ] |
| 104 # native sources |
| 105 native_sources = [ |
| 106 'compiled/library.cpp', |
| 107 ] |
89 | 108 |
90 defines_args = [] | 109 defines_args = [] |
91 foreach define : DEFINES | 110 foreach define : DEFINES |
92 defines_args += '-D' + define | 111 defines_args += '-D' + define |
93 endforeach | 112 endforeach |
94 | 113 |
95 generation_args = [] | 114 generation_args = [] |
96 foreach param : GENERATION_PARAMS | 115 foreach param : GENERATION_PARAMS |
97 generation_args += '-s' | 116 generation_args += '-s' |
98 generation_args += param[0] + '=' + '@0@'.format(param[1]) | 117 generation_args += param[0] + '=' + '@0@'.format(param[1]) |
99 endforeach | 118 endforeach |
100 | 119 |
101 optional_args = [] | 120 optional_args = [] |
102 buildtype = get_option('buildtype') | 121 buildtype = get_option('buildtype') |
103 if buildtype.startswith('debug') | 122 if buildtype.startswith('debug') |
104 optional_args += '-DDEBUG' | 123 optional_args += '-DDEBUG' |
105 optional_args += '-g3' | 124 optional_args += '-g3' |
| 125 if target_type == 'native' |
| 126 ADDITIONAL_PARAMS += [ '-fsanitize=address' ] |
| 127 LINK_PARAMS = [ '-fsanitize=address' ] |
| 128 endif |
106 endif | 129 endif |
107 tracing = get_option('tracing') | 130 tracing = get_option('tracing') |
108 if tracing | 131 if tracing |
109 optional_args += '--tracing' | 132 optional_args += '--tracing' |
110 endif | 133 endif |
111 | 134 |
112 compiler_args = defines_args + generation_args + ADDITIONAL_PARAMS | 135 compiler_args = defines_args + generation_args + ADDITIONAL_PARAMS |
113 | 136 |
114 # build objects. | 137 if target_type == 'js' |
115 core_objects = [] | 138 # build objects. |
116 bindings_objects = [] | 139 core_objects = [] |
117 shared_objects = [] | 140 bindings_objects = [] |
118 foreach group : ['core', 'bindings', 'shared'] | 141 shared_objects = [] |
119 objects = [] | 142 foreach group : ['core', 'bindings', 'shared'] |
120 foreach source_file : get_variable(group + '_sources') | 143 objects = [] |
121 output_file = source_file.underscorify() + '.o' | 144 foreach source_file : get_variable(group + '_sources') |
122 command = [ emcc, '-MD', '-MF', '@DEPFILE@', '-c', '-o', '@OUTPUT@', | 145 output_file = source_file.underscorify() + '.o' |
123 '@INPUT@' ] + compiler_args | 146 command = [ emcc, '-MD', '-MF', '@DEPFILE@', '-c', '-o', '@OUTPUT@', |
124 if group != 'bindings' | 147 '@INPUT@' ] + compiler_args |
125 command += CORE_PARAMS + optional_args | 148 if group != 'bindings' |
126 endif | 149 command += CORE_PARAMS + optional_args |
127 objects += custom_target(output_file, | 150 endif |
128 input: files(source_file), | 151 objects += custom_target(output_file, |
129 output: output_file, | 152 input: files(source_file), |
130 depfile: output_file + '.deps', | 153 output: output_file, |
131 command: command) | 154 depfile: output_file + '.deps', |
| 155 command: command) |
| 156 endforeach |
| 157 # Ideally, we would call set_variable() here but that doesn't work |
| 158 # with arrays (see |
| 159 # https://github.com/mesonbuild/meson/issues/1481). So we have to |
| 160 # do this shifting dance instead. |
| 161 core_objects = bindings_objects |
| 162 bindings_objects = shared_objects |
| 163 shared_objects = objects |
132 endforeach | 164 endforeach |
133 # Ideally, we would call set_variable() here but that doesn't work with arrays | |
134 # (see https://github.com/mesonbuild/meson/issues/1481). So we have to do this | |
135 # shifting dance instead. | |
136 core_objects = bindings_objects | |
137 bindings_objects = shared_objects | |
138 shared_objects = objects | |
139 endforeach | |
140 | 165 |
141 # link the binding generator | 166 # link the binding generator |
142 bindings_generator = custom_target(BINDINGS_GENERATOR, | 167 bindings_generator = custom_target(BINDINGS_GENERATOR, |
143 input: bindings_objects + shared_objects, | 168 input: bindings_objects + shared_objects, |
144 output: BINDINGS_GENERATOR, | 169 output: BINDINGS_GENERATOR, |
145 depend_files: [ JS_LIBRARY, BINDINGS_JS_LIBRA
RY ], | 170 depend_files: [ JS_LIBRARY, BINDINGS_JS_LIB
RARY ], |
146 command: [ | 171 command: [ |
147 emcc, '-o', '@OUTPUT@', | 172 emcc, '-o', '@OUTPUT@', |
148 '--js-library', JS_LIBRARY, | 173 '--js-library', JS_LIBRARY, |
149 '--js-library', BINDINGS_JS_LIBRARY, | 174 '--js-library', BINDINGS_JS_LIBRARY, |
150 '@INPUT@' | 175 '@INPUT@' |
151 ]) | 176 ]) |
152 # run the binding generator | 177 # run the binding generator |
153 bindings_output = custom_target(BINDINGS_OUTPUT, | 178 bindings_output = custom_target(BINDINGS_OUTPUT, |
154 input: bindings_generator, | 179 input: bindings_generator, |
155 output: BINDINGS_OUTPUT, | 180 output: BINDINGS_OUTPUT, |
156 capture: true, | 181 capture: true, |
157 command: [nodejs, '@INPUT@']) | 182 command: [nodejs, '@INPUT@']) |
| 183 # link the core |
| 184 output_file = join_paths(meson.source_root(), 'lib', COMPILER_OUTPUT) |
| 185 compiler_output = custom_target(COMPILER_OUTPUT, |
| 186 build_by_default: true, |
| 187 input: core_objects + shared_objects, |
| 188 output: COMPILER_OUTPUT, |
| 189 depend_files: [ JS_LIBRARY ], |
| 190 command: [ |
| 191 emcc, '-o', output_file, |
| 192 '--post-js', bindings_output, |
| 193 '--js-library', JS_LIBRARY, |
| 194 '@INPUT@' |
| 195 ] + compiler_args + optional_args) |
| 196 else |
| 197 adblockpluscore = library('adblockpluscore', shared_sources, |
| 198 native_sources, |
| 199 cpp_args: ADDITIONAL_PARAMS + CORE_PARAMS, |
| 200 link_args: LINK_PARAMS) |
| 201 endif |
158 | 202 |
159 # link the core | |
160 output_file = join_paths(meson.source_root(), 'lib', COMPILER_OUTPUT) | |
161 compiler_output = custom_target(COMPILER_OUTPUT, | |
162 build_by_default: true, | |
163 input: core_objects + shared_objects, | |
164 output: COMPILER_OUTPUT, | |
165 depend_files: [ JS_LIBRARY ], | |
166 command: [ | |
167 emcc, '-o', output_file, | |
168 '--post-js', bindings_output, | |
169 '--js-library', JS_LIBRARY, | |
170 '@INPUT@' | |
171 ] + compiler_args + optional_args) | |
OLD | NEW |