C++20 module Cmake Source Code | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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

18th May 2024, 12:32 AM
White Shadow
White Shadow - avatar
2 ответов
+ 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 )
18th May 2024, 6:45 AM
BroFar
BroFar - avatar
+ 1
@brofar Thanks for the reply... I'll try both and I'll give feedback after 17hrs
20th May 2024, 4:23 AM
White Shadow
White Shadow - avatar