.m sources compiled as C language instead of OBJC language
The OSS project for which I maintain the CMake project received an issue report today from a user for which the .m files failed to compile.
By adding -x objective-c
to the COMPILE_FLAGS
property of the target he could get it working.
In our project, we do project(SDL2 C CXX)
+ optionally enable OBJC
using enable_language(OBJC)
.
But the user posted a build log that made it clear the .m
sources were compiled as c source using -x c
:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c -target arm64-apple-macos12.3 -fmessage-length\=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit\=0 -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof -DCMAKE_INTDIR\=\"Debug\" -DSDL_STATIC_LIB -DUSING_GENERATED_CONFIG_H -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -fstrict-aliasing -Wdeprecated-declarations -g -Wno-sign-conversion -Wno-infinite-recursion -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-semicolon-before-method-body -index-store-path /Users/luca/Library/Developer/Xcode/DerivedData/blackboard_projects-epfzwdcjsptvawhbxsxatsajmyvz/Index/DataStore -I/Users/luca/dev/dashandslash/blackboard_app_template/.external/blackboard_app-src/.external/sdl-build/Debug/include -I/Users/luca/dev/dashandslash/blackboard_app_template/.external/blackboard_app-src/.external/sdl-build/include -I/Users/luca/dev/dashandslash/blackboard_app_template/.external/blackboard_app-src/.external/sdl-build/include-config-debug -I/Users/luca/dev/dashandslash/blackboard_app_template/.external/blackboard_app-src/.external/sdl-build/blackboard_projects.build/Debug/SDL2-static.build/DerivedSources-normal/arm64 -I/Users/luca/dev/dashandslash/blackboard_app_template/.external/blackboard_app-src/.external/sdl-build/blackboard_projects.build/Debug/SDL2-static.build/DerivedSources/arm64 -I/Users/luca/dev/dashandslash/blackboard_app_template/.external/blackboard_app-src/.external/sdl-build/blackboard_projects.build/Debug/SDL2-static.build/DerivedSources -F/Users/luca/dev/dashandslash/blackboard_app_template/.external/blackboard_app-src/.external/sdl-build/Debug -idirafter /Users/luca/dev/dashandslash/blackboard_app_template/.external/blackboard_app-src/.external/sdl-src/src/video/khronos -Wall -fno-strict-aliasing -Werror\=declaration-after-statement -Wdeclaration-after-statement -fvisibility\=hidden -Wshadow -D_THREAD_SAFE -DSDL_BUILD_MAJOR_VERSION\=2 -DSDL_BUILD_MINOR_VERSION\=25 -DSDL_BUILD_MICRO_VERSION\=0 -fobjc-arc -MMD -MT dependencies -MF /Users/luca/dev/dashandslash/blackboard_app_template/.external/blackboard_app-src/.external/sdl-build/blackboard_projects.build/Debug/SDL2-static.build/Objects-normal/arm64/SDL_sysfilesystem.d --serialize-diagnostics /Users/luca/dev/dashandslash/blackboard_app_template/.external/blackboard_app-src/.external/sdl-build/blackboard_projects.build/Debug/SDL2-static.build/Objects-normal/arm64/SDL_sysfilesystem.dia -c /Users/luca/dev/dashandslash/blackboard_app_template/.external/blackboard_app-src/.external/sdl-src/src/filesystem/cocoa/SDL_sysfilesystem.m -o /Users/luca/dev/dashandslash/blackboard_app_template/.external/blackboard_app-src/.external/sdl-build/blackboard_projects.build/Debug/SDL2-static.build/Objects-normal/arm64/SDL_sysfilesystem.o -index-unit-output-path /blackboard_projects.build/Debug/SDL2-static.build/Objects-normal/arm64/SDL_sysfilesystem.o
He also posted the CMake<LANG>Compiler.cmake
scripts generated by CMake.
In there, we see that CMakeCCompiler.cmake
sets set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m)
.
When he added enable_language(OBJCXX)
, the .m
source compiled succesfull as well.
My question is how this can happen and how to fix it.
Edited by Maarten