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