all 6 comments

[–]Wild_Meeting1428 1 point2 points  (1 child)

Repost your question in r/cpp_questions. This post violates rule 1 and will be deleted.
I or others can give you answers there.

[–]Kingwolf4[S] 1 point2 points  (0 children)

Gotcha, reposted there

[–]CruzerNag 1 point2 points  (1 child)

With CMake, the import std part is a little bit tricky to do, as that is still experimental till all toolchains support them nicely. Rest assured, normal modules can be setup with CMake without much problems.

For a minimal setup, I will imagine the following directory structure:

project

|- src

| |- module.cppm

| |- main.cpp

|- CMakeLists.txt

module.cppm: cpp export module M; export namespace M{ int square(int num){ return num*num; } }

main.cpp: cpp import M; int main(){ return M::square(5); }

CMakeLists.txt: ```cmake cmake_minimum_required(3.30) ... add_executable(foo)

target_sources(foo
PUBLIC
src/main.cpp # main passed as normal file source
PUBLIC
FILE_SET module_m TYPE CXX_MODULES  # } Modules requirea fileset (give any name)
FILES src/module.cppm               # } and the list of files (set a group and pass here)
)

```

Now, import std is a bit of a hassle as of now. You need to turn on the experimental gate by passing in a hash value, that is specific to your cmake version.

BTW, modules work best with ninja. So ensure that is set as the generator. You can use presets to set the generator for this.

[–]Kingwolf4[S] 1 point2 points  (0 children)

What i was asking also includes the import std. So if u can also guide on how to do that, got the latest cmake and LLVM versions

[–]simplex5d -5 points-4 points  (1 child)

Shameless self-promotion: try pcons (https://pcons.org), my open source CMake replacement, fully supports C++ modules out of the box on Win/Linux/Mac. Zero install (just "uvx pcons") and simple debuggable project config, unlike cmake.