55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
# (c) 2025 by Stephan Menzel
|
|
# Licensed under the Apache License, Version 2.0.
|
|
# See attached file LICENSE for full details
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from build_functions.build_utils import file_and_console_log, run_in_shell
|
|
from common.directory_helpers import pushd
|
|
import common.settings
|
|
from package.package_info import PackageInfo
|
|
|
|
|
|
def cmake_build_install(local_directory, package_info: PackageInfo, cmake_args: list[tuple[str, str]] = []):
|
|
argstr = ""
|
|
|
|
# Create flags string out of args tuples
|
|
for key, value in common.settings.cmake_global_flags:
|
|
slash_value = value.replace("\\", "/")
|
|
argstr += f"-D{key}={slash_value} "
|
|
|
|
for key, value in cmake_args:
|
|
slash_value = value.replace("\\", "/")
|
|
argstr += f"-D{key}={slash_value} "
|
|
|
|
argstr += f"-DCMAKE_CXX_STANDARD:STRING={common.settings.cpp_standard} "
|
|
|
|
build_folder = '_build'
|
|
with pushd(local_directory):
|
|
install_prefix = package_info.install_location()
|
|
|
|
if not os.path.isdir(build_folder):
|
|
os.makedirs(build_folder)
|
|
with pushd(build_folder):
|
|
if not common.settings.rebuild and Path("built_and_installed.txt").exists():
|
|
file_and_console_log("already built, exiting")
|
|
return install_prefix
|
|
|
|
run_in_shell(f"cmake .. {common.settings.cmake_toolset} -DCMAKE_CONFIGURATION_TYPES:STRING=Release "
|
|
f"{argstr} -DCMAKE_INSTALL_PREFIX={install_prefix}")
|
|
|
|
run_in_shell(f'cmake --build . --config Release --target INSTALL --parallel {common.settings.num_cores}')
|
|
|
|
with open("built_and_installed.txt", "w") as lockfile:
|
|
lockfile.write(f"built release")
|
|
|
|
# This stopped working somehow...
|
|
# if run_in_buildpipeline:
|
|
# shutil.rmtree(local_directory)
|
|
|
|
return install_prefix
|
|
|
|
def assemble_prefix_path(packages: list[PackageInfo]) -> str:
|
|
paths = [str(pkg.install_location()) for pkg in packages]
|
|
return ";".join(paths) |