iOS: Xcode: cmake --build . should automatically add -allowProvisioningUpdates option when the Xcode version supports it
With a free / personal Apple team account, trying to build a new iOS project (device, not simulator), with a new bundle id that was never used before, from the command line can fail because there is no available provisioning profile.
cmake_minimum_required(VERSION 3.14)
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "")
set(CMAKE_OSX_SYSROOT iphoneos)
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer")
set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "xyz") <--------------- replace with your own Apple team id
set(CMAKE_OSX_DEPLOYMENT_TARGET "10" CACHE STRING "")
project(ios_app LANGUAGES CXX)
if(APPLE)
set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.alroito.cmake-testapp-provision-v2")
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "0.1")
set(MACOSX_BUNDLE_LONG_VERSION_STRING "0.1")
set(MACOSX_BUNDLE_BUNDLE_VERSION "0.1")
endif()
set(main_cpp "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
file(GENERATE OUTPUT "${main_cpp}" CONTENT "int main() { return 0; }")
add_executable(app "${main_cpp}")
$ cmake .. -GXcode -DCMAKE_SYSTEM_NAME=iOS
-- The CXX compiler identification is AppleClang 12.0.0.12000032
....
-- Configuring done
-- Generating done
-- Build files have been written to: /Volumes/T3/Dev/projects/cmake/ios/minimal_ios_auto_provisioning/build
$ cmake --build .
....
error: No profiles for 'com.alroito.cmake-testapp-provision-v2' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.alroito.cmake-testapp-provision-v2'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'app' from project 'ios_app')
** BUILD FAILED **
Following the advice of adding -allowProvisioningUpdates
$ cmake --build . -- -allowProvisioningUpdates
....
CodeSign /Volumes/T3/Dev/projects/cmake/ios/minimal_ios_auto_provisioning/build/Debug-iphoneos/app.app (in target 'app' from project 'ios_app')
Signing Identity: "Apple Development: xxxxx yyyyyy"
Provisioning Profile: "iOS Team Provisioning Profile: com.alroito.cmake-testapp-provision-v2"
(zzzzzzzzzzzzzzzzzzzzzzzzz)
...
** BUILD SUCCEEDED **
It would be nice if cmake --build .
would automatically add that option if the Xcode version supports it. Perhaps it can be controlled by a new policy or global option?
The Xcode version that introduced the option is >=9. Relevant qmake change https://codereview.qt-project.org/c/qt/qtbase/+/370000/2/mkspecs/features/uikit/xcodebuild.mk