[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
.current_build
.vcpkg
scripts/__pycache__
compile_commands.json
build
conanbuild

View File

@ -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

View File

@ -1,58 +1,62 @@
#! /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)
def rm(path):
if os.path.exists(path) or os.path.islink(path):
os.remove(path)
if target == 'gba':
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(vcpkg_dir)
else:
toolchain = '-DCMAKE_TOOLCHAIN_FILE={:s}/scripts/buildsystems/vcpkg.cmake'.format(args.vcpkg_dir)
nostalgia_build_type = 'Native'
if build_type == 'asan':
if args.build_type == 'asan':
build_type_arg = 'Debug'
sanitizer_status = 'ON'
elif build_type == 'debug':
elif args.build_type == 'debug':
build_type_arg = 'Debug'
sanitizer_status = 'OFF'
elif build_type == 'release':
elif args.build_type == 'release':
build_type_arg = 'Release'
sanitizer_status = 'OFF'
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)
build_config = '{:s}-{:s}'.format(target, build_type)
if 'NOSTALGIA_QT_PATH' in os.environ:
if 'NOSTALGIA_QT_PATH' in os.environ:
qt_path = '-DNOSTALGIA_QT_PATH={:s}'.format(os.environ['NOSTALGIA_QT_PATH'])
else:
else:
qt_path = ''
if shutil.which('ninja') == None:
if args.build_tool == '' or args.build_tool == 'default':
if shutil.which('ninja') == None:
build_tool = ''
else:
else:
build_tool = '-GNinja'
elif args.build_tool == 'xcode':
build_tool = '-GXcode'
build_dir = '{:s}/build/{:s}'.format(project, build_config)
mkdir(build_dir)
subprocess.run(['cmake', '-S', project, '-B', build_dir, build_tool,
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),
@ -63,12 +67,19 @@ subprocess.run(['cmake', '-S', project, '-B', build_dir, build_tool,
toolchain,
])
mkdir('dist')
if target != 'gba':
mkdir('dist')
if args.target != 'gba':
cb = open('.current_build', 'w')
cb.write(build_type)
cb.write(args.build_type)
cb.close()
rm('compile_commands.json')
if platform.system() != 'Windows':
rm('compile_commands.json')
if platform.system() != 'Windows':
os.symlink('build/{:s}/compile_commands.json'.format(build_config), 'compile_commands.json')
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
sys.exit(1)