CMake silently allow multiple source files with the same name when generating an Xcode project while it is not possible in OBJECT library
We recently made some changes in our library by introducing multiple
As we are using multiple files with the same base name in a given
OBJECT library, it is no longer possible to generate an Xcode solution.
Indeed, if I understand it correctly, Xcode is generating its own way to name object files and it seems to not be configurable. CMake only tries to mimic its naming.
Let's say we have the following source files in our
library + folder1 | + bar.cpp | + foo.cpp + folder1 | + foo.c
We will usually expect object files with the following tree
library_objects + folder1 | + bar.cpp.o | + foo.cpp.o + folder1 | + foo.c.o
But, Xcode will output the following tree
library_objects + bar.o + foo-[hash1].o + foo-[hash2].o
However, when trying to link, we are asking to link against foo.o, for both foo.cpp and foo.c. As it doesn't exist, the build fails. This foo.o name is generated by CMake and doesn't match the existing ones.
There are different discussions about this specific issue:
And a general report about the lake of support for
OBJECT libraries with Xcode: #17500
It seems that the issue about the naming is known as there is a way to detect it, but there is no error handling, only a
It is maybe not possible to fix the issue, but I think there are possible feedback/doc improvements that could be really useful to avoid having to reverse engineer the whole process to understand the issue:
- Alert the user it will fails instead of the
- Document this limitation
- Document the fact that the
CMAKE_<LANG>_OUTPUT_EXTENSIONvariable are ignored when generating an Xcode project