• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
4set (UNIX 1)
5set (APPLE 1)
6set (IOS 1)
7
8# Darwin versions:
9#   6.x == Mac OSX 10.2
10#   7.x == Mac OSX 10.3
11#   8.x == Mac OSX 10.4
12#   9.x == Mac OSX 10.5
13#  10.x == Mac OSX 10.6 (Snow Leopard)
14string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_SYSTEM_VERSION}")
15string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\2" DARWIN_MINOR_VERSION "${CMAKE_SYSTEM_VERSION}")
16
17# Do not use the "-Wl,-search_paths_first" flag with the OSX 10.2 compiler.
18# Done this way because it is too early to do a TRY_COMPILE.
19if (NOT DEFINED HAVE_FLAG_SEARCH_PATHS_FIRST)
20    set (HAVE_FLAG_SEARCH_PATHS_FIRST 0)
21    if ("${DARWIN_MAJOR_VERSION}" GREATER 6)
22        set (HAVE_FLAG_SEARCH_PATHS_FIRST 1)
23    endif ("${DARWIN_MAJOR_VERSION}" GREATER 6)
24endif (NOT DEFINED HAVE_FLAG_SEARCH_PATHS_FIRST)
25# More desirable, but does not work:
26#INCLUDE(CheckCXXCompilerFlag)
27#CHECK_CXX_COMPILER_FLAG("-Wl,-search_paths_first" HAVE_FLAG_SEARCH_PATHS_FIRST)
28
29set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
30set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
31set (CMAKE_SHARED_MODULE_PREFIX "lib")
32set (CMAKE_SHARED_MODULE_SUFFIX ".so")
33set (CMAKE_MODULE_EXISTS 1)
34set (CMAKE_DL_LIBS "")
35
36set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
37set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
38set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
39set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
40
41# Hidden visibilty is required for cxx on iOS
42set (no_warn "-Wno-unused-function -Wno-overloaded-virtual")
43set (CMAKE_C_FLAGS "${no_warn}")
44set (CMAKE_CXX_FLAGS "-stdlib=libc++ -fvisibility=hidden -fvisibility-inlines-hidden ${no_warn}")
45
46set (CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3 -fomit-frame-pointer -ffast-math")
47
48if (HAVE_FLAG_SEARCH_PATHS_FIRST)
49    set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
50    set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
51endif (HAVE_FLAG_SEARCH_PATHS_FIRST)
52
53set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
54set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
55set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
56set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
57set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
58set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
59
60# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
61# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
62# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
63# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
64if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
65    find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
66endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
67
68# Setup iOS developer location
69if (IPHONEOS)
70    set (_CMAKE_IOS_DEVELOPER_ROOT "/Developer/Platforms/iPhoneOS.platform/Developer")
71else ()
72    if (IPHONESIMULATOR)
73        set (_CMAKE_IOS_DEVELOPER_ROOT "/Developer/Platforms/iPhoneSimulator.platform/Developer")
74    endif ()
75endif ()
76# Find installed iOS SDKs
77file (GLOB _CMAKE_IOS_SDKS "${_CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
78
79# Find and use the most recent iOS sdk
80if (_CMAKE_IOS_SDKS)
81    list (SORT _CMAKE_IOS_SDKS)
82    list (REVERSE _CMAKE_IOS_SDKS)
83    list (GET _CMAKE_IOS_SDKS 0 _CMAKE_IOS_SDK_ROOT)
84
85    # Set the sysroot default to the most recent SDK
86    set (CMAKE_OSX_SYSROOT ${_CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
87
88    # set the architecture for iOS - this env var sets armv6,armv7 and appears to be XCode's standard. The other found is ARCHS_UNIVERSAL_IPHONE_OS but that is armv7 only
89    set (CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_BIT)" CACHE string  "Build architecture for iOS")
90
91    # Set the default based on this file and not the environment variable
92    set (CMAKE_FIND_ROOT_PATH ${_CMAKE_IOS_DEVELOPER_ROOT} ${_CMAKE_IOS_SDK_ROOT} CACHE string  "iOS library search path root")
93
94    # default to searching for frameworks first
95    set (CMAKE_FIND_FRAMEWORK FIRST)
96
97    # set up the default search directories for frameworks
98    set (CMAKE_SYSTEM_FRAMEWORK_PATH
99        ${_CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
100        ${_CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
101        ${_CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
102    )
103endif (_CMAKE_IOS_SDKS)
104
105if ("${CMAKE_BACKWARDS_COMPATIBILITY}" MATCHES "^1\\.[0-6]$")
106    set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -flat_namespace -undefined suppress")
107endif ("${CMAKE_BACKWARDS_COMPATIBILITY}" MATCHES "^1\\.[0-6]$")
108
109if (NOT XCODE)
110      # Enable shared library versioning.  This flag is not actually referenced
111      # but the fact that the setting exists will cause the generators to support
112      # soname computation.
113      set (CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name")
114endif (NOT XCODE)
115
116# Xcode does not support -isystem yet.
117if (XCODE)
118    set (CMAKE_INCLUDE_SYSTEM_FLAG_C)
119    set (CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
120endif (XCODE)
121
122# Need to list dependent shared libraries on link line.  When building
123# with -isysroot (for universal binaries), the linker always looks for
124# dependent libraries under the sysroot.  Listing them on the link
125# line works around the problem.
126set (CMAKE_LINK_DEPENDENT_LIBRARY_FILES 1)
127
128set (CMAKE_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w)
129set (CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w)
130
131set (CMAKE_C_CREATE_SHARED_LIBRARY
132    "<CMAKE_C_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <LINK_FLAGS> -o <TARGET> -install_name <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
133set (CMAKE_CXX_CREATE_SHARED_LIBRARY
134    "<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <LINK_FLAGS> -o <TARGET> -install_name <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
135
136set (CMAKE_CXX_CREATE_SHARED_MODULE
137    "<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
138
139set (CMAKE_C_CREATE_SHARED_MODULE
140    "<CMAKE_C_COMPILER>  <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_MODULE_CREATE_C_FLAGS> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
141
142set (CMAKE_C_CREATE_MACOSX_FRAMEWORK
143    "<CMAKE_C_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <LINK_FLAGS> -o <TARGET> -install_name <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
144set (CMAKE_CXX_CREATE_MACOSX_FRAMEWORK
145    "<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <LINK_FLAGS> -o <TARGET> -install_name <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
146
147
148# Add the install directory of the running cmake to the search directories
149# CMAKE_ROOT is CMAKE_INSTALL_PREFIX/share/cmake, so we need to go two levels up
150get_filename_component (_CMAKE_INSTALL_DIR "${CMAKE_ROOT}" PATH)
151get_filename_component (_CMAKE_INSTALL_DIR "${_CMAKE_INSTALL_DIR}" PATH)
152
153# List common installation prefixes.  These will be used for all search types
154list (APPEND CMAKE_SYSTEM_PREFIX_PATH
155    # Standard
156    ${_CMAKE_IOS_DEVELOPER_ROOT}/usr
157    ${_CMAKE_IOS_SDK_ROOT}/usr
158
159    # CMake install location
160    "${_CMAKE_INSTALL_DIR}"
161
162    # Project install destination.
163    "${CMAKE_INSTALL_PREFIX}"
164)
165