Read CMakeConfigureLog.yaml from Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"] | |
pprint(r) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.26) | |
project(dummy LANGUAGES C CXX) | |
try_compile(c_cpp_ok | |
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lib.c ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp | |
CMAKE_FLAGS -DINCLUDE_DIRECTORIES=${CMAKE_CURRENT_SOURCE_DIR} | |
) | |
message(STATUS "try_compile: ${c_cpp_ok}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int add_one(int x) { | |
return x + 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <cassert> | |
#include "my.h" | |
int main() { | |
assert(add_one(2) == 3); | |
return EXIT_SUCCESS; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
int add_one(int); | |
#ifdef __cplusplus | |
} | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[build-system] | |
requires = ["setuptools>=61.0.0", "wheel"] | |
build-backend = "setuptools.build_meta" | |
[project] | |
requires-python = ">=3.8" | |
dependencies = ["PyYAML"] | |
[tool.black] | |
line-length = 110 | |
[tool.mypy] | |
files = ["."] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment