65def build_cpp_test(sources_dir: Path,
68 build_subdir: Optional[str] =
None) -> Path:
69 """Configure + build a C++ integration test target, returning the binary.
71 * ``sources_dir``: root provided by ``cosim_test`` (contains ``generated/``).
72 * ``target``: CMake target name (e.g. ``loopback_test``).
73 * ``header_subdir``: subdirectory under the include root where the generated
74 headers are copied (e.g. ``"loopback"`` or ``"test_codegen"``).
75 * ``build_subdir``: name for the build directory under ``sources_dir``.
76 Defaults to ``target``.
78 The configure step is skipped when the build directory already exists;
79 ``cmake --build`` always runs so that CMake's own dependency tracking
80 picks up any source or generated-header changes.
84 if build_subdir
is None:
86 build_dir = sources_dir / build_subdir
87 binary = build_dir / target
89 runtime_root = get_runtime_root()
90 include_dir = sources_dir /
"cpp_include"
91 generated_dir = include_dir / header_subdir
93 if not build_dir.exists():
94 generated_dir.mkdir(parents=
True, exist_ok=
True)
96 codegen_src = sources_dir /
"generated"
97 if codegen_src.exists():
98 for item
in codegen_src.iterdir():
100 shutil.copy(item, generated_dir)
102 result = subprocess.run(
109 f
"-DLOOPBACK_GENERATED_DIR={include_dir}",
110 f
"-DESI_RUNTIME_ROOT={runtime_root}",
115 assert result.returncode == 0, (
116 f
"cmake configure failed (rc={result.returncode}):\n"
117 f
"--- stdout ---\n{result.stdout}\n"
118 f
"--- stderr ---\n{result.stderr}")
120 result = subprocess.run(
122 str(build_dir),
"--target", target],
126 assert result.returncode == 0, (
127 f
"cmake build failed (rc={result.returncode}):\n"
128 f
"--- stdout ---\n{result.stdout}\n"
129 f
"--- stderr ---\n{result.stderr}")