2015-11-03 03:22:13 +08:00
|
|
|
#!/usr/bin/env python3
|
2015-11-09 00:26:22 +08:00
|
|
|
# -*- mode: python -*-
|
2015-11-03 03:22:13 +08:00
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2015-11-09 00:26:22 +08:00
|
|
|
def clean():
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
dirs = ['./bin', './lib', './build']
|
|
|
|
|
|
|
|
for dir in dirs:
|
|
|
|
if os.path.isdir(dir): shutil.rmtree(dir)
|
2015-11-03 03:22:13 +08:00
|
|
|
|
2015-11-09 00:26:22 +08:00
|
|
|
def is_exe(fpath):
|
|
|
|
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
|
|
|
|
|
|
|
def which(program):
|
2015-11-03 03:22:13 +08:00
|
|
|
fpath, fname = os.path.split(program)
|
2015-11-09 00:26:22 +08:00
|
|
|
|
2015-11-03 03:22:13 +08:00
|
|
|
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)
|
2015-11-11 09:47:07 +08:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
exe_file += '.exe'
|
2015-11-09 00:26:22 +08:00
|
|
|
|
2015-11-03 03:22:13 +08:00
|
|
|
if is_exe(exe_file):
|
|
|
|
return exe_file
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
2015-11-09 00:26:22 +08:00
|
|
|
def default_generator(platform):
|
|
|
|
generator = 'Unix Makefiles'
|
|
|
|
|
|
|
|
if sys.platform == 'darwin':
|
2015-11-11 08:01:52 +08:00
|
|
|
generator = 'Unix Makefiles'#'Xcode'
|
2015-11-09 00:26:22 +08:00
|
|
|
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):
|
2015-11-21 10:30:32 +08:00
|
|
|
options = {'SHARED' : 1}
|
2015-11-09 00:26:22 +08:00
|
|
|
generator = default_generator(sys.platform)
|
|
|
|
|
|
|
|
if len(args) == 0:
|
|
|
|
return options, generator
|
|
|
|
|
2015-11-11 08:01:52 +08:00
|
|
|
if not args[-1].startswith('--'):
|
|
|
|
generator = args.pop(len(args) - 1)
|
|
|
|
|
|
|
|
while len(args) and args[0].startswith('--'):
|
2015-11-09 00:26:22 +08:00
|
|
|
option = args.pop(0)
|
|
|
|
|
2015-11-11 08:01:52 +08:00
|
|
|
if not option.startswith('--'):
|
2015-11-09 00:26:22 +08:00
|
|
|
raise Exception('bad option: {}'.format(option))
|
|
|
|
|
2015-11-21 10:30:32 +08:00
|
|
|
if option == '--enable-shared':
|
2015-11-11 08:01:52 +08:00
|
|
|
options['SHARED'] = 1
|
2015-11-21 10:30:32 +08:00
|
|
|
elif option == '--enable-static':
|
|
|
|
options['STATIC'] = 1
|
|
|
|
elif option == '--disable-shared':
|
2015-11-11 08:47:31 +08:00
|
|
|
options['SHARED'] = 0
|
2015-11-21 10:30:32 +08:00
|
|
|
elif option == '--disable-static':
|
|
|
|
options['STATIC'] = 0
|
2015-12-27 02:31:55 +08:00
|
|
|
elif option == '--enable-framework':
|
|
|
|
options['FRAMEWORK'] = 1
|
2015-11-21 10:30:32 +08:00
|
|
|
elif option == '--enable-tests':
|
2015-11-11 08:01:52 +08:00
|
|
|
options['BUILD_TESTS'] = 1
|
2015-11-21 10:30:32 +08:00
|
|
|
elif option == '--enable-coverage':
|
|
|
|
options['CALC_COVERAGE'] = 1
|
|
|
|
elif option == '--enable-examples':
|
2015-11-11 08:01:52 +08:00
|
|
|
options['BUILD_EXAMPLES'] = 1
|
2015-11-21 10:30:32 +08:00
|
|
|
elif option == '--enable-benchmarks':
|
|
|
|
options['BUILD_BENCHMARKS'] = 1
|
|
|
|
elif option == '--enable-benchmarks':
|
|
|
|
options['BUILD_BENCHMARKS'] = 1
|
2015-11-11 08:47:31 +08:00
|
|
|
elif option.startswith('--prefix='):
|
|
|
|
options['CMAKE_INSTALL_PREFIX'] = option.split('=')[1]
|
2015-11-21 12:34:39 +08:00
|
|
|
elif option == '--debug':
|
|
|
|
options['DEBUG'] = 1
|
2015-11-11 08:47:31 +08:00
|
|
|
else:
|
|
|
|
print('skipping unknown option: {}'.format(option))
|
2015-11-09 00:26:22 +08:00
|
|
|
|
|
|
|
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)
|
2015-11-03 03:22:13 +08:00
|
|
|
|
2015-11-09 00:26:22 +08:00
|
|
|
cmake = find_cmake()
|
|
|
|
options, generator = parse_args(sys.argv[1:])
|
|
|
|
command = [cmake]
|
2015-11-03 03:22:13 +08:00
|
|
|
|
2015-11-09 00:26:22 +08:00
|
|
|
if generator != None:
|
|
|
|
command.extend(['-G', generator])
|
2015-11-03 03:22:13 +08:00
|
|
|
|
2015-11-09 00:26:22 +08:00
|
|
|
if options != None:
|
|
|
|
for option in options:
|
|
|
|
command.extend(['-D', '{}={}'.format(option, options[option])])
|
2015-11-03 03:22:13 +08:00
|
|
|
|
2015-11-09 00:26:22 +08:00
|
|
|
cmake_scripts_dir = '../cmake' # relative to build_dir
|
|
|
|
command.append(cmake_scripts_dir)
|
2015-11-03 03:22:13 +08:00
|
|
|
|
2015-11-11 08:47:31 +08:00
|
|
|
print(' '.join(command))
|
|
|
|
|
2015-11-09 00:26:22 +08:00
|
|
|
subprocess.call(command, cwd=build_dir)
|
2015-11-03 03:22:13 +08:00
|
|
|
|
2015-11-09 00:26:22 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|