Xcode: Incorrect explicitFileType for C++ .ipp header files
We have a C++ project in CMake that is typically used with the Xcode generator. We've noticed that if the project contains a C++ header file ending in extension .ipp
it will not get syntax highlighted by Xcode.
This appears to be because the pbxproj generated contains the following file reference:
7B2148660E7040C4970F7F9D /* /Users/jagostino/Documents/Cmake Xcode Test/foo.ipp */ = {isa = PBXFileReference; explicitFileType = sourcecode; fileEncoding = 4; name = foo.ipp; path = foo.ipp; sourceTree = SOURCE_ROOT; };
Note that the generator set the explicitFileType = sourcecode
value, which informs Xcode that it is a generic source code file and evidently no language-specific highlighting is applied. If you use the file inspector in Xcode to change the file type to "Default - C++ Header File" then the file reference in the pbxproj is rewritten as such:
C9E9BB54B3BE4E8D86A84A62 /* foo.ipp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = foo.ipp; sourceTree = SOURCE_ROOT; };
The explicitFileType
parameter is removed and replaced with lastKnownFileType = sourcecode.cpp.h
.
I also tried adding the explicit setting set_source_files_properties(foo2.ipp PROPERTIES LANGUAGE CXX)
to the CMake list. This results in the file reference getting explicitFileType = sourcecode.cpp.cpp
which while it does make the IDE highlight a file, it is not the correct type for a header file.
Finally I tried adding the following lines to the CMake list however it had no effect, the explicitFileType
was still sourcecode
:
set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${CMAKE_CXX_SOURCE_FILE_EXTENSIONS};ipp)
set(CMAKE_CXX_IGNORE_EXTENSIONS ${CMAKE_CXX_IGNORE_EXTENSIONS};ipp) # tried with and without this
I'd suggest that in most cases the Xcode default decision on a file type is going to be the right one and explicitFileType
should not be used. If the decision stands to have CMake control the file types of all files explicitly, then ipp
should be treated as a C++ header file internally by CMake. CMAKE_CXX_SOURCE_FILE_EXTENSIONS
and related config parameters should also have an effect on the Xcode generator's value for the parameter explicitFileType
.
My test project is attached Cmake_Xcode_Test.zip