mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
133 lines
3.3 KiB
Python
Executable File
133 lines
3.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- mode: python -*-
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
def clean():
|
|
import shutil
|
|
|
|
dirs = ['./bin', './lib', './build']
|
|
|
|
for dir in dirs:
|
|
if os.path.isdir(dir): shutil.rmtree(dir)
|
|
|
|
def is_exe(fpath):
|
|
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
|
|
|
def which(program):
|
|
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 sys.platform == 'win32':
|
|
exe_file += '.exe'
|
|
|
|
if is_exe(exe_file):
|
|
return exe_file
|
|
|
|
return None
|
|
|
|
def default_generator(platform):
|
|
generator = 'Unix Makefiles'
|
|
|
|
if sys.platform == 'darwin':
|
|
generator = 'Unix Makefiles'#'Xcode'
|
|
elif sys.platform == 'win32':
|
|
generator = 'Visual Studio 14 2015 Win64'
|
|
|
|
return generator
|
|
|
|
def find_cmake():
|
|
cmake = None
|
|
|
|
if which('cmake3'):
|
|
cmake = 'cmake3'
|
|
elif which('cmake'):
|
|
cmake = 'cmake'
|
|
|
|
if cmake == None:
|
|
raise Exception("cmake not found")
|
|
|
|
return cmake
|
|
|
|
def parse_args(args):
|
|
options = {'SHARED' : 1}
|
|
generator = default_generator(sys.platform)
|
|
|
|
if len(args) == 0:
|
|
return options, generator
|
|
|
|
if not args[-1].startswith('--'):
|
|
generator = args.pop(len(args) - 1)
|
|
|
|
while len(args) and args[0].startswith('--'):
|
|
option = args.pop(0)
|
|
|
|
if not option.startswith('--'):
|
|
raise Exception('bad option: {}'.format(option))
|
|
|
|
if option == '--enable-shared':
|
|
options['SHARED'] = 1
|
|
elif option == '--enable-static':
|
|
options['STATIC'] = 1
|
|
elif option == '--disable-shared':
|
|
options['SHARED'] = 0
|
|
elif option == '--disable-static':
|
|
options['STATIC'] = 0
|
|
elif option == '--enable-tests':
|
|
options['BUILD_TESTS'] = 1
|
|
elif option == '--enable-coverage':
|
|
options['CALC_COVERAGE'] = 1
|
|
elif option == '--enable-examples':
|
|
options['BUILD_EXAMPLES'] = 1
|
|
elif option == '--enable-benchmarks':
|
|
options['BUILD_BENCHMARKS'] = 1
|
|
elif option == '--enable-benchmarks':
|
|
options['BUILD_BENCHMARKS'] = 1
|
|
elif option.startswith('--prefix='):
|
|
options['CMAKE_INSTALL_PREFIX'] = option.split('=')[1]
|
|
else:
|
|
print('skipping unknown option: {}'.format(option))
|
|
|
|
return options, generator
|
|
|
|
def main():
|
|
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == 'clean':
|
|
clean()
|
|
return
|
|
|
|
build_dir = './build'
|
|
|
|
if not os.path.isdir(build_dir):
|
|
os.mkdir(build_dir)
|
|
|
|
cmake = find_cmake()
|
|
options, generator = parse_args(sys.argv[1:])
|
|
command = [cmake]
|
|
|
|
if generator != None:
|
|
command.extend(['-G', generator])
|
|
|
|
if options != None:
|
|
for option in options:
|
|
command.extend(['-D', '{}={}'.format(option, options[option])])
|
|
|
|
cmake_scripts_dir = '../cmake' # relative to build_dir
|
|
command.append(cmake_scripts_dir)
|
|
|
|
print(' '.join(command))
|
|
|
|
subprocess.call(command, cwd=build_dir)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|