[Build] Add --build-tests and --cmake-define flags to xenia-build.py

This commit is contained in:
Herman S.
2026-03-10 15:18:21 +09:00
parent d1ad597939
commit b15cd5b164
2 changed files with 26 additions and 4 deletions

View File

@@ -231,7 +231,7 @@ endfunction()
function(xe_test_suite name base_path) function(xe_test_suite name base_path)
cmake_parse_arguments(ARG "" "" "LINKS" ${ARGN}) cmake_parse_arguments(ARG "" "" "LINKS" ${ARGN})
file(GLOB _test_sources CONFIGURE_DEPENDS "${base_path}/*_test.cc") file(GLOB _test_sources "${base_path}/*_test.cc")
if(NOT _test_sources) if(NOT _test_sources)
return() return()

View File

@@ -673,12 +673,15 @@ def get_clang_format_binary():
sys.exit(1) sys.exit(1)
def run_cmake_configure(build_type="Release", cc=None): def run_cmake_configure(build_type="Release", cc=None, build_tests=False,
extra_args=None):
"""Runs cmake configure on the project. """Runs cmake configure on the project.
Args: Args:
build_type: Build configuration (Debug, Release, Checked). build_type: Build configuration (Debug, Release, Checked).
cc: C compiler to use (e.g. 'clang', 'gcc'). cc: C compiler to use (e.g. 'clang', 'gcc').
build_tests: If True, enables building test suites.
extra_args: Additional arguments to pass to cmake (e.g. -D flags).
Returns: Returns:
Return code from cmake. Return code from cmake.
@@ -698,6 +701,10 @@ def run_cmake_configure(build_type="Release", cc=None):
f"-DCMAKE_C_COMPILER={c_compiler}", f"-DCMAKE_C_COMPILER={c_compiler}",
f"-DCMAKE_CXX_COMPILER={cxx_compiler}", f"-DCMAKE_CXX_COMPILER={cxx_compiler}",
] ]
if build_tests:
args += ["-DXENIA_BUILD_TESTS=ON"]
if extra_args:
args += extra_args
ret = subprocess.call(args) ret = subprocess.call(args)
@@ -977,10 +984,14 @@ class PremakeCommand(Command):
*args, **kwargs) *args, **kwargs)
self.parser.add_argument( self.parser.add_argument(
"--cc", choices=["clang", "gcc", "msc"], default=None, help="Compiler toolchain") "--cc", choices=["clang", "gcc", "msc"], default=None, help="Compiler toolchain")
self.parser.add_argument(
"--build-tests", action="store_true", default=False,
help="Enables building test suites.")
def execute(self, args, pass_args, cwd): def execute(self, args, pass_args, cwd):
print("Running cmake configure...\n") print("Running cmake configure...\n")
ret = run_cmake_configure(cc=args["cc"]) ret = run_cmake_configure(cc=args["cc"],
build_tests=args["build_tests"])
print_status(ResultStatus.SUCCESS if not ret else ResultStatus.FAILURE) print_status(ResultStatus.SUCCESS if not ret else ResultStatus.FAILURE)
return ret return ret
@@ -1008,13 +1019,24 @@ class BaseBuildCommand(Command):
self.parser.add_argument( self.parser.add_argument(
"--no_premake", action="store_true", "--no_premake", action="store_true",
help="Skips running cmake configure before building.") help="Skips running cmake configure before building.")
self.parser.add_argument(
"--build-tests", action="store_true", default=False,
help="Enables building test suites.")
self.parser.add_argument(
"--cmake-define", dest="cmake_defines", action="append",
default=[], metavar="KEY=VALUE",
help="Pass a CMake define (e.g. --cmake-define CMAKE_CXX_FLAGS=/DUSE_BCRYPT_RSA).")
def execute(self, args, pass_args, cwd): def execute(self, args, pass_args, cwd):
config = args["config"].title() config = args["config"].title()
extra_args = [f"-D{d}" for d in args["cmake_defines"]]
if not args["no_premake"]: if not args["no_premake"]:
print("- running cmake configure...") print("- running cmake configure...")
run_cmake_configure(build_type=config, cc=args["cc"]) run_cmake_configure(build_type=config, cc=args["cc"],
build_tests=args["build_tests"],
extra_args=extra_args)
print("") print("")
print("- building (%s):%s..." % ( print("- building (%s):%s..." % (