add support to build without modules

some compilers don't fully support modules with the way cmake does them.
it seems like only Clang 16 supports them which is not in the arch repos
yet.
This commit is contained in:
Fries 2023-06-22 21:45:18 -07:00
parent 678b854b74
commit eb6fa7a104
2 changed files with 26 additions and 16 deletions

View file

@ -1,23 +1,29 @@
cmake_minimum_required(VERSION 3.26)
project(LearningProject CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
string(CONCAT CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE
"<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> <SOURCE>"
" -MT <DYNDEP_FILE> -MD -MF <DEP_FILE>"
" ${flags_to_scan_deps} -fdep-file=<DYNDEP_FILE> -fdep-output=<OBJECT>"
)
option(BUILD_WITH_MODULES "Build with C++ Modules" ON)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "gcc")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG
"${compiler_flags_for_module_map} -fmodule-mapper=<MODULE_MAP_FILE>")
if(BUILD_WITH_MODULES)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
string(CONCAT CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE
"<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> <SOURCE>"
" -MT <DYNDEP_FILE> -MD -MF <DEP_FILE>"
" ${flags_to_scan_deps} -fdep-file=<DYNDEP_FILE> -fdep-output=<OBJECT>"
)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "gcc")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG
"${compiler_flags_for_module_map} -fmodule-mapper=<MODULE_MAP_FILE>")
endif()
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
set(CMAKE_CXX_EXTENSIONS OFF)
add_subdirectory(src)

View file

@ -1,8 +1,12 @@
add_subdirectory(math)
if (BUILD_WITH_MODULES)
add_subdirectory(math)
endif()
add_executable(hello hello.cc)
add_executable(sqrt sqrt.cc)
target_link_libraries(sqrt PRIVATE Math)
if (BUILD_WITH_MODULES)
add_executable(sqrt sqrt.cc)
target_link_libraries(sqrt PRIVATE Math)
endif()
add_executable(inheritance inheritance.cc)
add_executable(enumerations enumerations.cc)
add_executable(namespaces namespaces.cc)