# Best practice for c++20 modules?

**URL:** https://discourse.cmake.org/t/best-practice-for-c-20-modules/8800
**Category:** Usage
**Created:** [August 22, 2023, 1:57pm UTC](https://discourse.cmake.org/t/best-practice-for-c-20-modules/8800 "2023-08-22T13:57:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Glad](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@Glad](https://discourse.cmake.org/u/Glad)
#### Post date: [August 22, 2023, 1:57pm UTC](https://discourse.cmake.org/t/best-practice-for-c-20-modules/8800/1 "2023-08-22T13:57:23Z")

</div>

Hi,

Using CMake 3.27+ and clang 16/17+ (or gcc 13.2+), what would be the best way to have a project B import a module generated in a project A, out of tree ?

I am on Linux.  
Many examples out there are not out-of-tree.

–Global dev dir  
-----Project A  
—build  
—src  
—includes  
—CMakeLists.txt

-----Project B  
—build  
—src  
—includes  
—CMakeLists.txt

-----Project C  
—build  
—src  
—includes  
—CMakeLists.txt

Projects are independent but Project A is a module, project B and C ae executables.

Right now, Project A is a static library imported in B and C. Works perfectly fine as is.  
But I am willing to test.

More globally, having a best practice thread, evolving with the implementations, would be phenomenal.

Thanks

---

<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: [August 22, 2023, 2:09pm UTC](https://discourse.cmake.org/t/best-practice-for-c-20-modules/8800/2 "2023-08-22T14:09:33Z")

</div>

Experimental support for `IMPORTED` targets with modules [just landed yesterday](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/8535) if you want to test out `master`. Note that there aren’t “best practices” yet, but testing that things work as intended with “real” code would be appreciated.

---

<div class="post-metadata">

### Author: ![Glad](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@Glad](https://discourse.cmake.org/u/Glad)
#### Post date: [August 22, 2023, 2:39pm UTC](https://discourse.cmake.org/t/best-practice-for-c-20-modules/8800/3 "2023-08-22T14:39:39Z")

</div>

I have a lot of interest for it so I will do.  
I have a medium multi libs project that is waiting for it. 🙂
