kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

ios.cmake (22020B)


      1 # This file is part of the ios-cmake project. It was retrieved from
      2 # https://github.com/cristeab/ios-cmake.git, which is a fork of
      3 # https://code.google.com/p/ios-cmake/. Which in turn is based off of
      4 # the Platform/Darwin.cmake and Platform/UnixPaths.cmake files which
      5 # are included with CMake 2.8.4
      6 #
      7 # The ios-cmake project is licensed under the new BSD license.
      8 #
      9 # Copyright (c) 2014, Bogdan Cristea and LTE Engineering Software,
     10 # Kitware, Inc., Insight Software Consortium.  All rights reserved.
     11 # Redistribution and use in source and binary forms, with or without
     12 # modification, are permitted provided that the following conditions
     13 # are met:
     14 # 1. Redistributions of source code must retain the above copyright
     15 # notice, this list of conditions and the following disclaimer.
     16 #
     17 # 2. Redistributions in binary form must reproduce the above copyright
     18 # notice, this list of conditions and the following disclaimer in the
     19 # documentation and/or other materials provided with the distribution.
     20 #
     21 # 3. Neither the name of the copyright holder nor the names of its
     22 # contributors may be used to endorse or promote products derived from
     23 # this software without specific prior written permission.
     24 #
     25 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     26 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     27 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     28 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     29 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     30 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     31 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     32 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     33 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     35 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36 # POSSIBILITY OF SUCH DAMAGE.
     37 #
     38 # This file is based off of the Platform/Darwin.cmake and
     39 # Platform/UnixPaths.cmake files which are included with CMake 2.8.4
     40 # It has been altered for iOS development.
     41 #
     42 # Updated by Alex Stewart ([email protected])
     43 #
     44 # *****************************************************************************
     45 #      Now maintained by Alexander Widerberg (widerbergaren [at] gmail.com)
     46 #                      under the BSD-3-Clause license
     47 #                   https://github.com/leetal/ios-cmake
     48 # *****************************************************************************
     49 #
     50 #                           INFORMATION / HELP
     51 #
     52 # The following variables control the behaviour of this toolchain:
     53 #
     54 # IOS_PLATFORM: OS (default) or SIMULATOR or SIMULATOR64 or TVOS or SIMULATOR_TVOS or WATCHOS or SIMULATOR_WATCHOS
     55 #    OS = Build for iPhoneOS.
     56 #    OS64 = Build for arm64 arm64e iPhoneOS.
     57 #    SIMULATOR = Build for x86 i386 iPhone Simulator.
     58 #    SIMULATOR64 = Build for x86_64 iPhone Simulator.
     59 #    TVOS = Build for AppleTVOS.
     60 #    SIMULATOR_TVOS = Build for x86_64 AppleTV Simulator.
     61 #    WATCHOS = Build for armv7k arm64_32 for WatchOS.
     62 #    SIMULATOR_WATCHOS = Build for x86_64 for Watch Simulator.
     63 # CMAKE_OSX_SYSROOT: Path to the iOS SDK to use.  By default this is
     64 #    automatically determined from IOS_PLATFORM and xcodebuild, but
     65 #    can also be manually specified (although this should not be required).
     66 # CMAKE_IOS_DEVELOPER_ROOT: Path to the Developer directory for the iOS platform
     67 #    being compiled for.  By default this is automatically determined from
     68 #    CMAKE_OSX_SYSROOT, but can also be manually specified (although this should
     69 #    not be required).
     70 # ENABLE_BITCODE: (1|0) Enables or disables bitcode support. Default 1 (true)
     71 # ENABLE_ARC: (1|0) Enables or disables ARC support. Default 1 (true, ARC enabled by default)
     72 # ENABLE_VISIBILITY: (1|0) Enables or disables symbol visibility support. Default 0 (false, visibility hidden by default)
     73 # IOS_ARCH: (armv7 armv7s armv7k arm64 arm64e arm64_32 i386 x86_64) If specified, will override the default architectures for the given IOS_PLATFORM
     74 #    OS = armv7 armv7s arm64 arm64e (if applicable)
     75 #    OS64 = arm64 arm64e (if applicable)
     76 #    SIMULATOR = i386
     77 #    SIMULATOR64 = x86_64
     78 #    TVOS = arm64
     79 #    SIMULATOR_TVOS = x86_64 (i386 has since long been deprecated)
     80 #    WATCHOS = armv7k arm64_32 (if applicable)
     81 #    SIMULATOR_WATCHOS = x86_64 (i386 has since long been deprecated)
     82 #
     83 # This toolchain defines the following variables for use externally:
     84 #
     85 # XCODE_VERSION: Version number (not including Build version) of Xcode detected.
     86 # IOS_SDK_VERSION: Version of iOS SDK being used.
     87 # CMAKE_OSX_ARCHITECTURES: Architectures being compiled for (generated from
     88 #    IOS_PLATFORM).
     89 #
     90 # This toolchain defines the following macros for use externally:
     91 #
     92 # set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE XCODE_VARIANT)
     93 #   A convenience macro for setting xcode specific properties on targets.
     94 #   Available variants are: All, Release, RelWithDebInfo, Debug, MinSizeRel
     95 #   example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1" "all").
     96 #
     97 # find_host_package (PROGRAM ARGS)
     98 #   A macro used to find executable programs on the host system, not within the
     99 #   iOS environment.  Thanks to the android-cmake project for providing the
    100 #   command.
    101 
    102 # Fix for PThread library not in path
    103 set(CMAKE_THREAD_LIBS_INIT "-lpthread")
    104 set(CMAKE_HAVE_THREADS_LIBRARY 1)
    105 set(CMAKE_USE_WIN32_THREADS_INIT 0)
    106 set(CMAKE_USE_PTHREADS_INIT 1)
    107 
    108 # Cache what generator is used
    109 set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE)
    110 
    111 # Get the Xcode version being used.
    112 execute_process(COMMAND xcodebuild -version
    113   OUTPUT_VARIABLE XCODE_VERSION
    114   ERROR_QUIET
    115   OUTPUT_STRIP_TRAILING_WHITESPACE)
    116 string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}")
    117 string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}")
    118 message(STATUS "Building with Xcode version: ${XCODE_VERSION}")
    119 # Default to building for iPhoneOS if not specified otherwise, and we cannot
    120 # determine the platform from the CMAKE_OSX_ARCHITECTURES variable. The use
    121 # of CMAKE_OSX_ARCHITECTURES is such that try_compile() projects can correctly
    122 # determine the value of IOS_PLATFORM from the root project, as
    123 # CMAKE_OSX_ARCHITECTURES is propagated to them by CMake.
    124 if (NOT DEFINED IOS_PLATFORM)
    125   if (CMAKE_OSX_ARCHITECTURES)
    126     if (CMAKE_OSX_ARCHITECTURES MATCHES ".*arm.*")
    127       set(IOS_PLATFORM "OS")
    128     elseif (CMAKE_OSX_ARCHITECTURES MATCHES "i386")
    129       set(IOS_PLATFORM "SIMULATOR")
    130     elseif (CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
    131       set(IOS_PLATFORM "SIMULATOR64")
    132     elseif (CMAKE_OSX_ARCHITECTURES MATCHES "armv7k")
    133       set(IOS_PLATFORM "WATCHOS")
    134     endif()
    135   endif()
    136   if (NOT IOS_PLATFORM)
    137     set(IOS_PLATFORM "OS")
    138   endif()
    139 endif()
    140 set(IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING
    141   "Type of iOS platform for which to build.")
    142 # Determine the platform name and architectures for use in xcodebuild commands
    143 # from the specified IOS_PLATFORM name.
    144 if (IOS_PLATFORM STREQUAL "OS")
    145   set(XCODE_IOS_PLATFORM iphoneos)
    146   if(NOT IOS_ARCH)
    147     if (XCODE_VERSION VERSION_GREATER 10.0)
    148       set(IOS_ARCH armv7 armv7s arm64 arm64e)
    149     else()
    150       set(IOS_ARCH armv7 armv7s arm64)
    151     endif()
    152   endif()
    153  elseif (IOS_PLATFORM STREQUAL "OS64")
    154   set(XCODE_IOS_PLATFORM iphoneos)
    155   if(NOT IOS_ARCH)
    156     if (XCODE_VERSION VERSION_GREATER 10.0)
    157       set(IOS_ARCH arm64 arm64e)
    158     else()
    159       set(IOS_ARCH arm64)
    160     endif()
    161   endif()
    162 elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
    163   set(XCODE_IOS_PLATFORM iphonesimulator)
    164   if(NOT IOS_ARCH)
    165     set(IOS_ARCH i386)
    166   endif()
    167   message(WARNING "SIMULATOR IS DEPRECATED. Consider using SIMULATOR64 instead.")
    168 elseif(IOS_PLATFORM STREQUAL "SIMULATOR64")
    169   set(XCODE_IOS_PLATFORM iphonesimulator)
    170   if(NOT IOS_ARCH)
    171     set(IOS_ARCH x86_64)
    172   endif()
    173 elseif (IOS_PLATFORM STREQUAL "TVOS")
    174   set(XCODE_IOS_PLATFORM appletvos)
    175   if(NOT IOS_ARCH)
    176     set(IOS_ARCH arm64)
    177   endif()
    178 elseif (IOS_PLATFORM STREQUAL "SIMULATOR_TVOS")
    179   set(XCODE_IOS_PLATFORM appletvsimulator)
    180   if(NOT IOS_ARCH)
    181     set(IOS_ARCH x86_64)
    182   endif()
    183 elseif (IOS_PLATFORM STREQUAL "WATCHOS")
    184   set(XCODE_IOS_PLATFORM watchos)
    185   if(NOT IOS_ARCH)
    186     if (XCODE_VERSION VERSION_GREATER 10.0)
    187       set(IOS_ARCH armv7k arm64_32)
    188     else()
    189       set(IOS_ARCH armv7k)
    190     endif()
    191   endif()
    192 elseif (IOS_PLATFORM STREQUAL "SIMULATOR_WATCHOS")
    193   set(XCODE_IOS_PLATFORM watchsimulator)
    194   if(NOT IOS_ARCH)
    195     set(IOS_ARCH x86_64)
    196   endif()
    197 else()
    198   message(FATAL_ERROR "Invalid IOS_PLATFORM: ${IOS_PLATFORM}")
    199 endif()
    200 message(STATUS "Configuring iOS build for platform: ${IOS_PLATFORM}, "
    201   "architecture(s): ${IOS_ARCH}")
    202 # If user did not specify the SDK root to use, then query xcodebuild for it.
    203 execute_process(COMMAND xcodebuild -version -sdk ${XCODE_IOS_PLATFORM} Path
    204     OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_INT
    205      OUTPUT_QUIET ERROR_QUIET
    206     OUTPUT_STRIP_TRAILING_WHITESPACE)
    207 # If user did not specify the SDK root to use, then query xcodebuild for it.
    208 if (NOT DEFINED CMAKE_OSX_SYSROOT OR (NOT CMAKE_OSX_SYSROOT STREQUAL CMAKE_OSX_SYSROOT_INT))
    209   execute_process(COMMAND xcodebuild -version -sdk ${XCODE_IOS_PLATFORM} Path
    210     OUTPUT_VARIABLE CMAKE_OSX_SYSROOT
    211     ERROR_QUIET
    212     OUTPUT_STRIP_TRAILING_WHITESPACE)
    213 endif()
    214 if (NOT EXISTS ${CMAKE_OSX_SYSROOT})
    215   message(SEND_ERROR "Please make sure that Xcode is installed and that the toolchain"
    216   "is pointing to the correct path. Please run:"
    217   "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer"
    218   "and see if that fixes the problem for you.")
    219   message(FATAL_ERROR "Invalid CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT} "
    220   "does not exist.")
    221 elseif(DEFINED CMAKE_OSX_SYSROOT)
    222   message(STATUS "Using manually set SDK path: ${CMAKE_OSX_SYSROOT} for platform: ${IOS_PLATFORM}")
    223 else()
    224    message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT} for platform: ${IOS_PLATFORM}")
    225 endif()
    226 # Specify minimum version of deployment target.
    227 if (NOT DEFINED IOS_DEPLOYMENT_TARGET)
    228   if (IOS_PLATFORM STREQUAL "WATCHOS" OR IOS_PLATFORM STREQUAL "SIMULATOR_WATCHOS")
    229     # Unless specified, SDK version 2.0 is used by default as minimum target version (watchOS).
    230     set(IOS_DEPLOYMENT_TARGET "2.0"
    231             CACHE STRING "Minimum iOS version to build for." )
    232   else()
    233     # Unless specified, SDK version 8.0 is used by default as minimum target version (iOS, tvOS).
    234     set(IOS_DEPLOYMENT_TARGET "8.0"
    235             CACHE STRING "Minimum iOS version to build for." )
    236   endif()
    237   message(STATUS "Using the default min-version since IOS_DEPLOYMENT_TARGET not provided!")
    238 endif()
    239 # Use bitcode or not
    240 if (NOT DEFINED ENABLE_BITCODE AND NOT IOS_ARCH MATCHES "((^|, )(i386|x86_64))+")
    241   # Unless specified, enable bitcode support by default
    242   set(ENABLE_BITCODE TRUE CACHE BOOL "Whether or not to enable bitcode")
    243   message(STATUS "Enabling bitcode support by default. ENABLE_BITCODE not provided!")
    244 endif()
    245 if (NOT DEFINED ENABLE_BITCODE)
    246   message(STATUS "Disabling bitcode support by default on simulators. ENABLE_BITCODE not provided for override!")
    247 endif()
    248 # Use ARC or not
    249 if (NOT DEFINED ENABLE_ARC)
    250   # Unless specified, enable ARC support by default
    251   set(ENABLE_ARC TRUE CACHE BOOL "Whether or not to enable ARC")
    252   message(STATUS "Enabling ARC support by default. ENABLE_ARC not provided!")
    253 endif()
    254 # Use hidden visibility or not
    255 if (NOT DEFINED ENABLE_VISIBILITY)
    256   # Unless specified, disable symbols visibility by default
    257   set(ENABLE_VISIBILITY FALSE CACHE BOOL "Whether or not to hide symbols (-fvisibility=hidden)")
    258   message(STATUS "Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!")
    259 endif()
    260 # Get the SDK version information.
    261 execute_process(COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion
    262   OUTPUT_VARIABLE IOS_SDK_VERSION
    263   ERROR_QUIET
    264   OUTPUT_STRIP_TRAILING_WHITESPACE)
    265 # Find the Developer root for the specific iOS platform being compiled for
    266 # from CMAKE_OSX_SYSROOT.  Should be ../../ from SDK specified in
    267 # CMAKE_OSX_SYSROOT.  There does not appear to be a direct way to obtain
    268 # this information from xcrun or xcodebuild.
    269 if (NOT CMAKE_IOS_DEVELOPER_ROOT)
    270   get_filename_component(IOS_PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT} PATH)
    271   get_filename_component(CMAKE_IOS_DEVELOPER_ROOT ${IOS_PLATFORM_SDK_DIR} PATH)
    272 endif()
    273 if (NOT EXISTS ${CMAKE_IOS_DEVELOPER_ROOT})
    274   message(FATAL_ERROR "Invalid CMAKE_IOS_DEVELOPER_ROOT: "
    275     "${CMAKE_IOS_DEVELOPER_ROOT} does not exist.")
    276 endif()
    277 # Find the C & C++ compilers for the specified SDK.
    278 if (NOT CMAKE_C_COMPILER)
    279   execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang
    280     OUTPUT_VARIABLE CMAKE_C_COMPILER
    281     ERROR_QUIET
    282     OUTPUT_STRIP_TRAILING_WHITESPACE)
    283   message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}")
    284 endif()
    285 if (NOT CMAKE_CXX_COMPILER)
    286   execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang++
    287     OUTPUT_VARIABLE CMAKE_CXX_COMPILER
    288     ERROR_QUIET
    289     OUTPUT_STRIP_TRAILING_WHITESPACE)
    290   message(STATUS "Using CXX compiler: ${CMAKE_CXX_COMPILER}")
    291 endif()
    292 # Find (Apple's) libtool.
    293 execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find libtool
    294   OUTPUT_VARIABLE IOS_LIBTOOL
    295   ERROR_QUIET
    296   OUTPUT_STRIP_TRAILING_WHITESPACE)
    297 message(STATUS "Using libtool: ${IOS_LIBTOOL}")
    298 # Configure libtool to be used instead of ar + ranlib to build static libraries.
    299 # This is required on Xcode 7+, but should also work on previous versions of
    300 # Xcode.
    301 set(CMAKE_C_CREATE_STATIC_LIBRARY
    302   "${IOS_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ")
    303 set(CMAKE_CXX_CREATE_STATIC_LIBRARY
    304   "${IOS_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ")
    305 # Get the version of Darwin (OS X) of the host.
    306 execute_process(COMMAND uname -r
    307   OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION
    308   ERROR_QUIET
    309   OUTPUT_STRIP_TRAILING_WHITESPACE)
    310 # Standard settings.
    311 set(CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL "")
    312 set(CMAKE_SYSTEM_VERSION ${IOS_SDK_VERSION} CACHE INTERNAL "")
    313 set(UNIX TRUE CACHE BOOL "")
    314 set(APPLE TRUE CACHE BOOL "")
    315 set(IOS TRUE CACHE BOOL "")
    316 set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
    317 set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE)
    318 # Force unset of OS X-specific deployment target (otherwise autopopulated),
    319 # required as of cmake 2.8.10.
    320 set(CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING
    321   "Must be empty for iOS builds." FORCE)
    322 # Set the architectures for which to build.
    323 set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE STRING "Build architecture for iOS")
    324 # Change the type of target generated for try_compile() so it'll work when cross-compiling
    325 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
    326 # All iOS/Darwin specific settings - some may be redundant.
    327 set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
    328 set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
    329 set(CMAKE_SHARED_MODULE_PREFIX "lib")
    330 set(CMAKE_SHARED_MODULE_SUFFIX ".so")
    331 set(CMAKE_C_COMPILER_ABI ELF)
    332 set(CMAKE_CXX_COMPILER_ABI ELF)
    333 set(CMAKE_C_HAS_ISYSROOT 1)
    334 set(CMAKE_CXX_HAS_ISYSROOT 1)
    335 set(CMAKE_MODULE_EXISTS 1)
    336 set(CMAKE_DL_LIBS "")
    337 set(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
    338 set(CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
    339 set(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
    340 set(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
    341 
    342 if(IOS_ARCH MATCHES "((^|, )(arm64|arm64e|x86_64))+")
    343   set(CMAKE_C_SIZEOF_DATA_PTR 8)
    344   set(CMAKE_CXX_SIZEOF_DATA_PTR 8)
    345   message(STATUS "Using a data_ptr size of 8")
    346 else()
    347   set(CMAKE_C_SIZEOF_DATA_PTR 4)
    348   set(CMAKE_CXX_SIZEOF_DATA_PTR 4)
    349   message(STATUS "Using a data_ptr size of 4")
    350 endif()
    351 
    352 message(STATUS "Building for minimum iOS version: ${IOS_DEPLOYMENT_TARGET}"
    353                " (SDK version: ${IOS_SDK_VERSION})")
    354 # Note that only Xcode 7+ supports the newer more specific:
    355 # -m${XCODE_IOS_PLATFORM}-version-min flags, older versions of Xcode use:
    356 # -m(ios/ios-simulator)-version-min instead.
    357 if (IOS_PLATFORM STREQUAL "OS" OR IOS_PLATFORM STREQUAL "OS64")
    358   if (XCODE_VERSION VERSION_LESS 7.0)
    359     set(XCODE_IOS_PLATFORM_VERSION_FLAGS
    360       "-mios-version-min=${IOS_DEPLOYMENT_TARGET}")
    361   else()
    362     # Xcode 7.0+ uses flags we can build directly from XCODE_IOS_PLATFORM.
    363     set(XCODE_IOS_PLATFORM_VERSION_FLAGS
    364       "-m${XCODE_IOS_PLATFORM}-version-min=${IOS_DEPLOYMENT_TARGET}")
    365   endif()
    366 elseif (IOS_PLATFORM STREQUAL "TVOS")
    367   set(XCODE_IOS_PLATFORM_VERSION_FLAGS
    368     "-mtvos-version-min=${IOS_DEPLOYMENT_TARGET}")
    369 elseif (IOS_PLATFORM STREQUAL "SIMULATOR_TVOS")
    370   set(XCODE_IOS_PLATFORM_VERSION_FLAGS
    371     "-mtvos-simulator-version-min=${IOS_DEPLOYMENT_TARGET}")
    372 elseif (IOS_PLATFORM STREQUAL "WATCHOS")
    373   set(XCODE_IOS_PLATFORM_VERSION_FLAGS
    374     "-mwatchos-version-min=${IOS_DEPLOYMENT_TARGET}")
    375 elseif (IOS_PLATFORM STREQUAL "SIMULATOR_WATCHOS")
    376   set(XCODE_IOS_PLATFORM_VERSION_FLAGS
    377     "-mwatchos-simulator-version-min=${IOS_DEPLOYMENT_TARGET}")
    378 else()
    379   # SIMULATOR or SIMULATOR64 both use -mios-simulator-version-min.
    380   set(XCODE_IOS_PLATFORM_VERSION_FLAGS
    381     "-mios-simulator-version-min=${IOS_DEPLOYMENT_TARGET}")
    382 endif()
    383 message(STATUS "Version flags set to: ${XCODE_IOS_PLATFORM_VERSION_FLAGS}")
    384 
    385 if (ENABLE_BITCODE)
    386   set(BITCODE "-fembed-bitcode")
    387   set(HEADER_PAD "")
    388   set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE ON)
    389   message(STATUS "Enabling bitcode support.")
    390 else()
    391   set(BITCODE "")
    392   set(HEADER_PAD "-headerpad_max_install_names")
    393   set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE OFF)
    394   message(STATUS "Disabling bitcode support.")
    395 endif()
    396 
    397 if (ENABLE_ARC)
    398   set(FOBJC_ARC "-fobjc-arc")
    399   message(STATUS "Enabling ARC support.")
    400 else()
    401   set(FOBJC_ARC "-fno-objc-arc")
    402   message(STATUS "Disabling ARC support.")
    403 endif()
    404 
    405 if (NOT ENABLE_VISIBILITY)
    406   set(VISIBILITY "-fvisibility=hidden")
    407   message(STATUS "Hiding symbols (-fvisibility=hidden).")
    408 else()
    409   set(VISIBILITY "")
    410 endif()
    411 
    412 set(CMAKE_C_FLAGS
    413 "${XCODE_IOS_PLATFORM_VERSION_FLAGS} ${BITCODE} -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_C_FLAGS}")
    414 # Hidden visibilty is required for C++ on iOS.
    415 set(CMAKE_CXX_FLAGS
    416 "${XCODE_IOS_PLATFORM_VERSION_FLAGS} ${BITCODE} ${VISIBILITY} -fvisibility-inlines-hidden -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_CXX_FLAGS}")
    417 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g ${BITCODE} ${CMAKE_CXX_FLAGS_DEBUG}")
    418 set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG -Os -ffast-math ${BITCODE} ${CMAKE_CXX_FLAGS_MINSIZEREL}")
    419 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG -O2 -g -ffast-math ${BITCODE} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
    420 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -ffast-math ${BITCODE} ${CMAKE_CXX_FLAGS_RELEASE}")
    421 set(CMAKE_C_LINK_FLAGS "${XCODE_IOS_PLATFORM_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
    422 set(CMAKE_CXX_LINK_FLAGS "${XCODE_IOS_PLATFORM_VERSION_FLAGS}  -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
    423 
    424 # In order to ensure that the updated compiler flags are used in try_compile()
    425 # tests, we have to forcibly set them in the CMake cache, not merely set them
    426 # in the local scope.
    427 list(APPEND VARS_TO_FORCE_IN_CACHE
    428   CMAKE_C_FLAGS
    429   CMAKE_CXX_FLAGS
    430   CMAKE_CXX_FLAGS_DEBUG
    431   CMAKE_CXX_FLAGS_RELWITHDEBINFO
    432   CMAKE_CXX_FLAGS_MINSIZEREL
    433   CMAKE_CXX_FLAGS_RELEASE
    434   CMAKE_C_LINK_FLAGS
    435   CMAKE_CXX_LINK_FLAGS)
    436 foreach(VAR_TO_FORCE ${VARS_TO_FORCE_IN_CACHE})
    437   set(${VAR_TO_FORCE} "${${VAR_TO_FORCE}}" CACHE STRING "")
    438 endforeach()
    439 
    440 set(CMAKE_PLATFORM_HAS_INSTALLNAME 1)
    441 set (CMAKE_SHARED_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks")
    442 set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib ${HEADER_PAD}")
    443 set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle ${HEADER_PAD}")
    444 set(CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
    445 set(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
    446 set(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
    447 
    448 # Hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old
    449 # build tree (where install_name_tool was hardcoded) and where
    450 # CMAKE_INSTALL_NAME_TOOL isn't in the cache and still cmake didn't fail in
    451 # CMakeFindBinUtils.cmake (because it isn't rerun) hardcode
    452 # CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did
    453 # before, Alex.
    454 if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
    455   find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
    456 endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
    457 
    458 # Set the find root to the iOS developer roots and to user defined paths.
    459 set(CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_OSX_SYSROOT}
    460   ${CMAKE_PREFIX_PATH} CACHE string  "iOS find search path root" FORCE)
    461 # Default to searching for frameworks first.
    462 set(CMAKE_FIND_FRAMEWORK FIRST)
    463 # Set up the default search directories for frameworks.
    464 set(CMAKE_SYSTEM_FRAMEWORK_PATH
    465   ${CMAKE_OSX_SYSROOT}/System/Library/Frameworks
    466   ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks
    467   ${CMAKE_OSX_SYSROOT}/Developer/Library/Frameworks)
    468 # Only search the specified iOS SDK, not the remainder of the host filesystem.
    469 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
    470 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    471 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    472 # This little macro lets you set any XCode specific property.
    473 macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE XCODE_RELVERSION)
    474   set(XCODE_RELVERSION_I "${XCODE_RELVERSION}")
    475   if (XCODE_RELVERSION_I STREQUAL "All")
    476     set_property(TARGET ${TARGET} PROPERTY
    477     XCODE_ATTRIBUTE_${XCODE_PROPERTY} "${XCODE_VALUE}")
    478   else()
    479     set_property(TARGET ${TARGET} PROPERTY
    480     XCODE_ATTRIBUTE_${XCODE_PROPERTY}[variant=${XCODE_RELVERSION_I}] "${XCODE_VALUE}")
    481   endif()
    482 endmacro(set_xcode_property)
    483 # This macro lets you find executable programs on the host system.
    484 macro(find_host_package)
    485   set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    486   set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
    487   set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
    488   set(IOS FALSE)
    489   find_package(${ARGN})
    490   set(IOS TRUE)
    491   set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
    492   set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    493   set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    494 endmacro(find_host_package)