C++20 module seems to be broken (missing transitive usage) in a very specific case

I am learning to use C++20 module with CMake 2.38.0-rc4, and I noticed a possible bug in CMake.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.28.0)

project(MyLib LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)

add_library(my-lib)

target_sources(my-lib PRIVATE FILE_SET CXX_MODULES FILES
    mod1.cpp
    mod3.cpp # import mod2
    mod4.cpp # import mod2
    mod2.cpp # import mod1
    mod5.cpp # import mod4
    mod6.cpp # import mod5
)

All module units are empty except for the imports as indicated in the comments above.

When compiling this project against Clang, I got

[13/14] Building CXX object CMakeFiles/my-lib.dir/mod6.cpp.o
/mnt/d/test/test-module/mod6.cpp:2:1: warning: it is deprecated to read module 'mod1' implicitly; it is going to be removed in clang 18; consider to specify the dependencies explicitly [-Wread-modules-implicitly]
    2 | import mod5;
      | ^
1 warning generated.
warning: it is deprecated to read module 'mod1' implicitly; it is going to be removed in clang 18; consider to specify the dependencies explicitly [-Wread-modules-implicitly]
1 warning generated.

It seems that CMake forgets to tell Clang the location of mod1.pcm when compiling mod6.cpp.

Note that the order of files in target_souces is significant. The warning might not occur if the files are listed in a different order.

Does this sound like a bug of CMake? Is this a known bug?

For the reference, here are the contents of `mod1.cpp` through `mod6.cpp`

mod1.cpp:

export module mod1;

mod2.cpp:

export module mod2;
import mod1;

mod3.cpp:

export module mod3;
import mod2;

mod4.cpp:

export module mod4;
import mod2;

mod5.cpp:

export module mod5;
import mod4;

mod6.cpp:

export module mod6;
import mod5;

It does sound like a bug; not known before.

I’m guessing that we need to do 2 full passes over the modules in order to support transitive module tracking properly. Thanks for the test case.

Thanks; do you mind filing an issue to track this?