First I set CMake generator to XCode in QT Creator Kits settings page:
and QT Creator started to run CMake with the following output:
[cmake] Running /opt/local/bin/cmake -S /Users/admin/dev/repos/examples/src/LinesGame/LinesGameQt -B /Users/admin/dev/repos/examples/src/LinesGame/LinesGameQt/build/Desktop_x86_darwin_generic_mach_o_64bit -DCMAKE_GENERATOR:STRING=Xcode -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=/Users/admin/dev/repos/examples/src/LinesGame/LinesGameQt/build/Desktop_x86_darwin_generic_mach_o_64bit/.qtc/package-manager/auto-setup.cmake -DQT_QMAKE_EXECUTABLE:FILEPATH=/Users/admin/dev/libs/QT6/release/MacOs/bin/qmake6 -DCMAKE_PREFIX_PATH:PATH=/Users/admin/dev/libs/QT6/release/MacOs -DCMAKE_C_COMPILER:FILEPATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -DCMAKE_CXX_COMPILER:FILEPATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -DCMAKE_CXX_FLAGS_INIT:STRING= in /Users/admin/dev/repos/examples/src/LinesGame/LinesGameQt/build/Desktop_x86_darwin_generic_mach_o_64bit.
[cmake] -- The CXX compiler identification is AppleClang 15.0.0.15000309
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
[cmake] -- Found Threads: TRUE
[cmake] -- Found ZLIB: /opt/local/lib/libz.dylib (found version "1.3.1")
[cmake] -- Found WrapSystemZLIB: TRUE
[cmake] -- Using system ZLIB.
[cmake] -- Found WrapZLIB: TRUE
[cmake] -- Performing Test HAVE_STDATOMIC
[cmake] -- Performing Test HAVE_STDATOMIC - Success
[cmake] -- Found WrapAtomic: TRUE
[cmake] -- Looking for backtrace
[cmake] -- Looking for backtrace - found
[cmake] -- backtrace facility detected in default set of libraries
[cmake] -- Found Backtrace: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include
[cmake] -- Using Qt bundled PCRE2.
[cmake] -- Found WrapPCRE2: TRUE
[cmake] -- Performing Test HAVE_GETTIME
[cmake] -- Performing Test HAVE_GETTIME - Success
[cmake] -- Performing Test HAVE_SHM_OPEN_SHM_UNLINK
[cmake] -- Performing Test HAVE_SHM_OPEN_SHM_UNLINK - Success
[cmake] -- Found WrapRt: TRUE
[cmake] -- Found OpenGL: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/System/Library/Frameworks/OpenGL.framework
[cmake] -- Found WrapOpenGL: TRUE
[cmake] -- Using Qt bundled PNG.
[cmake] -- Found WrapPNG: TRUE
[cmake] -- Using Qt bundled Harfbuzz.
[cmake] -- Found WrapHarfbuzz: TRUE
[cmake] -- Using Qt bundled Freetype.
[cmake] -- Found WrapFreetype: TRUE
[cmake] -- Using Qt bundled Jpeg.
[cmake] -- Found WrapJpeg: TRUE
[cmake] -- Performing Test HAVE_LIBRESOLV_FUNCTIONS
[cmake] -- Performing Test HAVE_LIBRESOLV_FUNCTIONS - Success
[cmake] -- Found WrapResolv: TRUE
[cmake] -- Found GSSAPI: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/System/Library/Frameworks/GSS.framework
[cmake] -- Found AVFoundation: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/System/Library/Frameworks/AVFoundation.framework
[cmake] Using home made implementation of std::jthread.
[cmake] CMAKE_SYSTEM_VERSION: 23.4.0
[cmake] Posix native platform.
[cmake] AWL_PLATFORM_DIR: ../../../lib/Awl/Platforms/Posix
[cmake] -- Could NOT find Boost (missing: Boost_INCLUDE_DIR)
[cmake] BOOST not found, AWL will compile without BOOST.
[cmake] Applying the workaround for QT Creator.
[cmake] Detected locale "C" with character encoding "US-ASCII", which is not UTF-8.
[cmake] Qt depends on a UTF-8 locale, and has switched to "UTF-8" instead.
[cmake] If this causes problems, reconfigure your locale. See the locale(1) manual
[cmake] for more information.
[cmake] -- Configuring done (16.0s)
[cmake] -- Generating done (0.1s)
[cmake] -- Build files have been written to: /Users/admin/dev/repos/examples/src/LinesGame/LinesGameQt/build/Desktop_x86_darwin_generic_mach_o_64bit
[cmake]
[cmake] Elapsed time: 00:17.
But when I tried to build the project with XCode I got the following errors:
probably because iOS and Desktop apps have different provisioning profiles, so I generated new CRS file with Keychain Access:
and uploaded it to Apple Developer website:
after that I downloaded the certificate as mac_app.cer
file, doubly clicked on it and the command
/usr/bin/env xcrun security find-identity -v -p codesigning
started to display new certificate at 4-th line:
created new profile:
clicked “Download Manual Profiles” button in XCode and a file with .provisionprofile
extension appeared in ~/Library/MobileDevice/Provisioning\ Profiles
folder.
Specified the following attributes in CMake:
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "1B2435791E92A2CEEE544A19851F1BE20B0D5303"
XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER "05013f4c-a5c4-4fca-95a4-1da073089aa4")
and was able to build the project in XCode, but when I clicked Project->Archive the following message appeared:
I selected “Update and Build”, it asked the password two times:
and created the archive, but when I tried to upload it I got the following errors:
Asset validation failed
The product archive is invalid. The Info.plist must contain a LSApplicationCategoryType key, whose value is the UTI for a valid category. For more details, see “Submitting your Mac apps to the App Store”. (ID: 0dc8b4ec-f1cd-4ea4-b374-8aac687d94b9)Asset validation failed
App sandbox not enabled. The following executables must include the “com.apple.security.app-sandbox” entitlement with a Boolean value of true in the entitlements property list: [( “com.sharlines.lines.pkg/Payload/Classic Lines.app/Contents/MacOS/Classic Lines” )] Refer to App Sandbox page at https://developer.apple.com/documentation/security/app_sandbox for more information on sandboxing your app. (ID: 74d67b9e-874a-474b-baa2-1492332ef43d)
Also XCode was unable to run signed app and displayed the following message:
Could not launch Classic Lines
Domain: IDELaunchErrorDomain
Code: 20
Recovery Suggestion: Runningboard has returned error 5. Please check the system logs for the underlying cause of the error.
User Info: {
DVTErrorCreationDateKey = "2024-04-30 21:37:13 +0000";
DVTRadarComponentKey = 968756;
IDERunOperationFailingWorker = IDELaunchServicesLauncher;
}
--
Could not launch “Classic Lines”
Domain: IDELaunchErrorDomain
Code: 20
Recovery Suggestion: Runningboard has returned error 5. Please check the system logs for the underlying cause of the error.
User Info: {
DVTRadarComponentKey = 968756;
IDERunOperationFailingWorker = IDELaunchServicesLauncher;
}
--
The operation couldn’t be completed. Launch failed.
Domain: RBSRequestErrorDomain
Code: 5
Failure Reason: Launch failed.
--
Launchd job spawn failed
Domain: NSPOSIXErrorDomain
Code: 162
--
Event Metadata: com.apple.dt.IDERunOperationWorkerFinished : {
"device_model" = "MacBookAir8,1";
"device_osBuild" = "14.4.1 (23E224)";
"device_platform" = "com.apple.platform.macosx";
"dvt_coredevice_version" = "355.24";
"dvt_mobiledevice_version" = "1643.100.58";
"launchSession_schemeCommand" = Run;
"launchSession_state" = 1;
"launchSession_targetArch" = "x86_64";
"operation_duration_ms" = 388;
"operation_errorCode" = 20;
"operation_errorDomain" = IDELaunchErrorDomain;
"operation_errorWorker" = IDELaunchServicesLauncher;
"operation_name" = IDERunOperationWorkerGroup;
"param_debugger_attachToExtensions" = 0;
"param_debugger_attachToXPC" = 1;
"param_debugger_type" = 3;
"param_destination_isProxy" = 0;
"param_destination_platform" = "com.apple.platform.macosx";
"param_diag_MainThreadChecker_stopOnIssue" = 0;
"param_diag_MallocStackLogging_enableDuringAttach" = 0;
"param_diag_MallocStackLogging_enableForXPC" = 1;
"param_diag_allowLocationSimulation" = 1;
"param_diag_checker_tpc_enable" = 1;
"param_diag_gpu_frameCapture_enable" = 0;
"param_diag_gpu_shaderValidation_enable" = 0;
"param_diag_gpu_validation_enable" = 0;
"param_diag_memoryGraphOnResourceException" = 0;
"param_diag_queueDebugging_enable" = 1;
"param_diag_runtimeProfile_generate" = 0;
"param_diag_sanitizer_asan_enable" = 0;
"param_diag_sanitizer_tsan_enable" = 0;
"param_diag_sanitizer_tsan_stopOnIssue" = 0;
"param_diag_sanitizer_ubsan_stopOnIssue" = 0;
"param_diag_showNonLocalizedStrings" = 0;
"param_diag_viewDebugging_enabled" = 1;
"param_diag_viewDebugging_insertDylibOnLaunch" = 1;
"param_install_style" = 0;
"param_launcher_UID" = 2;
"param_launcher_allowDeviceSensorReplayData" = 0;
"param_launcher_kind" = 0;
"param_launcher_style" = 99;
"param_launcher_substyle" = 8192;
"param_runnable_appExtensionHostRunMode" = 0;
"param_runnable_productType" = "com.apple.product-type.application";
"param_structuredConsoleMode" = 1;
"param_testing_launchedForTesting" = 0;
"param_testing_suppressSimulatorApp" = 0;
"param_testing_usingCLI" = 0;
"sdk_canonicalName" = "macosx14.4";
"sdk_osVersion" = "14.4";
"sdk_variant" = macos;
}
--
System Information
macOS Version 14.4.1 (Build 23E224)
Xcode 15.3 (22618) (Build 15E204a)
Timestamp: 2024-04-30T14:37:13-07:00
I added the following elements:
<key>LSApplicationCategoryType</key>
<string>public.app-category.board-games</string>
<key>com.apple.security.app-sandbox</key>
<true/>
but still get
Found the following lines in XCode project file:
1C35453BA1AA4863993B4DFA /* Info.plist */ = {isa = PBXFileReference; explicitFileType = sourcecode.text.plist; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = build/Desktop_x86_darwin_generic_mach_o_64bit/CMakeFiles/LinesGameQt.dir/Info.plist; sourceTree = SOURCE_ROOT; };
...
INFOPLIST_FILE = /Users/admin/dev/repos/examples/src/LinesGame/LinesGameQt/build/Desktop_x86_darwin_generic_mach_o_64bit/CMakeFiles/LinesGameQt.dir/Info.plist;
but XCode project file does not contain Sandbox
or Entitlements
.
I created a separate file Entitlements.macos.plist
file without com.apple.security.inherit
that causes a crash with the following text in the crash report:
Application Specific Information:
Process is not in an inherited sandbox.
so Entitlements.macos.plist
contains only com.apple.security.app-sandbox
element:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
</dict>
</plist>
added the following to CMake:
XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS ${CMAKE_CURRENT_SOURCE_DIR}/ios/Entitlements.macos.plist
and was able to upload my app:
and it successfully run with TestFlight:
https://stackoverflow.com/questions/21527036/app-sandbox-not-enabled
https://forums.developer.apple.com/forums/thread/99105
https://forums.developer.apple.com/forums/thread/41400
AppStore rejects SandBox of MacOS app with externally built console binaries
https://stackoverflow.com/questions/49096263/appstore-rejects-sandbox-of-macos-app-with-externally-built-console-binaries
[CMake] CMake and Sandboxed Mac OS X app
https://cmake.org/pipermail/cmake/2011-November/047683.html
https://cmake.cmake.narkive.com/q4MqajrN/and-sandboxed-mac-os-x-app
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
PROPERTIES OBJECT_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.entitlements)
This means that I only have to add the following parameters to my codesign
call: “–entitlements MyEntitlements.plist”
https://stackoverflow.com/questions/41558187/xcode-entitlements-dont-appear-enabled-with-cmake
set_target_properties(TargetApp PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS
“${CMAKE_CURRENT_LIST_DIR}/TargetApp.entitlements”)
The app icon set “AppIcon” has an unassigned child
https://stackoverflow.com/questions/35320432/the-app-icon-set-appicon-has-an-unassigned-child
Select the unassigned image and delete it via delete button. Clean and Build.
CMake seems to ignore CMAKE_OSX_DEPLOYMENT_TARGET
https://stackoverflow.com/questions/34208360/cmake-seems-to-ignore-cmake-osx-deployment-target
The variable CMAKE_OSX_DEPLOYMENT_TARGET must initialized as a cache variable prior to the first project() command in order for the Xcode project generation to be picked up properly:
set(CMAKE_OSX_DEPLOYMENT_TARGET “10.9” CACHE STRING “Minimum OS X deployment version”)
How do I build cmake from source as universal(arm64 and x86_64) binary on Mac?
https://discourse.cmake.org/t/how-do-i-build-cmake-from-source-as-universal-arm64-and-x86-64-binary-on-mac/5862
You need to tell CMake what is going on “-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64”. Just doing it as flags makes CMake unaware that multi-arch binaries are being made and confuses some things.
CMAKE_APPLE_SILICON_PROCESSOR
https://cmake.org/cmake/help/latest/variable/CMAKE_APPLE_SILICON_PROCESSOR.html
New in version 3.19.2.
On Apple Silicon hosts running macOS, set this variable to tell CMake what architecture to use for CMAKE_HOST_SYSTEM_PROCESSOR. The value must be either arm64 or x86_64.
The value of this variable should never be modified by project code. It is meant to be set as a cache entry provided by the user, e.g. via -DCMAKE_APPLE_SILICON_PROCESSOR=….
https://discourse.cmake.org/t/how-to-set-cmake-osx-deployment-target-conditionally/7772
Our project uses a single CMakeLists.txt file for both iOS and MacOS apps. We would like to set CMAKE_OSX_DEPLOYMENT_TARGET from the CMakeLists.txt file depending on the target OS(iOS, MacOS).
CMAKE_OSX_DEPLOYMENT_TARGET has to be set before project() call and CMAKE_SYSTEM_NAME would be undefined before project() call. Do we have any way to set CMAKE_OSX_DEPLOYMENT_TARGET conditionally?
==============
You could take advantage of the fact that CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET will override CMAKE_OSX_DEPLOYMENT_TARGET for iOS. Set the former to your iOS deployment target the latter to your macOS deployment target. In theory, I think that should work.
CMAKE_OSX_DEPLOYMENT_TARGET does not take an effect with iOS
https://stackoverflow.com/questions/78418185/cmake-osx-deployment-target-does-not-take-an-effect-with-ios
With MacOS this generates correct MACOSX_DEPLOYMENT_TARGET in XCode project, but with iOS it has no effect and IPHONEOS_DEPLOYMENT_TARGET = 11.0 is generated in XCode project, while according to docs it should also apply to iOS.
https://stackoverflow.com/questions/30022527/cmake-xcode-specify-platform
SET (CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET 6.0)
https://github.com/wang-bin/ios.cmake/blob/master/ios.cmake
# Specify minimum version of deployment target.
# Unless specified, the latest SDK version is used by default.
set(IOS_DEPLOYMENT_TARGET “${IOS_SDK_VERSION}” CACHE STRING “Minimum iOS version to build for.” )
message(STATUS “Building for minimum iOS version: ${IOS_DEPLOYMENT_TARGET} (SDK version: ${IOS_SDK_VERSION})”)
set(CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET “${IOS_DEPLOYMENT_TARGET}”)
https://stackoverflow.com/questions/75013303/how-to-set-cmake-osx-architectures-in-cmakelists-depending-on-debug-or-release-c
if(CMAKE_BUILD_TYPE STREQUAL “Release”)
set(CMAKE_OSX_ARCHITECTURES arm64 x86_64)
endif()
Xcode keeps asking for password to use the System Keychain
https://stackoverflow.com/questions/10068566/xcode-keeps-asking-for-password-to-use-the-system-keychain
CMAKE_OSX_DEPLOYMENT_TARGET does not take an effect with iOS
https://stackoverflow.com/questions/78418185/cmake-osx-deployment-target-does-not-take-an-effect-with-ios
cmake .. -GXcode -DCMAKE_SYSTEM_NAME=iOS
if (APPLE)
if(CMAKE_SYSTEM_NAME STREQUAL “iOS”)
set(CMAKE_OSX_DEPLOYMENT_TARGET “14.0” CACHE STRING “Minimum iOS deployment version”)
else()
endif()