1 # This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake
2 # files which are included with CMake 2.8.4
3 # It has been altered for iOS development
7 # IOS_PLATFORM = OS (default) or SIMULATOR
8 # This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders
9 # OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch.
10 # SIMULATOR - used to build for the Simulator platforms, which have an x86 arch.
12 # CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder
13 # By default this location is automatcially chosen based on the IOS_PLATFORM value above.
14 # If set manually, it will override the default location and force the user of a particular Developer Platform
16 # CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
17 # By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.
18 # In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path.
19 # If set manually, this will force the use of a specific SDK version
23 # set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE)
24 # A convenience macro for setting xcode specific properties on targets
25 # example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1")
27 # find_host_package (PROGRAM ARGS)
28 # A macro used to find executable programs on the host system, not within the iOS environment.
29 # Thanks to the android-cmake project for providing the command
33 set (CMAKE_SYSTEM_NAME Darwin)
34 set (CMAKE_SYSTEM_VERSION 1)
38 set (CMAKE_CXX_PLATFORM_ID IOS)
40 # Determine the cmake host system version so we know where to find the iOS SDKs
41 find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
43 exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
44 string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
47 # Force the compilers to gcc for iOS
48 include (CMakeForceCompiler)
49 CMAKE_FORCE_C_COMPILER (gcc gcc)
50 CMAKE_FORCE_CXX_COMPILER (g++ g++)
52 # Skip the platform compiler checks for cross compiling
53 set (CMAKE_CXX_COMPILER_WORKS TRUE)
54 set (CMAKE_C_COMPILER_WORKS TRUE)
56 # All iOS/Darwin specific settings - some may be redundant
57 set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
58 set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
59 set (CMAKE_SHARED_MODULE_PREFIX "lib")
60 set (CMAKE_SHARED_MODULE_SUFFIX ".so")
61 set (CMAKE_MODULE_EXISTS 1)
62 set (CMAKE_DL_LIBS "")
64 set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
65 set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
66 set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
67 set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
69 # Hidden visibilty is required for cxx on iOS
70 set (CMAKE_C_FLAGS_INIT "")
71 set (CMAKE_CXX_FLAGS_INIT "-headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden")
73 set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
74 set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
76 set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
77 set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
78 set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
79 set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
80 set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
81 set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
83 # hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
84 # (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
85 # and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
86 # hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
87 if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
88 find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
89 endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
91 # Setup iOS platform unless specified manually with IOS_PLATFORM
92 if (NOT DEFINED IOS_PLATFORM)
93 set (IOS_PLATFORM "OS")
94 endif (NOT DEFINED IOS_PLATFORM)
95 set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
97 # Check the platform selection and setup for developer root
98 if (${IOS_PLATFORM} STREQUAL "OS")
99 set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
101 # This causes the installers to properly locate the output libraries
102 set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
103 elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
104 set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
106 # This causes the installers to properly locate the output libraries
107 set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
108 else (${IOS_PLATFORM} STREQUAL "OS")
109 message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
110 endif (${IOS_PLATFORM} STREQUAL "OS")
112 # Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
113 # Note Xcode 4.3 changed the installation location, choose the most recent one available
114 set (XCODE_POST_43_ROOT "/Applications/Xcode.app/Contents/Developer/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")
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/*")
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 seach 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")
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")
142 # set the architecture for iOS
143 # NOTE: Currently both ARCHS_STANDARD_32_BIT and ARCHS_UNIVERSAL_IPHONE_OS set armv7 only, so set both manually
144 if (${IOS_PLATFORM} STREQUAL "OS")
145 set (IOS_ARCH armv6 armv7)
146 else (${IOS_PLATFORM} STREQUAL "OS")
148 endif (${IOS_PLATFORM} STREQUAL "OS")
150 set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")
152 # Set the find root to the iOS developer roots and to user defined paths
153 set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root")
155 # default to searching for frameworks first
156 set (CMAKE_FIND_FRAMEWORK FIRST)
158 # set up the default search directories for frameworks
159 set (CMAKE_SYSTEM_FRAMEWORK_PATH
160 ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
161 ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
162 ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
165 # only search the iOS sdks, not the remainder of the host filesystem
166 set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
167 set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
168 set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
171 # This little macro lets you set any XCode specific property
172 macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
173 set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
174 endmacro (set_xcode_property)
177 # This macro lets you find executable programs on the host system
178 macro (find_host_package)
179 set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
180 set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
181 set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
184 find_package(${ARGN})
187 set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
188 set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
189 set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
190 endmacro (find_host_package)