OBJC/OBJCXX flags don't get set for Xcode generator
The following minimal project can be used to demonstrate the problem described further below:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(objctest LANGUAGES C CXX OBJC OBJCXX)
# Uncomment one of these two commands
#string(APPEND CMAKE_OBJCXX_FLAGS " -fobjc-arc")
add_compile_options(-fobjc-arc)
add_library(myfuncs STATIC myfuncs.mm)
The contents of myfuncs.mm
are relatively unimportant, it's the actual command line used to compile it that matter. But for completeness, you can use the following as confirmation that the flag was present:
myfuncs.mm:
#if ! __has_feature(objc_arc)
#error THIS CODE MUST BE COMPILED WITH ARC ENABLED!
#endif
Using the Ninja or Makefiles generator, the -fobjc-arc
compiler option is added to the command line, whereas with the Xcode generator, it isn't. Further investigation shows that it seems like none of the methods that normally work for modifying compiler flags are working for the Xcode generator when the OBJC and OBJCXX languages are enabled. Neither target properties nor CMake variables like CMAKE_OBJCXX_FLAGS
seem to have any effect and are ignored. This breaks projects that previously worked without the OBJC or OBJCXX languages enabled.