MACOSX_DEPLOYMENT_TARGET is hardcoded also when compiling for iOS
I am building with iOS 10.2 SDK and need to support iOS 9 as well. I was happily using CMAKE_OSX_DEPLOYMENT_TARGET
when compiling for macOS 10.11 with 10.12 SDK, but somehow that didn't work for iOS, so I was digging around a bit. In the platform files I found a variable CMAKE_<LANG>_OSX_DEPLOYMENT_TARGET_FLAG
and overrode it to say -miphoneos-version-min=
when building for iOS, but that didn't help either.
In the end I discovered that none of that is used when generating Xcode projects and this is done via an IPHONEOS_DEPLOYMENT_TARGET
attribute in the Xcode project. However, the Xcode generator seems to be hardcoding MACOSX_DEPLOYMENT_TARGET
attribute no matter which platform is being used, see Source/cmGlobalXCodeGenerator.cxx:
const char* deploymentTarget =
this->CurrentMakefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
...
if (deploymentTarget && *deploymentTarget) {
buildSettings->AddAttribute("MACOSX_DEPLOYMENT_TARGET",
this->CreateString(deploymentTarget));
}
I think making CMAKE_OSX_DEPLOYMENT_TARGET
usable also on iOS would make sense, as other CMake "OSX" variables transitively work on iOS as well (such as CMAKE_OSX_SYSROOT
or CMAKE_OSX_ARCHITECTURES
). There are also the other Apple platforms like tvOS or watchOS, but I have zero experience there :)
Currently I'm working around this by not using CMAKE_OSX_DEPLOYMENT_TARGET
at all but setting the attribute directly via CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET
.
Thank you!