[nostalgia] Cleanup build scripts and add support for configuring Xcode project

This commit is contained in:
Gary Talent 2021-02-24 19:18:33 -06:00
parent b3aa0eb59d
commit d50551cc74
4 changed files with 78 additions and 78 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
.clangd .clangd
.current_build .current_build
.vcpkg .vcpkg
scripts/__pycache__
compile_commands.json compile_commands.json
build build
conanbuild conanbuild

View File

@ -10,7 +10,8 @@ endif
DEVENV=devenv$(shell pwd | sed 's/\//-/g') DEVENV=devenv$(shell pwd | sed 's/\//-/g')
DEVENV_IMAGE=nostalgia-devenv 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 CMAKE_BUILD=${PYBB} cmake-build
RM_RF=${PYBB} rm RM_RF=${PYBB} rm
ifndef VCPKG_DIR_BASE ifndef VCPKG_DIR_BASE
@ -98,9 +99,7 @@ devenv-shell:
vcpkg: ${VCPKG_DIR} vcpkg-install vcpkg: ${VCPKG_DIR} vcpkg-install
${VCPKG_DIR}: ${VCPKG_DIR}:
ifneq (,$(wildcard ${VCPKG_DIR}))
${ENV_RUN} ${RM_RF} ${VCPKG_DIR} ${ENV_RUN} ${RM_RF} ${VCPKG_DIR}
endif
${ENV_RUN} mkdir -p ${VCPKG_DIR_BASE} ${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} ${ENV_RUN} git clone -b release --depth 1 --branch ${VCPKG_VERSION} https://github.com/microsoft/vcpkg.git ${VCPKG_DIR}
ifneq (${OS},windows) ifneq (${OS},windows)
@ -117,37 +116,26 @@ else
${VCPKG_DIR}/vcpkg install --triplet x64-windows sdl2 jsoncpp ${VCPKG_DIR}/vcpkg install --triplet x64-windows sdl2 jsoncpp
endif endif
.PHONY: configure-xcode
configure-xcode:
${ENV_RUN} ${SETUP_BUILD} --vcpkg_dir ${VCPKG_DIR} --build_tool xcode
.PHONY: configure-release .PHONY: configure-release
configure-release: configure-release:
ifneq (,$(wildcard build/${HOST_ENV}-release)) ${ENV_RUN} ${SETUP_BUILD} --vcpkg_dir ${VCPKG_DIR} --build_type release
${ENV_RUN} ${RM_RF} build/${HOST_ENV}-release
endif
${ENV_RUN} python3 ./scripts/setup-build.py ${HOST_ENV} release ${VCPKG_DIR}
.PHONY: configure-debug .PHONY: configure-debug
configure-debug: configure-debug:
ifneq (,$(wildcard build/${HOST_ENV}-debug)) ${ENV_RUN} ${SETUP_BUILD} --vcpkg_dir ${VCPKG_DIR} --build_type debug
${ENV_RUN} ${RM_RF} build/${HOST_ENV}-debug
endif
${ENV_RUN} python3 ./scripts/setup-build.py ${HOST_ENV} debug ${VCPKG_DIR}
.PHONY: configure-asan .PHONY: configure-asan
configure-asan: configure-asan:
ifneq (,$(wildcard build/${HOST_ENV}-asan)) ${ENV_RUN} ${SETUP_BUILD} --vcpkg_dir ${VCPKG_DIR} --build_type asan
${ENV_RUN} ${RM_RF} build/${HOST_ENV}-asan
endif
${ENV_RUN} python3 ./scripts/setup-build.py ${HOST_ENV} asan ${VCPKG_DIR}
.PHONY: configure-gba .PHONY: configure-gba
configure-gba: configure-gba:
ifneq (,$(wildcard build/gba-release)) ${ENV_RUN} ${SETUP_BUILD} --target gba --build_type release
${ENV_RUN} ${RM_RF} build/gba-release
endif
${ENV_RUN} python3 ./scripts/setup-build.py gba release ${VCPKG_DIR}
.PHONY: configure-gba-debug .PHONY: configure-gba-debug
configure-gba-debug: configure-gba-debug:
ifneq (,$(wildcard build/gba-debug)) ${ENV_RUN} ${SETUP_BUILD} --target gba --build_type debug
${ENV_RUN} ${RM_RF} build/gba-debug
endif
${ENV_RUN} python3 ./scripts/setup-build.py gba debug ${VCPKG_DIR}

View File

@ -1,74 +1,85 @@
#! /usr/bin/env python3 #! /usr/bin/env python3
import argparse
import os import os
import platform import platform
import shutil import shutil
import subprocess import subprocess
import sys import sys
target = sys.argv[1] from pybb import mkdir, rm
build_type = sys.argv[2]
vcpkg_dir = sys.argv[3]
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 args.target == 'gba':
if not os.path.exists(path) and os.path.isdir(path): toolchain = '-DCMAKE_TOOLCHAIN_FILE=cmake/modules/GBA.cmake'
os.mkdir(path) 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 args.build_type == 'asan':
if os.path.exists(path) or os.path.islink(path): build_type_arg = 'Debug'
os.remove(path) 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': if args.build_tool == 'xcode':
toolchain = '-DCMAKE_TOOLCHAIN_FILE=cmake/modules/GBA.cmake' build_config = '{:s}-{:s}'.format(args.target, args.build_tool)
nostalgia_build_type = 'GBA' else:
else: build_config = '{:s}-{:s}'.format(args.target, args.build_type)
toolchain = '-DCMAKE_TOOLCHAIN_FILE={:s}/scripts/buildsystems/vcpkg.cmake'.format(vcpkg_dir)
nostalgia_build_type = 'Native'
if build_type == 'asan': if 'NOSTALGIA_QT_PATH' in os.environ:
build_type_arg = 'Debug' qt_path = '-DNOSTALGIA_QT_PATH={:s}'.format(os.environ['NOSTALGIA_QT_PATH'])
sanitizer_status = 'ON' else:
elif build_type == 'debug': qt_path = ''
build_type_arg = 'Debug'
sanitizer_status = 'OFF'
elif build_type == 'release':
build_type_arg = 'Release'
sanitizer_status = 'OFF'
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: mkdir('dist')
qt_path = '-DNOSTALGIA_QT_PATH={:s}'.format(os.environ['NOSTALGIA_QT_PATH']) if args.target != 'gba':
else: cb = open('.current_build', 'w')
qt_path = '' cb.write(args.build_type)
cb.close()
if shutil.which('ninja') == None: rm('compile_commands.json')
build_tool = '' if platform.system() != 'Windows':
else: os.symlink('build/{:s}/compile_commands.json'.format(build_config), 'compile_commands.json')
build_tool = '-GNinja'
build_dir = '{:s}/build/{:s}'.format(project, build_config) if __name__ == '__main__':
mkdir(build_dir) try:
subprocess.run(['cmake', '-S', project, '-B', build_dir, build_tool, main()
'-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', except KeyboardInterrupt:
'-DCMAKE_BUILD_TYPE={:s}'.format(build_type_arg), sys.exit(1)
'-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,
])
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')