diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-09-10 14:30:47 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-09-10 14:30:47 -0700 |
commit | ea729bea8c5008dedcdfd79aaf3b2deba3eec52b (patch) | |
tree | 33468a444c19bcdf0edc5bf33aa1e39371280bcc /tools/shared.py | |
parent | 690a9e16e812301245a12a6ac8f7597552255719 (diff) | |
parent | 48b79570deeee7fa22a6c5876aa949601aa7549d (diff) |
Merge pull request #1605 from juj/mingw32make_nmake_cmake
Mingw32make nmake cmake
Diffstat (limited to 'tools/shared.py')
-rw-r--r-- | tools/shared.py | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/tools/shared.py b/tools/shared.py index 8031d99c..94daadae 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -820,14 +820,52 @@ class Building: env['EMSCRIPTEN'] = path_from_root() return env + # Finds the given executable 'program' in PATH. Operates like the Unix tool 'which'. + @staticmethod + def which(program): + import os + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + + if WINDOWS and not '.' in fname: + if is_exe(exe_file + '.exe'): + return exe_file + '.exe' + if is_exe(exe_file + '.cmd'): + return exe_file + '.cmd' + if is_exe(exe_file + '.bat'): + return exe_file + '.bat' + + return None + @staticmethod def handle_CMake_toolchain(args, env): - # Don't append a toolchain file if the user specified one already. - for arg in args: - if '-DCMAKE_TOOLCHAIN_FILE' in arg: - return args - args.append('-DCMAKE_TOOLCHAIN_FILE=' + path_from_root('cmake', 'Platform', 'Emscripten.cmake')) + def has_substr(array, substr): + for arg in array: + if substr in arg: + return True + return False + + # Append the Emscripten toolchain file if the user didn't specify one. + if not has_substr(args, '-DCMAKE_TOOLCHAIN_FILE'): + args.append('-DCMAKE_TOOLCHAIN_FILE=' + path_from_root('cmake', 'Platform', 'Emscripten.cmake')) + + # On Windows specify MinGW Makefiles if we have MinGW and no other toolchain was specified, to avoid CMake + # pulling in a native Visual Studio, or Unix Makefiles. + if WINDOWS and not '-G' in args and Building.which('mingw32-make'): + args += ['-G', 'MinGW Makefiles'] + return args @staticmethod @@ -858,6 +896,13 @@ class Building: logging.error('Executable to run not specified.') sys.exit(1) #args += ['VERBOSE=1'] + + # On Windows prefer building with mingw32-make instead of make, if it exists. + if WINDOWS and args[0] == 'make': + mingw32_make = Building.which('mingw32-make') + if mingw32_make: + args[0] = mingw32_make + try: process = Popen(args, stdout=stdout, stderr=stderr, env=env) process.communicate() |