C++20 modules support in CMake#455
Conversation
|
@Neargye hello! What do you think about that? |
|
Hey @fdr400, great work! The CMake infrastructure, CI integration, and per-test module libraries are really well done. One thing I'd prefer to keep different: the magic_enum.cppm rework. Honestly, I wasn't maintaining it well before, but going forward, I'll keep a closer eye on it. The explicit using style is just easier for me to review and maintain, the interface is visible in one place, and detail:: symbols can't accidentally leak. Could you revert that file to the explicit approach and just add the missing symbols? Also a couple of small bugs found during review: Unmatched #pragma push without #pragma pop in magic_enum.cppm |
|
Hi @Neargye ! I understand your opinion about primary module interface unit, so I returned the explicit using-based style and added all required exports. The transparent modules migration is also possible because of automatic import inside headers
CMake documentation says |
Hi @Neargye ! I saw your awesome project has
magic_enum.cppmfile with C++20 module structure but, unfortunately, there is neither CMake support nor CI tests for modules build.So the PR introduces:
magic_enummodule and run all tests using the modulelibc++andctestrun in install test workflowI have some experience in C++ modules and supported modules for some of Boost libraries (for example, Boost.stacktrace).
The idea for modules in Boost is not the same as for
magic_enum.cppmthat currently includes all headers in global module fragment and exports all public symbols.Key concept is to make modules migration transparent for library clients (without changing their code). So the library (
magic_enumin this context) provides its interface via same headers as in non-module build, but headers are preprocessed intoimport magic_enumif library was build with modules-on flag.Also all function is attached to the library module, not the global module, and exported explicitly using the
exportkeyword (that is hidden with macros to support non-module build).So that it is harder to forget to export some public function because public interface is already in-closed into
export {}block. And, again, such concept allows to build library module and consume it transparently as a header.However, it is an ABI break because symbols have
@magic_enumsuffix, but I believe this is not significant problem (probably, I am wrong).Theoretically, modules +
magic_enumcan significantly speed up compilation speed for library consumers because of huge number ofconstexprfunctions and classes but I did not test it.Current CMake modules support is not full, especially there is no two-phase compilation, and there are many troubles when targets are build with different compiler flag. But it somehow works anyway.
I can split PR into some logical parts and explain some solutions and possibly rework some of them. But firstly I want to know your opinion about all of this and are you actually interested in modules support :)
Because this is fully (I believe) backward compatibly change for all library clients, it's worth it
P.S. Thanks for the great library!