+ 1
C++20 module Cmake Source Code
Is there anyone with a cmake source code that can enable c++20 module in CLion's IDE (from jetbrains) or guide me through the IDE settings to enable module syntax. It used to work on visual studio 2022 but my current compiler is is GCC >= 12 with latest cmake and i am tired of using #include. i think it's time to start using module but its wont work btw there's always an error that says c++ import can only be used with fs-module.ts or -std=c++20. I then tried adding this line to my cmake add_compile_options(--std=c++20 --pedantic) but still, it wont work
3 Antworten
+ 2
White Shadow did you try something like this
cmake_minimum_required(VERSION 3.10)
project(my_project)
set(CMAKE_CXX_STANDARD 20)
add_compile_options(-fmodules) # Or -fmodules-ts for transparent modules
add_executable(my_executable main.cpp module1.cpp)
******* or ********
cmake_minimum_required(VERSION 3.20) # Make sure you are using at least CMake 3.20
project(MyProject LANGUAGES CXX)
# Set the C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Add the module flag
add_compile_options(-fmodules-ts)
# Add your source files
add_executable(MyExecutable main.cpp my_module.cpp)
# Specify the module interface units explicitly if needed
target_sources(MyExecutable PRIVATE
FILE_SET cxx_modules TYPE CXX_MODULES
FILES my_module.cpp
)
+ 1
@brofar Thanks for the reply... I'll try both and I'll give feedback after 17hrs
0
@brofar the solution didn't work for me. I've deleted CLion2023 and install Clion2024, now I can use import without the modification of the Cmake source code