mirror of
https://github.com/fmtlib/fmt.git
synced 2026-02-11 20:59:58 +08:00
[fix] error: module file CMakeFiles/__cmake_cxx23.dir/std.pcm cannot be loaded due to a configuration mismatch with the current compilation #4279
This commit is contained in:
parent
4a4876dd62
commit
452dd2b9f8
@ -81,6 +81,15 @@ function(add_module_library name)
|
|||||||
# `std` is affected by CMake options and may be higher than C++20.
|
# `std` is affected by CMake options and may be higher than C++20.
|
||||||
get_target_property(std ${name} CXX_STANDARD)
|
get_target_property(std ${name} CXX_STANDARD)
|
||||||
|
|
||||||
|
# Respect CMAKE_CXX_EXTENSIONS when forming the -std flag used to
|
||||||
|
# precompile modules. A mismatch between -std=gnu++<ver> and -std=c++<ver>
|
||||||
|
# can cause "configuration mismatch" errors when loading .pcm files.
|
||||||
|
if (CMAKE_CXX_EXTENSIONS)
|
||||||
|
set(std_flag "-std=gnu++${std}")
|
||||||
|
else()
|
||||||
|
set(std_flag "-std=c++${std}")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
set(pcms)
|
set(pcms)
|
||||||
foreach (src ${sources})
|
foreach (src ${sources})
|
||||||
@ -94,15 +103,15 @@ function(add_module_library name)
|
|||||||
# Use an absolute path to prevent target_link_libraries prepending -l
|
# Use an absolute path to prevent target_link_libraries prepending -l
|
||||||
# to it.
|
# to it.
|
||||||
set(pcms ${pcms} ${CMAKE_CURRENT_BINARY_DIR}/${pcm})
|
set(pcms ${pcms} ${CMAKE_CURRENT_BINARY_DIR}/${pcm})
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${pcm}
|
OUTPUT ${pcm}
|
||||||
COMMAND ${CMAKE_CXX_COMPILER}
|
COMMAND ${CMAKE_CXX_COMPILER}
|
||||||
-std=c++${std} -x c++-module --precompile -c
|
${std_flag} -x c++-module --precompile -c
|
||||||
-o ${pcm} ${CMAKE_CURRENT_SOURCE_DIR}/${src}
|
-o ${pcm} ${CMAKE_CURRENT_SOURCE_DIR}/${src}
|
||||||
"-I$<JOIN:$<TARGET_PROPERTY:${name},INCLUDE_DIRECTORIES>,;-I>"
|
"-I$<JOIN:$<TARGET_PROPERTY:${name},INCLUDE_DIRECTORIES>,;-I>"
|
||||||
# Required by the -I generator expression above.
|
# Required by the -I generator expression above.
|
||||||
COMMAND_EXPAND_LISTS
|
COMMAND_EXPAND_LISTS
|
||||||
DEPENDS ${src})
|
DEPENDS ${src})
|
||||||
endforeach ()
|
endforeach ()
|
||||||
|
|
||||||
# Add .pcm files as sources to make sure they are built before the library.
|
# Add .pcm files as sources to make sure they are built before the library.
|
||||||
@ -112,11 +121,12 @@ function(add_module_library name)
|
|||||||
set(obj ${pcm_we}.o)
|
set(obj ${pcm_we}.o)
|
||||||
# Use an absolute path to prevent target_link_libraries prepending -l.
|
# Use an absolute path to prevent target_link_libraries prepending -l.
|
||||||
set(sources ${sources} ${pcm} ${CMAKE_CURRENT_BINARY_DIR}/${obj})
|
set(sources ${sources} ${pcm} ${CMAKE_CURRENT_BINARY_DIR}/${obj})
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${obj}
|
OUTPUT ${obj}
|
||||||
COMMAND ${CMAKE_CXX_COMPILER} $<TARGET_PROPERTY:${name},COMPILE_OPTIONS>
|
COMMAND ${CMAKE_CXX_COMPILER} ${std_flag} -c -o ${obj} ${pcm}
|
||||||
-c -o ${obj} ${pcm}
|
"-I$<JOIN:$<TARGET_PROPERTY:${name},INCLUDE_DIRECTORIES>,;-I>"
|
||||||
DEPENDS ${pcm})
|
COMMAND_EXPAND_LISTS
|
||||||
|
DEPENDS ${pcm})
|
||||||
endforeach ()
|
endforeach ()
|
||||||
endif ()
|
endif ()
|
||||||
target_sources(${name} PRIVATE ${sources})
|
target_sources(${name} PRIVATE ${sources})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user