# (c) 2025 by Stephan Menzel # Licensed under the Apache License, Version 2.0. # See attached file LICENSE for full details import math import multiprocessing import os from contextlib import contextmanager from pathlib import Path cmake_config_flag = "" cmake_toolset = "" boost_toolset = "" boost_bootstrap_toolset = "" build_dir = Path("raw") install_prefix = Path(R"C:\devel\3rd_party") rebuild = False # Hard wire this. According to Azure docs here: # https://github.com/MicrosoftDocs/azure-devops-docs/blob/main/docs/pipelines/agents/hosted.md # they run with 2 cores, which gives us a suitable parallel count of 3 # num_cores = 3 if run_in_buildpipeline else 6 # doesn't seem to work run_in_buildpipeline = "BUILD_ARTIFACTSTAGINGDIRECTORY" in os.environ num_cores = 3 if run_in_buildpipeline else 6 if os.name == "posix": cmake_toolset = "" lib_wildcard = "*.a" dll_wildcard = "*.so" zlib_static_lib_name = "libz.a" elif os.name == "nt": # Windows cmake_toolset = "-T v143" boost_toolset = "msvc-" + cmake_toolset[-3:-1] + "." + cmake_toolset[-1] boost_bootstrap_toolset = "vc" + cmake_toolset[-3:-1] + cmake_toolset[-1] lib_wildcard = "*.lib" dll_wildcard = "*.dll" zlib_static_lib_name = "zlibstatic.lib" else: print("Unsupported OS") exit(1) cpp_standard = "23" number_of_jobs = max(1, math.floor(multiprocessing.cpu_count())) cmake_global_flags = [ ("BUILD_SHARED_LIBS:BOOL", "OFF"), ("BUILD_TESTING:BOOL", "OFF"), ("CMAKE_CXX_STANDARD_REQUIRED:BOOL", "ON"), ("CMAKE_MSVC_RUNTIME_LIBRARY:STRING", "\"MultiThreadedDLL\""), ("CMAKE_POSITION_INDEPENDENT_CODE:BOOL", "ON"), ("CMAKE_CONFIGURATION_TYPES:STRING", "Release;RelWithDebInfo"), # ("CMAKE_BUILD_TYPE:STRING", "Release") ] def set_global_rebuild(new_rebuild: bool = False) -> None: global rebuild rebuild = new_rebuild def set_global_install_prefix(new_prefix: Path) -> None: global install_prefix install_prefix = new_prefix def set_global_build_dir(new_build_dir: Path) -> None: global build_dir build_dir = new_build_dir def switch_shared_libs(shared: bool) -> None: global cmake_global_flags for i, (k, v) in enumerate(cmake_global_flags): if k == "BUILD_SHARED_LIBS:BOOL": cmake_global_flags[i] = ("BUILD_SHARED_LIBS:BOOL", "ON") if shared else ("BUILD_SHARED_LIBS:BOOL", "OFF") @contextmanager def temporarily_set_shared(): """Create a scope in which we build dynamic""" global cmake_global_flags idx = 0 for idx, (k, v) in enumerate(cmake_global_flags): if k == "BUILD_SHARED_LIBS:BOOL": cmake_global_flags[idx] = ("BUILD_SHARED_LIBS:BOOL", "ON") break try: yield # control goes to the inner `with` block finally: cmake_global_flags[idx] = ("BUILD_SHARED_LIBS:BOOL", "OFF")