Backported #6865: Disable websockets command line option
[platform/upstream/freerdp.git] / cmake / iOSToolchain.cmake
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
4
5 # Options:
6 #
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.
11 #
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
15 #
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
20
21 # Macros:
22 #
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")
26 #
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
30
31
32 # Standard settings
33 set (CMAKE_SYSTEM_NAME Darwin)
34 set (CMAKE_SYSTEM_VERSION 1)
35 set (UNIX True)
36 set (APPLE True)
37 set (IOS True)
38
39 # Required as of cmake 2.8.10
40 #set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
41
42 # Determine the cmake host system version so we know where to find the iOS SDKs
43 find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
44 if (CMAKE_UNAME)
45         exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
46         string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
47 endif (CMAKE_UNAME)
48
49 # Force the compilers to gcc for iOS
50 include (CMakeForceCompiler)
51 CMAKE_FORCE_C_COMPILER (/usr/bin/clang Apple)
52 CMAKE_FORCE_CXX_COMPILER (/usr/bin/clang++ Apple)
53 set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
54
55 # Skip the platform compiler checks for cross compiling
56 #set (CMAKE_CXX_COMPILER_WORKS TRUE)
57 #set (CMAKE_C_COMPILER_WORKS TRUE)
58
59 # All iOS/Darwin specific settings - some may be redundant
60 set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
61 set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
62 set (CMAKE_SHARED_MODULE_PREFIX "lib")
63 set (CMAKE_SHARED_MODULE_SUFFIX ".so")
64 set (CMAKE_MODULE_EXISTS 1)
65 set (CMAKE_DL_LIBS "")
66
67 set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
68 set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
69 set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
70 set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
71
72 # Hidden visibilty is required for cxx on iOS 
73 set (CMAKE_C_FLAGS_INIT "")
74 set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden -isysroot ${CMAKE_OSX_SYSROOT}")
75
76 set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
77 set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
78
79 set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
80 set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
81 set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
82 set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
83 set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
84 set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
85
86 # hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
87 # (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
88 # and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
89 # hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
90 if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
91         find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
92 endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
93
94 # Setup iOS platform unless specified manually with IOS_PLATFORM
95 if (NOT DEFINED IOS_PLATFORM)
96         set (IOS_PLATFORM "OS")
97 endif (NOT DEFINED IOS_PLATFORM)
98 set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
99
100 # Check the platform selection and setup for developer root
101 if (${IOS_PLATFORM} STREQUAL "OS")
102         set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
103
104         # This causes the installers to properly locate the output libraries
105         set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
106 elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
107         set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
108
109         # This causes the installers to properly locate the output libraries
110         set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
111 else (${IOS_PLATFORM} STREQUAL "OS")
112         message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
113 endif (${IOS_PLATFORM} STREQUAL "OS")
114
115 # Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
116 # Note Xcode 4.3 changed the installation location, choose the most recent one available
117 set (XCODE_POST_43_ROOT "/Applications/Xcode.app/Contents/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
118 set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
119 if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
120         if (EXISTS ${XCODE_POST_43_ROOT})
121                 set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
122         elseif(EXISTS ${XCODE_PRE_43_ROOT})
123                 set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
124         endif (EXISTS ${XCODE_POST_43_ROOT})
125 endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
126 set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
127
128 # Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT
129 if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
130         file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
131         if (_CMAKE_IOS_SDKS) 
132                 list (SORT _CMAKE_IOS_SDKS)
133                 list (REVERSE _CMAKE_IOS_SDKS)
134                 list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
135         else (_CMAKE_IOS_SDKS)
136                 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.")
137         endif (_CMAKE_IOS_SDKS)
138         message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
139 endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
140 set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
141
142 # Set the sysroot default to the most recent SDK
143 set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
144
145 # set the architecture for iOS 
146 # NOTE: Currently both ARCHS_STANDARD_32_BIT and ARCHS_UNIVERSAL_IPHONE_OS set armv7 only, so set both manually
147 if (${IOS_PLATFORM} STREQUAL "OS")
148         set (IOS_ARCH armv7 armv7s)
149         set (CMAKE_SYSTEM_PROCESSOR armv7)
150 else (${IOS_PLATFORM} STREQUAL "OS")
151         set (IOS_ARCH i386)
152         set (CMAKE_SYSTEM_PROCESSOR i386)
153 endif (${IOS_PLATFORM} STREQUAL "OS")
154
155 set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string  "Build architecture for iOS")
156
157 # Set the find root to the iOS developer roots and to user defined paths
158 set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string  "iOS find search path root")
159
160 # default to searching for frameworks first
161 set (CMAKE_FIND_FRAMEWORK FIRST)
162
163 # set up the default search directories for frameworks
164 set (CMAKE_SYSTEM_FRAMEWORK_PATH
165         ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
166         ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
167         ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
168 )
169
170 # only search the iOS sdks, not the remainder of the host filesystem
171 set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
172 set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
173 set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
174
175
176 # This little macro lets you set any XCode specific property
177 macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
178         set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
179 endmacro (set_xcode_property)
180
181
182 # This macro lets you find executable programs on the host system
183 macro (find_host_package)
184         set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
185         set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
186         set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
187         set (IOS FALSE)
188
189         find_package(${ARGN})
190
191         set (IOS TRUE)
192         set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
193         set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
194         set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
195 endmacro (find_host_package)
196