Are FILE_SET CXX_MODULES and gcc-14 fully supported with cmake v3.30?

On GitHub CI with
Runner Image
Image: macos-14-arm64
Version: 20240701.9
Included Software: runner-images/images/macos/macos-14-arm64-Readme.md at macos-14-arm64/20240701.9 · actions/runner-images · GitHub
Image Release: Release macOS 14 arm64 (20240701) Image Update · actions/runner-images · GitHub

I see this error:

[44/170] Building CXX object _deps/fmt-build/CMakeFiles/fmt.dir/src/fmt.cc.o
FAILED: _deps/fmt-build/CMakeFiles/fmt.dir/src/fmt.cc.o _deps/fmt-build/CMakeFiles/fmt.dir/fmt.gcm 
/opt/homebrew/bin/g++-14 -DFMT_MODULE -I/Users/runner/work/cppstd20-code/build/_deps/fmt-src/include -isystem /opt/homebrew/Cellar/gcc/14.1.0_1/include/c++/14 -isystem /opt/homebrew/Cellar/gcc/14.1.0_1/include/c++/14/aarch64-apple-darwin23 -isystem /opt/homebrew/Cellar/gcc/14.1.0_1/include/c++/14/backward -isystem /opt/homebrew/Cellar/gcc/14.1.0_1/lib/gcc/current/gcc/aarch64-apple-darwin23/14/include -isystem /opt/homebrew/Cellar/gcc/14.1.0_1/lib/gcc/current/gcc/aarch64-apple-darwin23/14/include-fixed -isystem /Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include -isystem /Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks -g -std=c++20 -arch arm64 -isysroot /Applications/Xcode_15.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -fdiagnostics-color=always -fmodules-ts -MD -MT _deps/fmt-build/CMakeFiles/fmt.dir/src/fmt.cc.o -MF _deps/fmt-build/CMakeFiles/fmt.dir/src/fmt.cc.o.d -fmodules-ts -fmodule-mapper=_deps/fmt-build/CMakeFiles/fmt.dir/src/fmt.cc.o.modmap -MD -fdeps-format=p1689r5 -x c++ -o _deps/fmt-build/CMakeFiles/fmt.dir/src/fmt.cc.o -c /Users/runner/work/cppstd20-code/build/_deps/fmt-src/src/fmt.cc
/Users/runner/work/cppstd20-code/build/_deps/fmt-src/src/fmt.cc:82:8: internal compiler error: in core_vals, at cp/module.cc:6328
   82 | export module fmt;
      |        ^
Please submit a full bug report, with preprocessed source (by using -freport-bug).
See <https://github.com/Homebrew/homebrew-core/issues> for instructions.

On my local i386 iMAC it works?
bash-5.2$ uname -a

Darwin Claus-iMac.fritz.box 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:09:52 PDT 2024; root:xnu-10063.121.3~5/RELEASE_X86_64 x86_64 i386 Darwin

bash-5.2$

-- The CXX compiler identification is GNU 14.1.0
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/g++-14 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /usr/local/bin/git (found version "2.45.2")
-- CPM: Adding package project_options@0.29.0 (v0.29.0 at /Users/clausklein/.cache/CPM/project_options/0e3c3707685b2c6fe672bed1a7777cc774e65099)
-- The default CMAKE_C_STANDARD used by external targets and tools is not set yet. Using the latest supported C standard that is 90
-- /usr/local/bin/ccache found and enabled
-- Found Python: /Users/clausklein/.direnv/python-3.12/bin/python3.12 (found version "3.12.4") found components: Interpreter
-- CPM: Adding package Format.cmake@1.8.0 (v1.8.0 at /Users/clausklein/.cache/CPM/format.cmake/06265f78ebb8ff13ed1c78918ea1164580c48853)
-- CPM: Adding package PackageProject.cmake@1.11.0 (v1.11.0 at /Users/clausklein/.cache/CPM/packageproject.cmake/fc402989ee6e628476b3d8661f8f96774d89df74)
-- {fmt} version: 11.0.1
-- Build type: Release
-- CPM: Adding package fmt@11.0.1 (11.0.1 at /Users/clausklein/.cache/CPM/fmt/73b5ec45edbd92babfd91c3777a9e1ab9cac8238)
-- Configuring done (1.8s)
-- Generating done (0.2s)
-- Build files have been written to: /Users/clausklein/Workspace/cpp/cxx20/cppstd20-code/build/Release

