C++20 module is broken (missing transitive usage) when the files are listed in a certain order
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.
For the reference, here's the project in a zip file: test-module.zip