2018-06-14 04:17:34 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
from pathlib import Path
|
|
|
|
import platform
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from conans.client import conan_api
|
|
|
|
|
|
|
|
|
|
|
|
openrw_path = Path(__file__).resolve().parents[2]
|
|
|
|
cmake_generator_lookup = {
|
|
|
|
2015: 'Visual Studio 14 2015',
|
|
|
|
2017: 'Visual Studio 15 2017',
|
|
|
|
}
|
|
|
|
architectures = ['x64', 'x86']
|
|
|
|
|
2018-08-20 18:46:49 +02:00
|
|
|
conan_arch_map = {
|
|
|
|
'x86': 'x86',
|
|
|
|
'x64': 'x86_64',
|
|
|
|
}
|
|
|
|
|
2018-06-14 04:17:34 +02:00
|
|
|
|
|
|
|
def to_cmake_generator(vs_version, arch):
|
|
|
|
cmake_generator = cmake_generator_lookup[vs_version]
|
|
|
|
if arch == 'x64':
|
|
|
|
cmake_generator = '{} Win64'.format(cmake_generator)
|
|
|
|
return cmake_generator
|
2018-08-20 18:46:49 +02:00
|
|
|
|
|
|
|
|
2018-06-14 04:17:34 +02:00
|
|
|
def create_solution(path, vs_version, arch):
|
|
|
|
conan, _, _ = conan_api.ConanAPIV1.factory()
|
2018-09-02 15:09:49 +02:00
|
|
|
conan.remote_add('bincrafters', 'https://api.bintray.com/conan/bincrafters/public-conan', force=True)
|
2018-08-20 18:46:49 +02:00
|
|
|
conan_arch = conan_arch_map[arch]
|
2018-07-06 02:25:48 +02:00
|
|
|
conan.install(path=openrw_path, generators=('cmake_multi',), build=['missing', ],
|
2018-08-20 18:46:49 +02:00
|
|
|
settings=('build_type=Debug', 'arch={}'.format(conan_arch), ), install_folder=path)
|
2018-07-06 02:25:48 +02:00
|
|
|
conan.install(path=openrw_path, generators=('cmake_multi',), build=['missing', ],
|
2018-08-20 18:46:49 +02:00
|
|
|
settings=('build_type=Release', 'arch={}'.format(conan_arch), ), install_folder=path)
|
2018-06-14 04:17:34 +02:00
|
|
|
cmake_generator = to_cmake_generator(vs_version=vs_version, arch=arch)
|
|
|
|
subprocess.run([
|
2018-07-06 02:25:48 +02:00
|
|
|
'cmake', '-DUSE_CONAN=TRUE', '-DBOOST_STATIC=TRUE',
|
|
|
|
'-DBUILD_TESTS=TRUE', '-DBUILD_VIEWER=TRUE', '-DBUILD_TOOLS=TRUE',
|
2018-06-14 04:17:34 +02:00
|
|
|
'-G{}'.format(cmake_generator), str(openrw_path),
|
|
|
|
], cwd=path, check=True)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description='Create a Visual Studio solution for OpenRW.')
|
|
|
|
parser.add_argument('path', nargs='?', default=Path(), metavar='PATH', type=Path, help='Location to the solution')
|
|
|
|
parser.add_argument('-v', default=max(cmake_generator_lookup.keys()), choices=list(cmake_generator_lookup.keys()),
|
|
|
|
type=int, metavar='VERSION', dest='vs_version',
|
|
|
|
help='Version of Visual Studio (choices={})'.format(list(cmake_generator_lookup.keys())))
|
|
|
|
parser.add_argument('-a', default=architectures[0], choices=architectures, metavar='ARCH', dest='arch',
|
|
|
|
help='Architecture to build (choices={})'.format(architectures))
|
|
|
|
ns = parser.parse_args()
|
|
|
|
|
|
|
|
if platform.system() != 'Windows':
|
|
|
|
print('This script can only generate Visual Studio solutions for Windows.', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
path = ns.path.resolve()
|
|
|
|
arch = ns.arch
|
|
|
|
vs_version = ns.vs_version
|
|
|
|
|
|
|
|
print('Solution directory: {}'.format(path))
|
|
|
|
print('Architecture: {}'.format(arch))
|
|
|
|
print('Visual Studio version: {}'.format(vs_version))
|
|
|
|
|
|
|
|
create_solution(path=path, vs_version=vs_version, arch=arch)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|