diff --git a/src/cppboot/generate/cmake_files.py b/src/cppboot/generate/cmake_files.py index c00f3a8..e2ad060 100644 --- a/src/cppboot/generate/cmake_files.py +++ b/src/cppboot/generate/cmake_files.py @@ -418,11 +418,17 @@ def _src_cmake(ctx: _Context) -> str: def _version_src_cmake(ctx: _Context) -> str: if ctx.with_modules: + # BASE_DIRS must include the generated .cppm path; CMake rejects FILE_SET + # members outside the set's base directories (often defaults to this dir). return f"""\ # version component (C++20 module) — generated from cmake/version.cppm.in + VERSION. +# Generated unit lives under the build tree; BASE_DIRS must cover that path. target_sources(${{PROJECT_NAME}}_lib PUBLIC - FILE_SET CXX_MODULES FILES + FILE_SET CXX_MODULES + BASE_DIRS + ${{{ctx.macro}_GENERATED_DIR}} + FILES ${{{ctx.macro}_GENERATED_DIR}}/version.cppm ) """ diff --git a/tests/integration/test_generate.py b/tests/integration/test_generate.py index a371021..003aaa6 100644 --- a/tests/integration/test_generate.py +++ b/tests/integration/test_generate.py @@ -107,6 +107,13 @@ def test_modules_layout(tmp_root: Path) -> None: assert not (root / "cmake" / "version.hpp.in").exists() cmake = (root / "CMakeLists.txt").read_text(encoding="utf-8") assert "3.28" in cmake + version_cmake = (root / "src" / "version" / "CMakeLists.txt").read_text(encoding="utf-8") + assert "FILE_SET CXX_MODULES" in version_cmake + assert "BASE_DIRS" in version_cmake + assert "version.cppm" in version_cmake + main = (root / "src" / "main.cpp").read_text(encoding="utf-8") + assert "import " in main + assert "#include" not in main or "CLI" in main # CLI11 still classic header def test_shared_library(tmp_root: Path) -> None: