Although it is a toy example (and probably incorrect) it compiles and runs fine. I tried to achieve the same results by writing a CMakeLists.txt and use cmake 3.28, but I failed. Is this doable with cmake 3.28/gcc14 (master) ?
Thanks for taking an interest in my question. Yes I’ve read the post you mentioned and it mentions that only named modules are supported. I think it doesn’t support my use case although I may be wrong.
cmake_minimum_required(VERSION 3.28)
project(std_module_example CXX)
# Turning off extensions avoids and issue with the clang 16 compiler
# clang 17 and greater can avoid this setting
set(CMAKE_CXX_EXTENSIONS OFF)
# Set the version of C++ for the project
set(CMAKE_CXX_STANDARD 20)
# Create a library
add_library(foo)
# Add the module file to the library
target_sources(foo
PUBLIC
FILE_SET CXX_MODULES FILES
foo.cxx
)
# Create an executable
add_executable(hello main.cxx)
# Link to the library foo
target_link_libraries(hello foo)
Then I updated the CMakeLists.txt to take into account mystd.o but when I run ninja I get the following error:
main.cxx:2:1:
mystd: error: failed to read compiled module: Unknown CMI mapping
mystd: note: imports must be built before being imported
mystd: fatal error: returning to the gate for a mechanical issue