Hi, now Fedora 40 was shipped with CMAKE >= 3.28 I thought it’s time to use the C++20 modules feature. But I am having problems to use it.
First after some research I found out it is not allowed any more to use e.g.
“-fmodules-ts” compiler switches for clang. This is because it would enable a non-standard modules implementation. Good to know.
Second I found out I had to modify my CMakeLists.txt like
target_sources(
${CMAKE_PROJECT_NAME}
PUBLIC
${SOURCES}
${HEADERS}
PUBLIC
FILE_SET CXX_MODULES
FILES
${MODULES}
)
Good to know also. With this I can use modules in my application and compile it. But now I am having several libraries this application is using. So I thought to use a module for testing purposes in one of the libs also. But there are two problems I am facing. I can compile the lib without problems but if it comes to compile the application depending on it I get the following error message:
“fatal error: module ‘XXXX’ not found”
Ok, so I thought maybe throwing all .pcm files in one folder “Modules” and provide the compiler switch
-fprebuilt-module-path="${PROJECT_PATH}/Modules""
But this feels somehow wrong and surely is non standard c++ conform. It’s clang specific. So I thought there must be a standard way of doing so?
Also there is another problem related to this. I can specify the folder for the lookup of the pcm files. But how the hell one can tell CMAKE to but the pcm files to it? For now the pcm files are put in the “…/CMakeFiles/objlib.dir” folder.
And finally if the paths in the target_sources FILES section containing “…” like “My/Path/…/…/to/the/file.ixx”. There appears an error:
CMake Error in CMakeLists.txt:
Target "objlib" has source file
/My/Path/../../../to/File.ixx
in a "FILE_SET TYPE CXX_MODULES" but it is not scheduled for compilation.
Without the “…/…/” it compiles.
So how to avoid these problems? What is the CMAKE way to do it correctly? Or is it still in 2024 that C++ modules are broken?