Skip to content

VS: Make BMIs public by default for shared libraries

Andreas Weis requested to merge ComicSansMS/cmake:master into master

Enable the AllProjectBMIsArePublic option for shared libraries in the VS project files when building with C++20 modules support.

This request is a follow-up to this discussion on Discourse.

This request fixes a problem when building a shared library and an executable depending on functionality from that shared library that is provided by a C++20 modules source file. By default, MSVC will be unable to find modules from a library dependency if that dependency is a shared library. The DLL project needs to specify which of its module source files are public. Currently MSVC only allows specifying this by either making all modules public or by making all modules from a specified set of directories public. There is no way to give a list of module source files that should be public; a feature request for that has been filed with MSVC. This change will make all module sources from a shared library public by default.

I am unsure what is the best place to add a test for this change. Any help in that regard is highly appreciated.

The change should only have an effect for shared library targets that are built with Modules support on MSVC. The modification to the vcxproj file is parsed correctly by MSVC and shows up in the GUI as expected. The corresponding option can be found in the Project Properties under VC++ Directories->All Modules are Public.

When setting the option directly from the GUI, MSVC will write one PropertyGroup entry for each configuration with a matching Condition attribute and place the AllProjectBMIsArePublic within with no attributes. CMake seems to always write a single PropertyGroup entry with no condition instead and include inside the elements with Condition attributes for the configuration. I followed the CMake convention here.

The entry is written to the same place in the generated vcxproj files as it would get written to when being set from the GUI.

Backport: release
Topic-rename: vs-cxxmodules-public-bmis

Edited by Brad King

Merge request reports