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.
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.
I just tried both CMake 4.0.2 and 4.2.3 with correct UUIDs from needed tag tree but still have the same issue. And I set it before project as said in docs.
I use it like this:
I also tried to set it inside library.cmake in the function begining . Actually, it builds ok even without CMAKE_CXX_MODULE_STD so I’m not sure do I really need it?
Well, when you do this, you’re telling the compiler how to satisfy import std without CMake knowing about it. Not having to do this is kind of the point of the import std feature in CMake.