Visual Studio build fails with two identical cpp file names in the same project
I am using CMake 3.12.3 with Visual Studio 2017 15.8.8. I am building a library using:
add_library(my_lib bar.cpp foo/bar.cpp)
The resulting vcxproj file contains:
<ClCompile Include="D:\Projects\my_lib\bar.cpp">
<ObjectFileName>$(IntDir)/bar.cpp.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="D:\Projects\my_lib\foo\bar.cpp">
<ObjectFileName>$(IntDir)/foo/bar.cpp.obj</ObjectFileName>
</ClCompile>
The first bar.cpp successfully compiles, but the second fails:
D:\Projects\my_lib\foo\bar.cpp : fatal error C1083: Cannot open compiler generated file: 'D:\Builds\my_lib\my_lib.dir\Debug\foo\bar.cpp.obj': No such file or directory
The build fails because the foo directory doesn't exist. The build succeeds when I create the directory manually. Obviously neither CMake nor Visual C++ creates that directory automatically.
The workarounds are trivial: Renaming the files or using a CMake command to create the directory.
But an average user might not be able to find out why the build fails based on the error message, so it would be nice if CMake would create the directory automatically.
Thanks in advance for fixing it! Appreciate your great work!