I was looking into building shared libraries with modules on MSVC and ran into an issue.
Starting from the example from the blog post, I change the library foo to be a shared library(set(BUILD_SHARED_LIBS ON)
). With this the MSVC build will fail with error C2230: Translation units from the executable will be unable to find the module ‘foo’.
It turns out that MSVC by default will not make modules from DLL targets public. There is however an option to control which modules become public. The easiest way to make the example work is to just set Project Properties->VC++ Directories->All Modules are Public to Yes on the ‘foo’ project. This will add the following entry to the foo.vcxproj
file:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<AllProjectBMIsArePublic>true</AllProjectBMIsArePublic>
</PropertyGroup>
With this entry in place, the example compiles fine. However, as far as I can see, there is no way to enable this option from within CMake, so regenerating the file with CMake will break the build.
From the limited amount of investigation that I did, it seems to me that if CMake emitted this option by default for shared library projects that contain C++ module source files, the behavior would be consistent with that of static libraries. Has this been considered?