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