Executing workflow step 2 of 5: build preset "Release"

[38/40] Generating CXX dyndep file lib/CMakeFiles/swap.dir/CXX.dd

Executing workflow step 3 of 5: test preset "Release"

Scanning /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stagedir/module/asio.cppm for CXX dependencies FAILED:

cmake -G Ninja -S asio-module -B build/asio -D CMAKE_INSTALL_PREFIX=/Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stagedir --fresh
-- The CXX compiler identification is GNU 14.1.0
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/g++-14 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (1.1s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/build/asio
cmake --build build/asio
ninja: no work to do.
cmake --install build/asio # --prefix stagedir
-- Install configuration: ""
cmake -G Ninja -S . -B build -D CMAKE_PREFIX_PATH=stagedir #XXX --fresh #XXX --debug-find-pkg=Asio
-- GNU_ROOT=/usr/local/Cellar/gcc/14.1.0_1
-- LLVM_LIBC_SOURCE=/Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stdlib
-- ASIO_ROOT is: /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stagedir
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/build
ninja -C build
ninja: Entering directory `build'
[1/20] Scanning /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/main2.cpp for CXX dependencies
g++-14: warning: /usr/local/Cellar/gcc/14.1.0_1/include/c++/14/x86_64-apple-darwin23: linker input file unused because linking not done
[2/20] Scanning /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stagedir/module/asio.cppm for CXX dependencies
FAILED: CMakeFiles/asio.dir/stagedir/module/asio.cppm.o.ddi 
/usr/local/bin/g++-14 -DASIO_HAS_SNPRINTF -DASIO_NO_DEPRECATED -DASIO_STANDALONE -I/Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stagedir/include -isystem /usr/local/Cellar/openssl@3/3.3.1/include -std=c++23 -std=c++23 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -stdlib=libc++ -isystem /usr/local/Cellar/gcc/14.1.0_1/include/c++/14 /usr/local/Cellar/gcc/14.1.0_1/include/c++/14/x86_64-apple-darwin23 -E -x c++ /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stagedir/module/asio.cppm -MT CMakeFiles/asio.dir/stagedir/module/asio.cppm.o.ddi -MD -MF CMakeFiles/asio.dir/stagedir/module/asio.cppm.o.ddi.d -fmodules-ts -fdeps-file=CMakeFiles/asio.dir/stagedir/module/asio.cppm.o.ddi -fdeps-target=CMakeFiles/asio.dir/stagedir/module/asio.cppm.o -fdeps-format=p1689r5 -o CMakeFiles/asio.dir/stagedir/module/asio.cppm.o.ddi.i
In file included from /usr/local/Cellar/gcc/14.1.0_1/include/c++/14/version:36,
                 from /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stagedir/include/asio/detail/config.hpp:30,
                 from /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stagedir/include/asio/any_completion_executor.hpp:18,
                 from /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stagedir/include/asio.hpp:18,
                 from /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stagedir/module/asio.cppm:3:
/usr/local/Cellar/gcc/14.1.0_1/include/c++/14/bits/version.h:49:10: fatal error: bits/c++config.h: No such file or directory
   49 | #include <bits/c++config.h>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
[3/20] Scanning /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/main7.cpp for CXX dependencies
g++-14: warning: /usr/local/Cellar/gcc/14.1.0_1/include/c++/14/x86_64-apple-darwin23: linker input file unused because linking not done
[4/20] Scanning /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/main3.cpp for CXX dependencies
g++-14: warning: /usr/local/Cellar/gcc/14.1.0_1/include/c++/14/x86_64-apple-darwin23: linker input file unused because linking not done
[5/20] Scanning /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/main6.cpp for CXX dependencies
g++-14: warning: /usr/local/Cellar/gcc/14.1.0_1/include/c++/14/x86_64-apple-darwin23: linker input file unused because linking not done
[6/20] Scanning /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/main.cpp for CXX dependencies
g++-14: warning: /usr/local/Cellar/gcc/14.1.0_1/include/c++/14/x86_64-apple-darwin23: linker input file unused because linking not done
[7/20] Scanning /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/main4.cpp for CXX dependencies
g++-14: warning: /usr/local/Cellar/gcc/14.1.0_1/include/c++/14/x86_64-apple-darwin23: linker input file unused because linking not done
[8/20] Scanning /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/main5.cpp for CXX dependencies
g++-14: warning: /usr/local/Cellar/gcc/14.1.0_1/include/c++/14/x86_64-apple-darwin23: linker input file unused because linking not done
ninja: build stopped: subcommand failed.
make: *** [all] Error 1
bash-5.2$ 
``

I need to set include path to c++ headers?

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14.0)
        set(USE_MODULES TRUE)
        if(DEFINED ENV{GNU_ROOT})
            message(STATUS "GNU_ROOT=$ENV{GNU_ROOT}")
            #FIXME: include_directories(BEFORE SYSTEM $ENV{GNU_ROOT}/include/c++/14)
            add_compile_options(-I $ENV{GNU_ROOT}/include/c++/14)
            add_compile_options(-isystem $ENV{GNU_ROOT}/include/c++/14/x86_64-apple-darwin23)
        endif()
endif()

@ben.boeckel Is this a cmake or a gcc problem?

CMake know the include paths, but it is not used and can’t be added:

CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES=/usr/local/Cellar/gcc/14.1.0_1/include/c++/14;/usr/local/Cellar/gcc/14.1.0_1/include/c++/14/x86_64-apple-darwin23;/usr/local/Cellar/gcc/14.1.0_1/include/c++/14/backward;/usr/local/Cellar/gcc/14.1.0_1/lib/gcc/current/gcc/x86_64-apple-darwin23/14/include;/usr/local/Cellar/gcc/14.1.0_1/lib/gcc/current/gcc/x86_64-apple-darwin23/14/include-fixed;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/System/Library/Frameworks

@craig.scott do you have any idea?

Can you reproduce the problem outside of CMake?

-isystem /opt/homebrew/Cellar/gcc/14.1.0_1/include/c++/14

This seems…wrong (as with other similar paths I see). The compiler should be searching this path on its own already. Listing it explicitly could mess up the search order.

The crash is definitely a GCC problem though…a better error message about the actual problem being encountered would be nice.

Perhaps it is was to much?

I tried to compile the clang++ std module with g+±14.

I give it up for now.

There are also to much differences with native build and CI builds:

see Add GNUmakefile and CI script to help fix problems on OSX with clang++-18 and cmake v3.30 by ClausKlein · Pull Request #1 · anarthal/boost-modules-bench · GitHub

Oh, that is certainly something that is likely to make the compiler sad.

And sometime CMake too:

cmake -G Ninja -S . -B build -D BUILD_SHARED_LIBS=YES -D CMAKE_PREFIX_PATH=/Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stagedir --fresh #XXX --debug-find-pkg=Asio
-- The CXX compiler identification is Clang 18.1.8
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenSSL: /usr/local/Cellar/openssl@3/3.3.1/lib/libcrypto.dylib (found version "3.3.1")
-- LLVM_ROOT=/usr/local/Cellar/llvm/18.1.8
-- CMAKE_CXX_COMPILER_IMPORT_STD=23
-- USE_MODULES=TRUE
-- LLVM_LIBC_SOURCE=/usr/local/Cellar/llvm/18.1.8/share/libc++/v1
-- Looking for snprintf
-- Looking for snprintf - found
-- Looking for sprintf_s
-- Looking for sprintf_s - not found
-- HAS_STDLIB_MODULES=stdlib
-- ASIO_ROOT is: /Users/clausklein/Workspace/cpp/cxx20/boost-modules-bench/stagedir
-- Configuring done (2.8s)
CMake Error in CMakeLists.txt:
  The "CXX_MODULE_STD" property on the target "stdlib" requires that the
  "__CMAKE::CXX23" target exist, but it was not provided by the toolchain.
  Reason:

    Experimental `import std` support not enabled when detecting toolchain; it must be set before `CXX` is enabled (usually a `project()` call)

I need to add this:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4e5e8b6..00424b8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -84,7 +84,7 @@ endif()
 # Build the stdlib module
 function(add_stdlib_module NAME)
     add_library(${NAME})
-    # add_library(__CMAKE::CXX23 ALIAS ${NAME})
+    add_library(__CMAKE::CXX23 ALIAS ${NAME})
     # cmake-format: off
     target_sources(${NAME} PUBLIC
         FILE_SET CXX_MODULES

What is the effect of
CMAKE_CXX_COMPILER_IMPORT_STD=23 ?