# compile C++20 modules with cmake

**URL:** https://discourse.cmake.org/t/compile-c-20-modules-with-cmake/5116
**Category:** Code
**Tags:** comp:gcc, os:linux, gen:ninja
**Created:** [February 25, 2022, 3:30pm UTC](https://discourse.cmake.org/t/compile-c-20-modules-with-cmake/5116 "2022-02-25T15:30:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![raj](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/c0e974/32.png) [@raj](https://discourse.cmake.org/u/raj)
#### Post date: [February 25, 2022, 3:30pm UTC](https://discourse.cmake.org/t/compile-c-20-modules-with-cmake/5116/1 "2022-02-25T15:30:03Z")

</div>

Hi  
I have two files main.cpp and module1.cpp (simple hello\_world example)  
I want to build them with cmake.  
following is cmake code (not working)

cmake\_minimum\_required(VERSION 3.21)  
project(cpp\_concurrency\_masterclass)  
SET(CMAKE\_CXX\_STANDARD 20)  
SET(CMAKE\_CXX\_FLAGS “-fmodules-ts”)  
add\_executable(main module1.cpp main.cpp)

on command line following works perfectly  
g++ -fmodules-ts module1.cpp main.cpp

but with cmake it generates seperate object file for each source file and then while compiling main.cpp it can not find the module1.  
Did not find any simple answer on google either.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 25, 2022, 5:49pm UTC](https://discourse.cmake.org/t/compile-c-20-modules-with-cmake/5116/2 "2022-02-25T17:49:59Z")

</div>

CMake does not yet support modules out of the box. See [this issue](https://gitlab.kitware.com/cmake/cmake/-/issues/18355) where updates will be posted as they happen.
