# How to specify C++-module-implementation file in CMakeLists.txt?

**URL:** https://discourse.cmake.org/t/how-to-specify-c-module-implementation-file-in-cmakelists-txt/14317
**Category:** Usage
**Created:** [July 4, 2025, 8:23pm UTC](https://discourse.cmake.org/t/how-to-specify-c-module-implementation-file-in-cmakelists-txt/14317 "2025-07-04T20:23:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![markus.parker](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/b9bd4f/32.png) [@markus.parker](https://discourse.cmake.org/u/markus.parker)
#### Post date: [July 4, 2025, 8:23pm UTC](https://discourse.cmake.org/t/how-to-specify-c-module-implementation-file-in-cmakelists-txt/14317/1 "2025-07-04T20:23:24Z")

</div>

Hello,  
I posted the following at [https://stackoverflow.com/q/79687866/5525302](https://stackoverflow.com/q/79687866/5525302), but got no answer, that is why I try it here.

I want to create a c+±20-module without partitions but where the interface is in a different file than the implementation. This is my setup:

interface file _ModuleTest.ixx_:

```auto
export module moduleTest;
export int foo();

```

implementation file _ModuleTest.cpp_:

```auto
module moduleTest;
int foo() {
  // some implementation
}

```

How do I need to specify the implementation file within the corresponding target in _CMakeLists.txt_?

This is what I tried:

```auto
add_library(moduleTest)

target_sources(moduleTest
    PRIVATE FILE_SET CXX_MODULES FILES
    ModuleTest.ixx
    PRIVATE
    ModuleTest.cpp
)
target_compile_features(moduleTest PUBLIC cxx_std_20)
target_compile_options(moduleTest PRIVATE "-fmodules-ts")

I get this error:

```

```auto
moduleTest: error: failed to read compiled module: No such file or directory
moduleTest: note: compiled module file is 'gcm.cache/moduleTest.gcm'
moduleTest: note: imports must be built before being imported
moduleTest: fatal error: returning to the gate for a mechanical issue

Can I expect this to work at all? 

Thanks for any advice!

```

---

<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: [July 5, 2025, 5:18am UTC](https://discourse.cmake.org/t/how-to-specify-c-module-implementation-file-in-cmakelists-txt/14317/2 "2025-07-05T05:18:16Z")

</div>

You may read [C++20 Modules, CMake, And Shared Libraries](https://crascit.com/2024/04/04/cxx-modules-cmake-shared-libraries/)
