# Building C++ modules with GCC and Clang for presentatoins

**URL:** https://discourse.cmake.org/t/building-c-modules-with-gcc-and-clang-for-presentatoins/13601
**Category:** Code
**Tags:** os:linux
**Created:** [February 18, 2025, 7:53pm UTC](https://discourse.cmake.org/t/building-c-modules-with-gcc-and-clang-for-presentatoins/13601 "2025-02-18T19:53:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rmerriam](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rmerriam/32/5357_2.png) [@rmerriam](https://discourse.cmake.org/u/rmerriam)
#### Post date: [February 18, 2025, 7:53pm UTC](https://discourse.cmake.org/t/building-c-modules-with-gcc-and-clang-for-presentatoins/13601/1 "2025-02-18T19:53:54Z")

</div>

I’m working on a presentation about C++ modules using CMake to build them. Here are my two CMakeLists.txt files for GCC which works fine. What changes for Clang?

Any improvements on the overall CMake code so it is good for a presentation?

Upper level CMakeLists.txt

```auto
cmake_minimum_required(VERSION 3.30)
project(pragmatic_modules)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-std=c++23 -Werror -Wpedantic -Wall
                    -Mmodules
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")

add_compile_options(-std=c++23 -Werror -Wpedantic -Wall
                    -fmodules
)
endif()

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_SCAN_FOR_MODULES ON)

add_subdirectory(Aegean)
add_subdirectory(Aegean.Private)
add_subdirectory(AmericanBobtail)

```

One of the subdirectory files:

```auto
cmake_minimum_required(VERSION 3.28.3)
project(Aegean.Private LANGUAGES CXX)
set(library_name agean.private)

add_executable(${PROJECT_NAME} main.cpp)

add_library(${library_name})

target_sources(${library_name}
               PUBLIC
               FILE_SET cxx_modules TYPE CXX_MODULES
               FILES Aegean.cppm
)

target_link_libraries(${PROJECT_NAME} ${library_name})

```

---

<div class="post-metadata">

### Author: ![rmerriam](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rmerriam/32/5357_2.png) [@rmerriam](https://discourse.cmake.org/u/rmerriam)
#### Post date: [February 20, 2025, 6:40pm UTC](https://discourse.cmake.org/t/building-c-modules-with-gcc-and-clang-for-presentatoins/13601/2 "2025-02-20T18:40:38Z")

</div>

I needed `set(CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS "/usr/bin/clang-scan-deps-18") ` before the `project()`.
