Using Ubuntu 22.04 LTS, CMake 3.28.1, Ninja 1.11.1 and Clang 17.0.6, I’m trying to create a library using modules, supported under these conditions, as described at import-cmake-the-experiment-is-over.
I managed to successfully create a library with modules, and link it to an executable in the same project.
–
My library is quite simple:
// robocin/utility/concepts.ixx
module;
#include <concepts>
#include <google/protobuf/message_lite.h>
export module robocin.utility:concepts;
export namespace robocin {
template <class T>
concept protobufish = std::derived_from<std::remove_cvref_t<T>, ::google::protobuf::MessageLite>;
} // namespace robocin
// robocin/utility/utility.ixx
export module robocin.utility;
export import :concepts;
- Here is my rule responsible for creating a library.
// CMakeLists.txt
robocin_cpp_library(
NAME utility
MODS utility.ixx
concepts.ixx
DEPS protobuf::libprotobuf
)
robocin_cpp_executable(
NAME local_target
SRCS local_target_main.cpp
DEPS utility
)
// robocin/utility/local_target_main.cpp
#include <iostream>
#include <vector>
import robocin.utility;
int main() { return robocin::protobufish<std::vector<int>>; }
Compile and works as expected.
–
However, when I tried to install it and use it in an executable in another project, the library created with modules was unable to find the included dependency:
// CMakeLists.txt
robocin_cpp_executable(
NAME external_target
SRCS external_target_main.cpp
DEPS common::utility # utility library generated by robocin/utility project and installed on the system.
)
// experimental/external_target_main.cpp (same as robocin/utility/local_target_main.cpp)
#include <iostream>
#include <vector>
import robocin.utility;
int main() { return robocin::protobufish<std::vector<int>>; }
Compiling output:
[proc] Executing command: /usr/local/bin/cmake --build /workspaces/project/experiments/cpp-modules/build --config Debug --target all -j 6 --
[build] [1/6 16% :: 0.058] Scanning /usr/local/modules/concepts.ixx for CXX dependencies
[build] FAILED: CMakeFiles/common__utility@synth_ee677d4352ba.dir/90ece7fad90b.bmi.ddi
[build] "/usr/bin/clang-scan-deps-17" -format=p1689 -- /usr/bin/clang++ -DROBOCIN_PROJECT_NAME=\"common\" -DROBOCIN_PROJECT_PATH=\"/tmp/common/cpp\" -I/tmp/common/cpp -I/tmp/common/cpp/build -g -std=gnu++23 --precompile -x c++ /usr/local/modules/concepts.ixx -c -o CMakeFiles/common__utility@synth_ee677d4352ba.dir/90ece7fad90b.bmi -MT CMakeFiles/common__utility@synth_ee677d4352ba.dir/90ece7fad90b.bmi.ddi -MD -MF CMakeFiles/common__utility@synth_ee677d4352ba.dir/90ece7fad90b.bmi.ddi.d > CMakeFiles/common__utility@synth_ee677d4352ba.dir/90ece7fad90b.bmi.ddi.tmp && mv CMakeFiles/common__utility@synth_ee677d4352ba.dir/90ece7fad90b.bmi.ddi.tmp CMakeFiles/common__utility@synth_ee677d4352ba.dir/90ece7fad90b.bmi.ddi
[build] Error while scanning dependencies for /usr/local/modules/concepts.ixx:
[build] /usr/local/modules/concepts.ixx:4:10: fatal error: 'google/protobuf/message_lite.h' file not found
[build] ninja: build stopped: subcommand failed.
- Here is the generated CMake file, which I imagine is imported by the executable for linking dependencies.
Previously this same library was a header, and it worked in both cases.
A complete example with all the files is available on GitHub: robocin/ssl-core/tree/cpp-modules.