Skip to content

Conversation

@LiangHuDream
Copy link
Contributor

@LiangHuDream LiangHuDream commented Oct 17, 2025

[fix] error: module file CMakeFiles/__cmake_cxx23.dir/std.pcm cannot be loaded due to a configuration mismatch with the current compilation #4279
What I changed

The modifications I made (specific and traceable)
Edit file: CMakeLists.txt
In the manual pre-compilation module path (CMake does not use FILE_SET to manage modules), ensure that CMake's automatic module scanning is not triggered - to avoid build failures caused by CMake requiring the compiler to support import-graph scanning.
In scenarios where it is not safe to use CMake's FILE_SET module support (such as GCC + Ninja), FMT_USE_CMAKE_MODULES is disabled, causing the build to revert to manual pre-compilation/non-FILE_SET paths.
In environments where module support cannot be reliably provided (GCC's several versions), if the user requests -DFMT_MODULE=ON, FMT_MODULE will be automatically set back to OFF (and a warning will be printed) to avoid compiler internal errors (cc1plus segment errors) caused by -fmodules-ts.
In the manual module branch as the target, CXX_SCAN_FOR_MODULES (target property) is turned off, and CMAKE_CXX_SCAN_FOR_MODULES (cache) is globally turned off under GCC to ensure CMake no longer attempts to automatically scan.
Add diagnostic output to enable seeing the decision of FMT_USE_CMAKE_MODULES during configure (helpful for subsequent debugging).
(Notes) I did not modify the public API or source code functionality; only adjusted the CMake configuration logic, with minor and low-risk modifications.

image

@vitaut
Copy link
Contributor

vitaut commented Oct 17, 2025

This looks similar to #4580. In the future please update the PR instead of closing and creating a new one.

@LiangHuDream
Copy link
Contributor Author

This looks similar to #4580. In the future please update the PR instead of closing and creating a new one.

OK, thank you for your suggestion.

@vitaut
Copy link
Contributor

vitaut commented Oct 18, 2025

Could you provide an example demonstrating the problem?

@LiangHuDream
Copy link
Contributor Author

LiangHuDream commented Oct 25, 2025

Could you provide an example demonstrating the problem?

It's ok, thank you for checking the code.

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the logic to set std flag make sense. Please move the other changes to a separate PR and add more context.

Comment on lines +265 to +276
# Decide whether to use CMake's FILE_SET-based module support. We only enable
# it when the generator and CMake version support it and the compiler is not
# GCC (GCC lacks import-graph discovery in many setups). This check must run
# after project() so CMAKE_CXX_COMPILER_ID is available.
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.28 AND
CMAKE_GENERATOR STREQUAL "Ninja" AND
NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(FMT_USE_CMAKE_MODULES TRUE)
else()
set(FMT_USE_CMAKE_MODULES FALSE)
endif()
message(STATUS "FMT_USE_CMAKE_MODULES = ${FMT_USE_CMAKE_MODULES}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better not to split the logic to set FMT_USE_CMAKE_MODULES.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants