""" CMake abstraction """ import os import sys import subprocess __all__ = [ 'cmake_configure', 'cmake_build', 'cmake_install', 'cmake_uninstall', ] #--- # Pulbic #--- def cmake_configure(prefix_build, prefix_src): """ Abstract cmake configuration """ toolchain_flag = '' if toolchain_path := os.environ.get('VXSDK_HOOK_CMAKE_TOOLCHAIN'): toolchain_flag = f"-DCMAKE_TOOLCHAIN_FILE={toolchain_path}" shell_cmd = f"cmake {toolchain_flag} -B {prefix_build} -S {prefix_src}" return subprocess.run(shell_cmd.split(), check=False).returncode def cmake_build(prefix_build, verbose): """ Abstract cmake configuration """ shell_cmd = f"cmake --build {prefix_build}" if verbose: shell_cmd += ' --verbose' return subprocess.run(shell_cmd.split(), check=False).returncode def cmake_install(prefix_build, verbose): """ Abstract cmake installation """ shell_cmd = f"cmake --install {prefix_build}" if verbose: shell_cmd += ' --verbose' return subprocess.run(shell_cmd.split(), check=False).returncode def cmake_uninstall(prefix_build, verbose): """ Abstract cmake uninstall Note that CMake does not offert a easy way to uninstall project, but it generate a file which contains all installed pathname """ manifile = f"{prefix_build}/install_manifest.txt" if not os.path.exists(manifile): print('project not installed') return -1 retcode = 0 with open(manifile, 'r', encoding='utf8') as manifest: for pathname in manifest.readlines(): pathname = pathname.strip() if not os.path.exists(pathname): continue if verbose: print("-- Removing {pathname}") ret = subprocess.run(f"rm {pathname}".split(), check=False) if ret.returncode == 0: continue print("warning : error during removing file", file=sys.stderr) retcode -= 1 return retcode