VS: Mutliple add_library of INTERFACE targets with source files in the same CMakeLists.txt can produce MSB8028 (Visual Studio generator)
Found this edge case...
We have two libraries in one CMakeList.txt file that are INTERFACE
targets with source files.
After CMake version 3.19, targets are being created (stated in the documentation https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries)
The Visual Studio generator does not add an "IntDir" to the project file being generated. This is due to the first conditional in cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions
:
if (ttype > cmStateEnums::GLOBAL_TARGET) {
return;
}
When two targets of this type are declared in the same CMakeLists.txt, Visual Studio will assume a default IntDir, which does not depend on the target name itself, but on the folder where the target is, in our case is x64\profile
. When building, warning MSB8028 gets produced because the two targets are sharing the same intermediate directory.
In our case there is no file in the intermediate folder that has the same name across targets, only tlog and recipe files are there and they are named after the target, so the warning is not an issue. However, it would be nice to get IntDir generated similarly to other targets to avoid the warning.