import std appears to be broken in release 4.0.2

I attempted to upgrade to 4.0.2 but found that my modules projects using import std are now unbuildable. I’m using Visual Studio Community 17.15.0 Preview 4.0 + Ninja.

After fiddling across a large-scale project with a number of C++ module deps, I went ahead and tried a minimal project to confirm, and it too was unbuildable. The CMakeLists for the minimal project looks like this:

cmake_minimum_required(VERSION 4.0.2)
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444")

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_MODULE_STD 1)
project(minimal LANGUAGES CXX)

add_executable(minimal)
target_sources(minimal
        PUBLIC
        FILE_SET cxx_modules TYPE CXX_MODULES FILES
        main.ixx
)

I fiddled with various configurations (one call before another - i.e. sets before project(...) and after it, - different hashes for CMAKE_EXPERIMENTAL_CXX_IMPORT_STD, etc.). Regardless, the result is always this error:

CMake Error in CMakeLists.txt:
  The "CXX_MODULE_STD" property on the target "minimal" 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)

Rolling back to 3.31.7 is the only way I could get things to build again.

The UUID for 4.0.2 is different (because the set of features changed). It is a9e1cf81-9932-4810-974b-6eccaf14e457 for 4.0.2.

That was the problem. Where is the UUID for the current version documented?

The UUID I was using was the one on this page: CMake/Help/dev/experimental.rst at master · Kitware/CMake

But that one is apparently out of date.

In the Help/dev/experimental.rst file of the version you’re using (change master to v4.0.1 in the URL). If you build master, it is correct. It was most recently bumped because CMake learned to support clang -stdlib=libstdc++ and import std;. 4.0.1 lacks it, so it uses an older UUID.