| 1 |
# Portions Copyright (c) 2017-2022, The Monero Project |
| 2 |
# This file is based off of the https://code.google.com/archive/p/ios-cmake/ |
| 3 |
# It has been altered for Monero iOS development |
| 4 |
# |
| 5 |
# |
| 6 |
# Options: |
| 7 |
# |
| 8 |
# IOS_PLATFORM = OS (default) or SIMULATOR or SIMULATOR64 |
| 9 |
# This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders |
| 10 |
# OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch. |
| 11 |
# SIMULATOR - used to build for the Simulator platforms, which have an x86 arch. |
| 12 |
# |
| 13 |
# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder |
| 14 |
# By default this location is automatcially chosen based on the IOS_PLATFORM value above. |
| 15 |
# If set manually, it will override the default location and force the user of a particular Developer Platform |
| 16 |
# |
| 17 |
# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder |
| 18 |
# By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value. |
| 19 |
# In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path. |
| 20 |
# If set manually, this will force the use of a specific SDK version |
| 21 |
|
| 22 |
|
| 23 |
# Standard settings |
| 24 |
set (CMAKE_SYSTEM_NAME Darwin) |
| 25 |
set (CMAKE_SYSTEM_VERSION 1) |
| 26 |
set (UNIX True) |
| 27 |
set (APPLE True) |
| 28 |
set (IOS True) |
| 29 |
|
| 30 |
# Required as of cmake 2.8.10 |
| 31 |
set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE) |
| 32 |
|
| 33 |
# Determine the cmake host system version so we know where to find the iOS SDKs |
| 34 |
find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin) |
| 35 |
if (CMAKE_UNAME) |
| 36 |
exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION) |
| 37 |
string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}") |
| 38 |
endif (CMAKE_UNAME) |
| 39 |
|
| 40 |
# Force the compilers to gcc for iOS |
| 41 |
include (CMakeForceCompiler) |
| 42 |
# set (MAKE_C_COMPILER "/usr/bin/gcc Apple") |
| 43 |
# set (CMAKE_CXX_COMPILER "/usr/bin/g++ Apple") |
| 44 |
set(CMAKE_AR ar CACHE FILEPATH "" FORCE) |
| 45 |
|
| 46 |
# Skip the platform compiler checks for cross compiling |
| 47 |
set (CMAKE_CXX_COMPILER_WORKS TRUE) |
| 48 |
set (CMAKE_C_COMPILER_WORKS TRUE) |
| 49 |
|
| 50 |
# All iOS/Darwin specific settings - some may be redundant |
| 51 |
set (CMAKE_SHARED_LIBRARY_PREFIX "lib") |
| 52 |
set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib") |
| 53 |
set (CMAKE_SHARED_MODULE_PREFIX "lib") |
| 54 |
set (CMAKE_SHARED_MODULE_SUFFIX ".so") |
| 55 |
set (CMAKE_MODULE_EXISTS 1) |
| 56 |
set (CMAKE_DL_LIBS "") |
| 57 |
|
| 58 |
set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ") |
| 59 |
set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ") |
| 60 |
set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") |
| 61 |
set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") |
| 62 |
|
| 63 |
# Hidden visibilty is required for cxx on iOS |
| 64 |
set (CMAKE_C_FLAGS_INIT "") |
| 65 |
set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden") |
| 66 |
|
| 67 |
set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") |
| 68 |
set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") |
| 69 |
|
| 70 |
set (CMAKE_PLATFORM_HAS_INSTALLNAME 1) |
| 71 |
set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names") |
| 72 |
set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names") |
| 73 |
set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,") |
| 74 |
set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,") |
| 75 |
set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a") |
| 76 |
|
| 77 |
# Setup iOS platform unless specified manually with IOS_PLATFORM |
| 78 |
if (NOT DEFINED IOS_PLATFORM) |
| 79 |
set (IOS_PLATFORM "OS") |
| 80 |
endif (NOT DEFINED IOS_PLATFORM) |
| 81 |
set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform") |
| 82 |
|
| 83 |
# Setup building for arm64 or not |
| 84 |
if (NOT DEFINED BUILD_ARM64) |
| 85 |
set (BUILD_ARM64 true) |
| 86 |
endif (NOT DEFINED BUILD_ARM64) |
| 87 |
set (BUILD_ARM64 ${BUILD_ARM64} CACHE STRING "Build arm64 arch or not") |
| 88 |
|
| 89 |
# Check the platform selection and setup for developer root |
| 90 |
if (${IOS_PLATFORM} STREQUAL "OS") |
| 91 |
set (IOS_PLATFORM_LOCATION "iPhoneOS.platform") |
| 92 |
|
| 93 |
# This causes the installers to properly locate the output libraries |
| 94 |
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos") |
| 95 |
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") |
| 96 |
set (SIMULATOR true) |
| 97 |
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") |
| 98 |
|
| 99 |
# This causes the installers to properly locate the output libraries |
| 100 |
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") |
| 101 |
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64") |
| 102 |
set (SIMULATOR true) |
| 103 |
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") |
| 104 |
|
| 105 |
# This causes the installers to properly locate the output libraries |
| 106 |
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") |
| 107 |
else (${IOS_PLATFORM} STREQUAL "OS") |
| 108 |
message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR") |
| 109 |
endif (${IOS_PLATFORM} STREQUAL "OS") |
| 110 |
|
| 111 |
# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT |
| 112 |
# Note Xcode 4.3 changed the installation location, choose the most recent one available |
| 113 |
exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR) |
| 114 |
set (XCODE_POST_43_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer") |
| 115 |
set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") |
| 116 |
if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) |
| 117 |
if (EXISTS ${XCODE_POST_43_ROOT}) |
| 118 |
set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT}) |
| 119 |
elseif(EXISTS ${XCODE_PRE_43_ROOT}) |
| 120 |
set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT}) |
| 121 |
endif (EXISTS ${XCODE_POST_43_ROOT}) |
| 122 |
endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) |
| 123 |
set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform") |
| 124 |
|
| 125 |
# Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT |
| 126 |
if (NOT DEFINED CMAKE_IOS_SDK_ROOT) |
| 127 |
file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*") |
| 128 |
if (_CMAKE_IOS_SDKS) |
| 129 |
list (SORT _CMAKE_IOS_SDKS) |
| 130 |
list (REVERSE _CMAKE_IOS_SDKS) |
| 131 |
list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT) |
| 132 |
else (_CMAKE_IOS_SDKS) |
| 133 |
message (FATAL_ERROR "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.") |
| 134 |
endif (_CMAKE_IOS_SDKS) |
| 135 |
message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}") |
| 136 |
endif (NOT DEFINED CMAKE_IOS_SDK_ROOT) |
| 137 |
set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK") |
| 138 |
|
| 139 |
# Set the sysroot default to the most recent SDK |
| 140 |
set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support") |
| 141 |
|
| 142 |
# set the architecture for iOS |
| 143 |
if (NOT DEFINED ARCH) |
| 144 |
set (ARCH armv7) |
| 145 |
endif() |
| 146 |
set (IOS_ARCH ${ARCH}) |
| 147 |
|
| 148 |
set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS") |
| 149 |
message(STATUS "ios arch: ${IOS_ARCH}") |
| 150 |
|
| 151 |
# Set the find root to the iOS developer roots and to user defined paths |
| 152 |
set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root") |
| 153 |
|
| 154 |
# default to searching for frameworks first |
| 155 |
set (CMAKE_FIND_FRAMEWORK FIRST) |
| 156 |
|
| 157 |
# set up the default search directories for frameworks |
| 158 |
set (CMAKE_SYSTEM_FRAMEWORK_PATH |
| 159 |
${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks |
| 160 |
${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks |
| 161 |
${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks |
| 162 |
) |
| 163 |
|
| 164 |
message(STATUS "IOS CMAKE conf finished") |