Skip to content

Instantly share code, notes, and snippets.

Last active March 3, 2023 18:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save scivision/79e0dcd418e776d7ddbc12e32449f88c to your computer and use it in GitHub Desktop.
Read CMakeConfigureLog.yaml from Python
#!/usr/bin/env python3
read CMakeConfigureLog.yaml
from __future__ import annotations
import yaml
from pathlib import Path
import argparse
from pprint import pprint
def get_log(build_dir: Path) -> dict[str, str]:
"""read CMakeConfigureLog.yaml"""
log_file = Path(build_dir).expanduser() / "CMakeFiles/CMakeConfigureLog.yaml"
with open(log_file) as f:
return yaml.safe_load(f)
def get_events(log: dict[str, str]) -> list[dict[str, str]]:
"""get events from CMakeConfigureLog.yaml"""
return log["events"]
if __name__ == "__main__":
p = argparse.ArgumentParser()
p.add_argument("build_dir", help="build directory")
args = p.parse_args()
log = get_log(args.build_dir)
for event in get_events(log):
if event["kind"].startswith("try_compile"):
for e in event["backtrace"]:
# arbitrary filter criteria as CMake does several try_compile even for targetless project.
if e.startswith("CMakeLists.txt:") and e.endswith("try_compile)"):
r = event["buildResult"]
cmake_minimum_required(VERSION 3.26)
project(dummy LANGUAGES C CXX)
message(STATUS "try_compile: ${c_cpp_ok}")
int add_one(int x) {
return x + 1;
#include <cstdlib>
#include <cassert>
#include "my.h"
int main() {
assert(add_one(2) == 3);
#ifdef __cplusplus
extern "C" {
int add_one(int);
#ifdef __cplusplus
requires = ["setuptools>=61.0.0", "wheel"]
build-backend = "setuptools.build_meta"
requires-python = ">=3.8"
dependencies = ["PyYAML"]
line-length = 110
files = ["."]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment