Recently I've decided to "modularize" my library. No success. Here is the repo where you can find CMakeLists.txt & CMakePresets.json: kissra (GitHub)
The issue is that CMake cannot find standard std.cppm primary module interface - it is trying to find it in a wrong directory (/lib/share/libc++/v1) whereas the LLVM toolset is in fact installed in /usr/lib/llvm-21/. And I haven't figured out how to force CMake search PMIs in a different directory.
Here is the error I'm getting:
-- Configuring done (7.1s)
CMake Error at build/debug/CMakeFiles/4.2.1/CMakeCXXCompiler.cmake:111 (target_sources):
Cannot find source file: /lib/share/libc++/v1/std.cppm
Call Stack (most recent call first):
CMakeLists.txt:8 (project)
I've looked into the generated CMake scripts in the build directory and found this (CMakeCXXCompiler.cmake):
### Imported target for C++26 standard library
if (NOT TARGET "__CMAKE::CXX26")
if (NOT TARGET "__cmake_cxx26")
add_library(__cmake_cxx26 STATIC)
target_sources(__cmake_cxx26 INTERFACE "$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>:$<TARGET_OBJECTS:__cmake_cxx26>>")
set_property(TARGET __cmake_cxx26 PROPERTY EXCLUDE_FROM_ALL 1)
set_property(TARGET __cmake_cxx26 PROPERTY CXX_SCAN_FOR_MODULES 1)
set_property(TARGET __cmake_cxx26 PROPERTY CXX_MODULE_STD 0)
target_compile_features(__cmake_cxx26 PUBLIC cxx_std_26)
target_compile_options(__cmake_cxx26 PRIVATE -Wno-reserved-module-identifier)
target_include_directories(__cmake_cxx26 PRIVATE "/lib/x86_64-linux-gnu/../share/libc++/v1")
target_sources(__cmake_cxx26
PUBLIC
FILE_SET std TYPE CXX_MODULES
BASE_DIRS "/lib/x86_64-linux-gnu/../share/libc++/v1"
FILES "/lib/x86_64-linux-gnu/../share/libc++/v1/std.cppm" "/lib/x86_64-linux-gnu/../share/libc++/v1/std.compat.cppm")
endif ()
add_library(__CMAKE::CXX26 ALIAS __cmake_cxx26)
endif ()
if (TARGET "__CMAKE::CXX26")
list(APPEND CMAKE_CXX_COMPILER_IMPORT_STD "26")
endif ()
As you can see, CMake is trying to find PMIs in /lib/share/libc++/v1. Is there a way to customize the location for PMIs by setting some obscure global CMake variable in CMakePreset.json file?