Glad
November 1, 2023, 7:48pm
1
Hi,
Waiting for the 3.28 official release, what would importing a module from another directory look like ?
The helloword example has foo.cxx in the same dir, but sooner or later we will end up with modules in some directories and project located elsewhere calling them.
Main proj dir
----- CMakeLists.txt
----- main.cpp ← import module in that source
Module dir
----- CMakeLists.txt
----- mod.cxx ← export module from that source
----- build/
A helloworld with that scenario would be nice
Thanks
1 Like
ben.boeckel
(Ben Boeckel (Kitware))
November 3, 2023, 2:15am
2
There are examples in the test suite. To get this to work, you’ll need:
a Ninja
generator (Visual Studio doesn’t provide the needed information for CMake to do what is needed at build time);
a CXX_MODULES_DIRECTORY
argument to the export
and/or install(EXPORT)
calls to generate the needed information;
consumption from a Ninja
build (Visual Studio can support it, CMake just needs to do a bit more to get it all correct).
Once that is done, you just link the target as normal.
Glad
November 4, 2023, 7:01am
3
I missed the fact that modules are managed like static libs with a differing way to set the source.
With the examples it became clear.
Thanks,
Glad
November 4, 2023, 12:31pm
4
The most straightforward way I could find to use multiple modules from out of tree, is to link the folders/files in the current project’s tree.
Otherwise, the experience is very verbose. Not sure if it has some complications down the road, but it is the easiest way I could find right now.
ben.boeckel
(Ben Boeckel (Kitware))
November 17, 2023, 1:29pm
5
This sounds like a hack and not something likely to work long-term or scale well. Why is using the imported targets not sufficient?
Glad
November 17, 2023, 2:02pm
6
You are right, forgot to update, but I ended doing it the usual way, with specifying the other folders in the current CMake.
Thanks Ben,