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
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:
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})