[buildcore] Update buildcore

This commit is contained in:
Gary Talent 2022-07-24 00:34:52 -05:00
parent 6f6f77f104
commit 68d963ab69
4 changed files with 104 additions and 39 deletions

View File

@ -11,7 +11,7 @@ set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/dist/${BUILDCORE_BUILD_CONFIG}")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
# enable ccache # enable ccache
@ -26,9 +26,14 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG) add_definitions(-DDEBUG)
else() else()
add_definitions(-DNDEBUG) add_definitions(-DNDEBUG)
if(APPLE)
set(CMAKE_OSX_ARCHITECTURES arm64;x86_64)
endif()
endif() endif()
if(NOT MSVC) if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:preprocessor")
else()
# forces colored output when using ninja # forces colored output when using ninja
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color")
# enable warnings # enable warnings
@ -39,7 +44,7 @@ if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-field-initializers") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-field-initializers")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnull-dereference") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnull-dereference")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic")

View File

@ -24,10 +24,12 @@ ifneq ($(shell which docker 2> /dev/null),)
endif endif
endif endif
ifeq ($(shell ${ENV_RUN} python -c 'import sys; print(sys.version_info[0])'),3) ifneq ($(shell which python3 2> /dev/null),)
PYTHON3=python
else
PYTHON3=python3 PYTHON3=python3
else
ifeq ($(shell ${ENV_RUN} python -c 'import sys; print(sys.version_info[0])'),3)
PYTHON3=python
endif
endif endif
SCRIPTS=${BUILDCORE_PATH}/scripts SCRIPTS=${BUILDCORE_PATH}/scripts
@ -46,7 +48,7 @@ ifdef USE_VCPKG
VCPKG_TOOLCHAIN=--toolchain=${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake VCPKG_TOOLCHAIN=--toolchain=${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake
endif endif
ifeq ($(OS),darwin) ifeq ($(OS),darwin)
DEBUGGER=lldb DEBUGGER=lldb --
else else
DEBUGGER=gdb --args DEBUGGER=gdb --args
endif endif
@ -126,18 +128,22 @@ else
${VCPKG_DIR}/vcpkg install --triplet x64-windows ${VCPKG_PKGS} ${VCPKG_DIR}/vcpkg install --triplet x64-windows ${VCPKG_PKGS}
endif endif
else # USE_VCPKG ################################################ else ifdef USE_CONAN # USE_VCPKG ################################################
.PHONY: setup-conan .PHONY: setup-conan
conan-config: conan-config:
${ENV_RUN} conan profile new ${PROJECT_NAME} --detect --force ${ENV_RUN} conan profile new ${PROJECT_NAME} --detect --force
ifeq ($(OS),linux) ifeq ($(OS),linux)
${ENV_RUN} conan profile update settings.compiler.libcxx=libstdc++11 ${PROJECT_NAME} ${ENV_RUN} conan profile update settings.compiler.libcxx=libstdc++11 ${PROJECT_NAME}
else
${ENV_RUN} conan profile update settings.compiler.cppstd=20 ${PROJECT_NAME}
ifeq ($(OS),windows)
${ENV_RUN} conan profile update settings.compiler.runtime=static ${PROJECT_NAME}
endif
endif endif
.PHONY: conan .PHONY: conan
conan: conan:
${ENV_RUN} ${PYBB} conan-install ${PROJECT_NAME} ${ENV_RUN} ${PYBB} conan-install ${PROJECT_NAME}
#@mkdir -p .conanbuild && cd .conanbuild && conan install ../ --build=missing -pr=${PROJECT_NAME}
endif # USE_VCPKG ############################################### endif # USE_VCPKG ###############################################
.PHONY: configure-xcode .PHONY: configure-xcode

View File

@ -8,7 +8,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
# #
# "Python Busy Box" - adds cross platform equivalents to Unix commands that # "Python Busy Box" - adds cross-platform equivalents to Unix commands that
# don't translate well to that other operating system # don't translate well to that other operating system
import os import os
@ -17,31 +17,56 @@ import subprocess
import sys import sys
def cat(path): def cat(paths: [str]) -> int:
for path in paths:
try: try:
with open(path) as f: with open(path) as f:
data = f.read() data = f.read()
print(data) sys.stdout.write(data)
return 0
except FileNotFoundError: except FileNotFoundError:
sys.stderr.write('cat: {}: no such file or directory\n'.format(path)) sys.stderr.write('cat: {}: no such file or directory\n'.format(path))
return 1 return 1
sys.stdout.write('\n')
return 0
def mkdir(path): def mkdir(path: str) -> int:
if not os.path.exists(path) and os.path.isdir(path): if not os.path.exists(path):
try:
os.mkdir(path) os.mkdir(path)
except:
return 1
return 0
if os.path.isdir(path):
return 0
return 1
# this exists because Windows is utterly incapable of providing a proper rm -rf # this exists because Windows is utterly incapable of providing a proper rm -rf
def rm(path): def rm(path: str) -> int:
if (os.path.exists(path) or os.path.islink(path)) and not os.path.isdir(path): if (os.path.exists(path) or os.path.islink(path)) and not os.path.isdir(path):
os.remove(path) os.remove(path)
elif os.path.isdir(path): elif os.path.isdir(path):
shutil.rmtree(path) shutil.rmtree(path)
return 0
def cmake_build(base_path, target): def ctest_all() -> int:
base_path = sys.argv[2]
if not os.path.isdir(base_path):
# no generated projects
return 0
args = ['ctest'] + sys.argv[3:]
orig_dir = os.getcwd()
for d in os.listdir(base_path):
os.chdir(os.path.join(orig_dir, base_path, d))
err = subprocess.run(args).returncode
if err != 0:
return err
return 0
def cmake_build(base_path: str, target: str) -> int:
if not os.path.isdir(base_path): if not os.path.isdir(base_path):
# nothing to build # nothing to build
return 0 return 0
@ -52,24 +77,47 @@ def cmake_build(base_path, target):
err = subprocess.run(args).returncode err = subprocess.run(args).returncode
if err != 0: if err != 0:
return err return err
return 0
def conan() -> int:
project_name = sys.argv[2]
conan_dir = '.conanbuild'
err = mkdir(conan_dir)
if err != 0:
return err
args = ['conan', 'install', '../', '--build=missing', '-pr', project_name]
os.chdir(conan_dir)
err = subprocess.run(args).returncode
if err != 0:
return err
return 0
def main(): def main():
err = 0
if sys.argv[1] == 'mkdir': if sys.argv[1] == 'mkdir':
mkdir(sys.argv[2]) err = mkdir(sys.argv[2])
elif sys.argv[1] == 'rm': elif sys.argv[1] == 'rm':
for i in range(2, len(sys.argv)): for i in range(2, len(sys.argv)):
rm(sys.argv[i]) rm(sys.argv[i])
elif sys.argv[1] == 'conan-install':
err = conan()
elif sys.argv[1] == 'ctest-all':
err = ctest_all()
elif sys.argv[1] == 'cmake-build': elif sys.argv[1] == 'cmake-build':
err = cmake_build(sys.argv[2], sys.argv[3] if len(sys.argv) > 3 else None) err = cmake_build(sys.argv[2], sys.argv[3] if len(sys.argv) > 3 else None)
sys.exit(err)
elif sys.argv[1] == 'cat': elif sys.argv[1] == 'cat':
err = cat(sys.argv[2]) err = cat(sys.argv[2:])
sys.exit(err) else:
sys.stderr.write('Command not found\n')
err = 1
return err
if __name__ == '__main__': if __name__ == '__main__':
try: try:
main() err = main()
sys.exit(err)
except KeyboardInterrupt: except KeyboardInterrupt:
sys.exit(1) sys.exit(1)

View File

@ -66,15 +66,21 @@ def main():
build_dir = '{:s}/build/{:s}'.format(project_dir, build_config) build_dir = '{:s}/build/{:s}'.format(project_dir, build_config)
rm(build_dir) rm(build_dir)
mkdir(build_dir) mkdir(build_dir)
subprocess.run(['cmake', '-S', project_dir, '-B', build_dir, build_tool, cmake_cmd = [
'cmake', '-S', project_dir, '-B', build_dir, build_tool,
'-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON',
'-DCMAKE_TOOLCHAIN_FILE={:s}'.format(args.toolchain), '-DCMAKE_TOOLCHAIN_FILE={:s}'.format(args.toolchain),
'-DCMAKE_BUILD_TYPE={:s}'.format(build_type_arg), '-DCMAKE_BUILD_TYPE={:s}'.format(build_type_arg),
'-DUSE_ASAN={:s}'.format(sanitizer_status), '-DUSE_ASAN={:s}'.format(sanitizer_status),
'-DBUILDCORE_BUILD_CONFIG={:s}'.format(build_config), '-DBUILDCORE_BUILD_CONFIG={:s}'.format(build_config),
'-DBUILDCORE_TARGET={:s}'.format(args.target), '-DBUILDCORE_TARGET={:s}'.format(args.target),
qt_path, ]
]) if qt_path != '':
cmake_cmd.append(qt_path)
if platform.system() == 'Windows':
cmake_cmd.append('-A x64')
subprocess.run(cmake_cmd)
mkdir('dist') mkdir('dist')
if int(args.current_build) != 0: if int(args.current_build) != 0: