Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/emcmake.py
6175 views
1
#!/usr/bin/env python3
2
# Copyright 2016 The Emscripten Authors. All rights reserved.
3
# Emscripten is available under two separate licenses, the MIT license and the
4
# University of Illinois/NCSA Open Source License. Both these licenses can be
5
# found in the LICENSE file.
6
7
import os
8
import shlex
9
import shutil
10
import sys
11
12
from tools import config, shared, utils
13
14
15
#
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
# In order to allow cmake to run code built with pthreads we need to pass
40
# some extra flags to node.
41
node_js += shared.node_pthread_flags(config.NODE_JS)
42
node_js = ';'.join(node_js)
43
# See https://github.com/emscripten-core/emscripten/issues/15522
44
args.append(f'-DCMAKE_CROSSCOMPILING_EMULATOR={node_js}')
45
46
# Print a better error if we have no CMake executable on the PATH
47
if not os.path.dirname(args[0]) and not shutil.which(args[0]):
48
print(f'emcmake: cmake executable not found on PATH: `{args[0]}`', file=sys.stderr)
49
return 1
50
51
# On Windows specify MinGW Makefiles or ninja if we have them and no other
52
# toolchain was specified, to keep CMake from pulling in a native Visual
53
# Studio, or Unix Makefiles.
54
if utils.WINDOWS and not any(arg.startswith('-G') for arg in args):
55
if shutil.which('mingw32-make'):
56
args += ['-G', 'MinGW Makefiles']
57
elif shutil.which('ninja'):
58
args += ['-G', 'Ninja']
59
else:
60
print('emcmake: no compatible cmake generator found; Please install ninja or mingw32-make, or specify a generator explicitly using -G', file=sys.stderr)
61
return 1
62
63
print(f'emcmake: {shlex.join(args)} in directory {os.getcwd()}', file=sys.stderr)
64
shared.exec_process(args)
65
66
67
if __name__ == '__main__':
68
sys.exit(run())
69
70