From d50551cc74c70c22c1505c96490b382fd25fc527 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 24 Feb 2021 19:18:33 -0600 Subject: [PATCH] [nostalgia] Cleanup build scripts and add support for configuring Xcode project --- .gitignore | 1 + Makefile | 34 ++++------- scripts/{pybb => pybb.py} | 0 scripts/setup-build.py | 121 +++++++++++++++++++++----------------- 4 files changed, 78 insertions(+), 78 deletions(-) rename scripts/{pybb => pybb.py} (100%) diff --git a/.gitignore b/.gitignore index d63eb2a8..1f40a23e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .clangd .current_build .vcpkg +scripts/__pycache__ compile_commands.json build conanbuild diff --git a/Makefile b/Makefile index 433a597c..bc52aef6 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,8 @@ endif DEVENV=devenv$(shell pwd | sed 's/\//-/g') DEVENV_IMAGE=nostalgia-devenv -PYBB=python3 scripts/pybb +SETUP_BUILD=python3 ./scripts/setup-build.py +PYBB=python3 scripts/pybb.py CMAKE_BUILD=${PYBB} cmake-build RM_RF=${PYBB} rm ifndef VCPKG_DIR_BASE @@ -98,9 +99,7 @@ devenv-shell: vcpkg: ${VCPKG_DIR} vcpkg-install ${VCPKG_DIR}: -ifneq (,$(wildcard ${VCPKG_DIR})) ${ENV_RUN} ${RM_RF} ${VCPKG_DIR} -endif ${ENV_RUN} mkdir -p ${VCPKG_DIR_BASE} ${ENV_RUN} git clone -b release --depth 1 --branch ${VCPKG_VERSION} https://github.com/microsoft/vcpkg.git ${VCPKG_DIR} ifneq (${OS},windows) @@ -117,37 +116,26 @@ else ${VCPKG_DIR}/vcpkg install --triplet x64-windows sdl2 jsoncpp endif +.PHONY: configure-xcode +configure-xcode: + ${ENV_RUN} ${SETUP_BUILD} --vcpkg_dir ${VCPKG_DIR} --build_tool xcode + .PHONY: configure-release configure-release: -ifneq (,$(wildcard build/${HOST_ENV}-release)) - ${ENV_RUN} ${RM_RF} build/${HOST_ENV}-release -endif - ${ENV_RUN} python3 ./scripts/setup-build.py ${HOST_ENV} release ${VCPKG_DIR} + ${ENV_RUN} ${SETUP_BUILD} --vcpkg_dir ${VCPKG_DIR} --build_type release .PHONY: configure-debug configure-debug: -ifneq (,$(wildcard build/${HOST_ENV}-debug)) - ${ENV_RUN} ${RM_RF} build/${HOST_ENV}-debug -endif - ${ENV_RUN} python3 ./scripts/setup-build.py ${HOST_ENV} debug ${VCPKG_DIR} + ${ENV_RUN} ${SETUP_BUILD} --vcpkg_dir ${VCPKG_DIR} --build_type debug .PHONY: configure-asan configure-asan: -ifneq (,$(wildcard build/${HOST_ENV}-asan)) - ${ENV_RUN} ${RM_RF} build/${HOST_ENV}-asan -endif - ${ENV_RUN} python3 ./scripts/setup-build.py ${HOST_ENV} asan ${VCPKG_DIR} + ${ENV_RUN} ${SETUP_BUILD} --vcpkg_dir ${VCPKG_DIR} --build_type asan .PHONY: configure-gba configure-gba: -ifneq (,$(wildcard build/gba-release)) - ${ENV_RUN} ${RM_RF} build/gba-release -endif - ${ENV_RUN} python3 ./scripts/setup-build.py gba release ${VCPKG_DIR} + ${ENV_RUN} ${SETUP_BUILD} --target gba --build_type release .PHONY: configure-gba-debug configure-gba-debug: -ifneq (,$(wildcard build/gba-debug)) - ${ENV_RUN} ${RM_RF} build/gba-debug -endif - ${ENV_RUN} python3 ./scripts/setup-build.py gba debug ${VCPKG_DIR} + ${ENV_RUN} ${SETUP_BUILD} --target gba --build_type debug diff --git a/scripts/pybb b/scripts/pybb.py similarity index 100% rename from scripts/pybb rename to scripts/pybb.py diff --git a/scripts/setup-build.py b/scripts/setup-build.py index 85164441..15bd23a0 100755 --- a/scripts/setup-build.py +++ b/scripts/setup-build.py @@ -1,74 +1,85 @@ #! /usr/bin/env python3 +import argparse import os import platform import shutil import subprocess import sys -target = sys.argv[1] -build_type = sys.argv[2] -vcpkg_dir = sys.argv[3] +from pybb import mkdir, rm -project = os.getcwd() +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--target', help='Platform target ({OS}-{Arch},gba)', default='{:s}-{:s}'.format(sys.platform, platform.machine())) + parser.add_argument('--build_type', help='Build type (asan,debug,release)', default='release') + parser.add_argument('--build_tool', help='Build tool (default,xcode)', default='') + parser.add_argument('--vcpkg_dir', help='Path to VCPKG') + args = parser.parse_args() -def mkdir(path): - if not os.path.exists(path) and os.path.isdir(path): - os.mkdir(path) + if args.target == 'gba': + toolchain = '-DCMAKE_TOOLCHAIN_FILE=cmake/modules/GBA.cmake' + nostalgia_build_type = 'GBA' + else: + toolchain = '-DCMAKE_TOOLCHAIN_FILE={:s}/scripts/buildsystems/vcpkg.cmake'.format(args.vcpkg_dir) + nostalgia_build_type = 'Native' -def rm(path): - if os.path.exists(path) or os.path.islink(path): - os.remove(path) + if args.build_type == 'asan': + build_type_arg = 'Debug' + sanitizer_status = 'ON' + elif args.build_type == 'debug': + build_type_arg = 'Debug' + sanitizer_status = 'OFF' + elif args.build_type == 'release': + build_type_arg = 'Release' + sanitizer_status = 'OFF' -if target == 'gba': - toolchain = '-DCMAKE_TOOLCHAIN_FILE=cmake/modules/GBA.cmake' - nostalgia_build_type = 'GBA' -else: - toolchain = '-DCMAKE_TOOLCHAIN_FILE={:s}/scripts/buildsystems/vcpkg.cmake'.format(vcpkg_dir) - nostalgia_build_type = 'Native' + if args.build_tool == 'xcode': + build_config = '{:s}-{:s}'.format(args.target, args.build_tool) + else: + build_config = '{:s}-{:s}'.format(args.target, args.build_type) -if build_type == 'asan': - build_type_arg = 'Debug' - sanitizer_status = 'ON' -elif build_type == 'debug': - build_type_arg = 'Debug' - sanitizer_status = 'OFF' -elif build_type == 'release': - build_type_arg = 'Release' - sanitizer_status = 'OFF' + if 'NOSTALGIA_QT_PATH' in os.environ: + qt_path = '-DNOSTALGIA_QT_PATH={:s}'.format(os.environ['NOSTALGIA_QT_PATH']) + else: + qt_path = '' + if args.build_tool == '' or args.build_tool == 'default': + if shutil.which('ninja') == None: + build_tool = '' + else: + build_tool = '-GNinja' + elif args.build_tool == 'xcode': + build_tool = '-GXcode' -build_config = '{:s}-{:s}'.format(target, build_type) + project_dir = os.getcwd() + build_dir = '{:s}/build/{:s}'.format(project_dir, build_config) + rm(build_dir) + mkdir(build_dir) + subprocess.run(['cmake', '-S', project_dir, '-B', build_dir, build_tool, + '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', + '-DCMAKE_BUILD_TYPE={:s}'.format(build_type_arg), + '-DUSE_ASAN={:s}'.format(sanitizer_status), + '-DNOSTALGIA_IDE_BUILD=OFF', + '-DNOSTALGIA_BUILD_CONFIG={:s}'.format(build_config), + '-DNOSTALGIA_BUILD_TYPE={:s}'.format(nostalgia_build_type), + qt_path, + toolchain, + ]) -if 'NOSTALGIA_QT_PATH' in os.environ: - qt_path = '-DNOSTALGIA_QT_PATH={:s}'.format(os.environ['NOSTALGIA_QT_PATH']) -else: - qt_path = '' + mkdir('dist') + if args.target != 'gba': + cb = open('.current_build', 'w') + cb.write(args.build_type) + cb.close() -if shutil.which('ninja') == None: - build_tool = '' -else: - build_tool = '-GNinja' + rm('compile_commands.json') + if platform.system() != 'Windows': + os.symlink('build/{:s}/compile_commands.json'.format(build_config), 'compile_commands.json') -build_dir = '{:s}/build/{:s}'.format(project, build_config) -mkdir(build_dir) -subprocess.run(['cmake', '-S', project, '-B', build_dir, build_tool, - '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', - '-DCMAKE_BUILD_TYPE={:s}'.format(build_type_arg), - '-DUSE_ASAN={:s}'.format(sanitizer_status), - '-DNOSTALGIA_IDE_BUILD=OFF', - '-DNOSTALGIA_BUILD_CONFIG={:s}'.format(build_config), - '-DNOSTALGIA_BUILD_TYPE={:s}'.format(nostalgia_build_type), - qt_path, - toolchain, - ]) +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + sys.exit(1) -mkdir('dist') -if target != 'gba': - cb = open('.current_build', 'w') - cb.write(build_type) - cb.close() - -rm('compile_commands.json') -if platform.system() != 'Windows': - os.symlink('build/{:s}/compile_commands.json'.format(build_config), 'compile_commands.json')