()
| 16 | # Main run() function |
| 17 | # |
| 18 | def run(): |
| 19 | if len(sys.argv) < 2 or sys.argv[1] in {'--version', '--help'}: |
| 20 | print('''\ |
| 21 | emcmake is a helper for cmake, setting various environment |
| 22 | variables so that emcc etc. are used. Typical usage: |
| 23 | |
| 24 | emcmake cmake [FLAGS] |
| 25 | ''', file=sys.stderr) |
| 26 | return 1 |
| 27 | |
| 28 | args = sys.argv[1:] |
| 29 | |
| 30 | def has_substr(args, substr): |
| 31 | return any(substr in s for s in args) |
| 32 | |
| 33 | # Append the Emscripten toolchain file if the user didn't specify one. |
| 34 | if not has_substr(args, '-DCMAKE_TOOLCHAIN_FILE') and 'CMAKE_TOOLCHAIN_FILE' not in os.environ: |
| 35 | args.append('-DCMAKE_TOOLCHAIN_FILE=' + utils.path_from_root('cmake/Modules/Platform/Emscripten.cmake')) |
| 36 | |
| 37 | if not has_substr(args, '-DCMAKE_CROSSCOMPILING_EMULATOR'): |
| 38 | node_js = config.NODE_JS[0] |
| 39 | # See https://github.com/emscripten-core/emscripten/issues/15522 |
| 40 | args.append(f'-DCMAKE_CROSSCOMPILING_EMULATOR={node_js}') |
| 41 | |
| 42 | # Print a better error if we have no CMake executable on the PATH |
| 43 | if not os.path.dirname(args[0]) and not shutil.which(args[0]): |
| 44 | print(f'emcmake: cmake executable not found on PATH: `{args[0]}`', file=sys.stderr) |
| 45 | return 1 |
| 46 | |
| 47 | # On Windows specify MinGW Makefiles or ninja if we have them and no other |
| 48 | # toolchain was specified, to keep CMake from pulling in a native Visual |
| 49 | # Studio, or Unix Makefiles. |
| 50 | if utils.WINDOWS and not any(arg.startswith('-G') for arg in args): |
| 51 | if shutil.which('mingw32-make'): |
| 52 | args += ['-G', 'MinGW Makefiles'] |
| 53 | elif shutil.which('ninja'): |
| 54 | args += ['-G', 'Ninja'] |
| 55 | else: |
| 56 | print('emcmake: no compatible cmake generator found; Please install ninja or mingw32-make, or specify a generator explicitly using -G', file=sys.stderr) |
| 57 | return 1 |
| 58 | |
| 59 | print(f'emcmake: {shlex.join(args)} in directory {os.getcwd()}', file=sys.stderr) |
| 60 | shared.exec_process(args) |
| 61 | |
| 62 | |
| 63 | if __name__ == '__main__': |
no test coverage detected