|
| 1 | +#!/bin/env python |
| 2 | +# |
| 3 | +# Build script for CMAKE module |
| 4 | +# |
| 5 | +# Assumes FSLDIR is set. If FSLDEVDIR is also set, this will be used as the installation |
| 6 | +# prefix |
| 7 | +# |
| 8 | +# Note that arch is only currently used for Windows to set the correct VC compiler architecture |
| 9 | + |
| 10 | +import os, sys |
| 11 | +import shutil |
| 12 | +import traceback |
| 13 | +import stat |
| 14 | + |
| 15 | +def remove_readonly(func, path, excinfo): |
| 16 | + os.chmod(path, stat.S_IWRITE) |
| 17 | + func(path) |
| 18 | + |
| 19 | +def rmdir(d): |
| 20 | + try: |
| 21 | + shutil.rmtree(d, onerror=remove_readonly) |
| 22 | + except: |
| 23 | + print("Error removing %s" % d) |
| 24 | + traceback.print_exc(limit=0) |
| 25 | + |
| 26 | +win = sys.platform.startswith("win") |
| 27 | +osx = sys.platform.startswith("darwin") |
| 28 | + |
| 29 | +if len(sys.argv) < 3: |
| 30 | + print("Usage: build.py <type> <arch> [--install]") |
| 31 | + sys.exit(1) |
| 32 | + |
| 33 | +build_type = sys.argv[1] |
| 34 | +arch = sys.argv[2] |
| 35 | +install = "--install" in sys.argv |
| 36 | + |
| 37 | +rootdir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) |
| 38 | +builddir = os.path.join(rootdir, "build_%s" % build_type) |
| 39 | +rmdir(builddir) |
| 40 | +os.makedirs(builddir) |
| 41 | +cwd = os.getcwd() |
| 42 | +os.chdir(builddir) |
| 43 | + |
| 44 | +cmake_opts = "-DCMAKE_BUILD_TYPE=%s" % build_type |
| 45 | +if install: |
| 46 | + installdir = os.environ.get("FSLDEVDIR", os.environ["FSLDIR"]) |
| 47 | + cmake_opts += ' -DCMAKE_INSTALL_PREFIX="%s"' % installdir |
| 48 | + |
| 49 | +if win: |
| 50 | + if "VCINSTALLDIR" not in os.environ: |
| 51 | + print("You must run this script from the Visual Studio tools command line") |
| 52 | + sys.exit(1) |
| 53 | + os.system('"%s/vcvarsall" %s' % (os.environ["VCINSTALLDIR"], arch)) |
| 54 | + cmake_opts += ' -G "NMake Makefiles"' |
| 55 | + make = "nmake" |
| 56 | +else: |
| 57 | + make = "make" |
| 58 | + |
| 59 | +os.system("cmake .. %s" % cmake_opts) |
| 60 | +os.system(make) |
| 61 | +if install: |
| 62 | + os.system("%s install" % make) |
| 63 | +else: |
| 64 | + os.system(make) |
| 65 | + |
| 66 | +os.chdir(cwd) |
| 67 | + |
0 commit comments