
a) You add_library() and target_souces() using the new FILE_SET CXX_MODULES feature. This builds a library (e.g. libboost_asio.a) and a BMI. Note that even previously header-only libraries end up generating compiled libraries in the modules world. The compiled library contains code for global initializers, and is emitted even if there are no global initializers [1]. b) You install() the library with its module bindings. This means that you end up installing libboost_asio.a and any other files required to generate the BMI for the Asio module (in this case, this would be Asio headers). If the module contained implementation units (somehow akin to .cpp files in today's world - apologies if the comparison is not exact), these shouldn't get installed. c) The user calls find_package() on the installed package, and calls target_link_libraries() linking to the library installed in the previous step. When doing this, CMake rebuilds the BMI, but not the object files (libboost_asio.a). The BMI will be built with the same cxxstd (I don't know about other properties) as the original library. This is the point that generates questions for me, as it imposes manyyou need to assume tha more restrictions than the traditional header model [2]. On the other hand, the CMake team seems to be working on enhancing this, but without an ETA [3].
Correct me if I'm wrong, but in the modules world I don't think you can really install anything - you need to think of them as more like precompiled headers that are project specific and built as part of each individual project, you need to assume that changing *any* compiler option will break the module unless it is re-built. That's why the msvc std module is built on a per-project basis. Boost modules will be just the same I assume.
If I understood the CMake developers and Chuanqi correctly (please let me know if I didn't), you do install a library with the generated object files, but you do not install the BMIs, as they're like pre-compiled headers. Let me explain how I understood it with two concrete examples. Take Boost.Url as an example of a compiled library, and Boost.Regex as an example of a header-only library. 1. Boost.Url today installs: * libboost_url.a, containing function definitions. * Headers, containing declarations. 2. Boost.Url in the module world would install: * libboost_url.a, containing the same function definitions as above. * A boost_url.cppm file, akin to what headers are today. CMake would build a BMI from this file when a user needs to import boost.url. In practice, this cppm file will likely be implemented in terms of the header files that we have today. 3. Boost.Regex today installs: * Headers, containing declarations and definitions. 4. Boost.Regex in the module world would install: * A libboost_regex.a object, containing module initializers [1]. For instance, if you have a singleton defining a Boost.System error category, initialization code for the singleton would be emitted here. From the docs, it seems this object gets created even if no initialization code is required. * A boost_regex.cppm file, containing the bulk of the library, akin to what we provide using headers today. My intention is doing some testing to see how much trouble would this new libboost_regex.a library cause.
Meanwhile, I've cleaned up and merged Boost.Regex module support to develop if anyone wants to try it out. There are rudimentary instructions here: https://github.com/boostorg/regex/blob/develop/doc/modules.qbk, conceivably this could be enhanced by providing CMake and visual studio projects.
What I described above is what you get if you use CMake's install() function for a target containing C++20 modules. Ironically, this doesn't apply for the standard library, which is always built by the user. Unfortunately, CMake doesn't seem to have first-class support for this, meaning that the user would need to figure out dependencies manually. I think the best model for our header-only libraries would be the one used for the std module: we distribute the cppm files, and the module gets built by the user. I will ping the CMake developers to see if there is a way to handle this. Thanks for your efforts here, John. Regards, Ruben.