# Distributing C++20 modules as source

**URL:** https://discourse.cmake.org/t/distributing-c-20-modules-as-source/13246
**Category:** Usage
**Created:** [December 21, 2024, 12:23pm UTC](https://discourse.cmake.org/t/distributing-c-20-modules-as-source/13246 "2024-12-21T12:23:14Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [November 30, 2025, 5:08pm UTC](https://discourse.cmake.org/t/distributing-c-20-modules-as-source/13246/4 "2025-11-30T17:08:04Z")

</div>

### OK, `import std;` need more love (CMAKE\_CXX\_MODULE\_STD=ON), then it works:

```makefile
# Standard stuff

.SUFFIXES:

MAKEFLAGS+= --no-builtin-rules # Disable the built-in implicit rules.
# MAKEFLAGS+= --warn-undefined-variables # Warn when an undefined variable is referenced.
# MAKEFLAGS+= --include-dir=$(CURDIR)/conan # Search DIRECTORY for included makefiles (*.mk).

export hostSystemName=$(shell uname)

ifeq (${hostSystemName},Darwin)
  export LLVM_PREFIX=$(shell brew --prefix llvm)
  export LLVM_DIR=$(shell realpath ${LLVM_PREFIX})
  export PATH:=${LLVM_DIR}/bin:${PATH}

  # export CMAKE_CXX_STDLIB_MODULES_JSON=${LLVM_DIR}/lib/c++/libc++.modules.json
  # export CXX=clang++
  # export LDFLAGS=-L$(LLVM_DIR)/lib/c++ -lc++abi -lc++ -lc++experimental
  # export GCOV="llvm-cov gcov"

  ### TODO: to test g++-15:
  export CXX:=g++-15
  export CXXFLAGS:=-stdlib=libstdc++
  export GCC_PREFIX=$(shell brew --prefix gcc)
  export GCC_DIR=$(shell realpath ${GCC_PREFIX})
  export CMAKE_CXX_STDLIB_MODULES_JSON=${GCC_DIR}/lib/gcc/current/libstdc++.modules.json
else ifeq (${hostSystemName},Linux)
  export LLVM_DIR=/usr/lib/llvm-20
  export PATH:=${LLVM_DIR}/bin:${PATH}
  export CXX=clang++-20
endif

.PHONY: all clean distclean

all: build
	ln -sf build/compile_commands.json .
	ninja -C build

build: CMakeLists.txt
	cmake -S . -B build -G Ninja -D CMAKE_SKIP_INSTALL_RULES=ON \
		-D CMAKE_EXPERIMENTAL_CXX_IMPORT_STD="d0edc3af-4c50-42ea-a356-e2862fe7a444" \
		-D BOOST_USE_MODULES=ON -D CMAKE_CXX_MODULE_STD=ON \
		-D CMAKE_CXX_STANDARD=23 -D CMAKE_CXX_EXTENSIONS=ON -D CMAKE_CXX_STANDARD_REQUIRED=ON \
		-D CMAKE_CXX_STDLIB_MODULES_JSON=${CMAKE_CXX_STDLIB_MODULES_JSON} \
		-D BUILD_TESTING=ON -D BOOST_INCLUDE_LIBRARIES='any;type_index;test' # XXX --fresh

distclean: clean
	rm -rf build

# Anything we don't know how to build will use this rule.
% ::
	ninja -C build $(@)

```

```bash
bash-5.3$ make distclean
rm -rf build
bash-5.3$ make
cmake -S . -B build -G Ninja -D BOOST_USE_MODULES=ON -D CMAKE_SKIP_INSTALL_RULES=ON \
		-D CMAKE_EXPERIMENTAL_CXX_IMPORT_STD="d0edc3af-4c50-42ea-a356-e2862fe7a444" \
		-D CMAKE_CXX_STANDARD=23 -D CMAKE_CXX_EXTENSIONS=ON -D CMAKE_CXX_STANDARD_REQUIRED=ON \
		-D CMAKE_CXX_STDLIB_MODULES_JSON=/usr/local/Cellar/gcc/15.2.0/lib/gcc/current/libstdc++.modules.json \
		-D BOOST_INCLUDE_LIBRARIES='any' # XXX --fresh
-- The CXX compiler identification is GNU 15.2.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++-15 - skipped
-- Detecting CXX compile features
CMake Warning (dev) at /Users/clausklein/.local/share/cmake-4.2/Modules/Compiler/CMakeCommonCompilerMacros.cmake:248 (cmake_language):
  CMake's support for `import std;` in C++23 and newer is experimental. It
  is meant only for experimentation and feedback to CMake developers.
Call Stack (most recent call first):
  /Users/clausklein/.local/share/cmake-4.2/Modules/CMakeDetermineCompilerSupport.cmake:113 (cmake_create_cxx_import_std)
  /Users/clausklein/.local/share/cmake-4.2/Modules/CMakeTestCXXCompiler.cmake:83 (CMAKE_DETERMINE_COMPILER_SUPPORT)
  CMakeLists.txt:20 (project)
This warning is for project developers. Use -Wno-dev to suppress it.

-- Detecting CXX compile features - done
-- CMAKE_CXX_COMPILER_IMPORT_STD=23;26
-- CMAKE_CXX_MODULE_STD=ON
-- CMAKE_CXX_STANDARD=23
-- CMAKE_CXX_SCAN_FOR_MODULES=ON
-- Boost: using system layout: include, bin, lib, lib/cmake, share
-- Boost: using CMake 4.2.0-gd4539f6
-- Boost: Release build, static libraries, MPI OFF, Python OFF, testing OFF
-- Boost: libraries included: any
-- Using `import std;`
-- Using `import std;`
-- Configuring done (1.0s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/clausklein/Workspace/cpp/boost-git/build
ln -sf build/compile_commands.json .
ninja -C build
ninja: Entering directory `build'
[0/2] Re-checking globbed directories...
[12/13] Linking CXX static library stage/lib/libboost_any.a
bash-5.3$ 

```

---

_[View the full topic](https://discourse.cmake.org/t/distributing-c-20-modules-as-source/13246)._
