2011-08-23 19:19:58 +08:00
# This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake
# files which are included with CMake 2.8.4
# It has been altered for iOS development
set ( UNIX 1 )
set ( APPLE 1 )
set ( IOS 1 )
# Darwin versions:
# 6.x == Mac OSX 10.2
# 7.x == Mac OSX 10.3
# 8.x == Mac OSX 10.4
# 9.x == Mac OSX 10.5
# 10.x == Mac OSX 10.6 (Snow Leopard)
string ( REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_SYSTEM_VERSION}" )
string ( REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\2" DARWIN_MINOR_VERSION "${CMAKE_SYSTEM_VERSION}" )
# Do not use the "-Wl,-search_paths_first" flag with the OSX 10.2 compiler.
# Done this way because it is too early to do a TRY_COMPILE.
if ( NOT DEFINED HAVE_FLAG_SEARCH_PATHS_FIRST )
2012-10-17 07:18:30 +08:00
set ( HAVE_FLAG_SEARCH_PATHS_FIRST 0 )
if ( "${DARWIN_MAJOR_VERSION}" GREATER 6 )
set ( HAVE_FLAG_SEARCH_PATHS_FIRST 1 )
endif ( "${DARWIN_MAJOR_VERSION}" GREATER 6 )
2011-08-23 19:19:58 +08:00
endif ( NOT DEFINED HAVE_FLAG_SEARCH_PATHS_FIRST )
# More desirable, but does not work:
#INCLUDE(CheckCXXCompilerFlag)
#CHECK_CXX_COMPILER_FLAG("-Wl,-search_paths_first" HAVE_FLAG_SEARCH_PATHS_FIRST)
set ( CMAKE_SHARED_LIBRARY_PREFIX "lib" )
set ( CMAKE_SHARED_LIBRARY_SUFFIX ".dylib" )
set ( CMAKE_SHARED_MODULE_PREFIX "lib" )
set ( CMAKE_SHARED_MODULE_SUFFIX ".so" )
set ( CMAKE_MODULE_EXISTS 1 )
set ( CMAKE_DL_LIBS "" )
set ( CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version " )
set ( CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version " )
set ( CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}" )
set ( CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}" )
2017-01-21 00:16:01 +08:00
# Additional flags for dynamic framework
if ( APPLE_FRAMEWORK AND BUILD_SHARED_LIBS )
set ( CMAKE_MODULE_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks" )
set ( CMAKE_SHARED_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks" )
set ( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG 1 )
set ( CMAKE_INSTALL_NAME_DIR "@rpath" )
endif ( )
2012-10-17 07:18:30 +08:00
# Hidden visibilty is required for cxx on iOS
2014-10-17 20:46:47 +08:00
set ( no_warn "-Wno-unused-function -Wno-overloaded-virtual" )
2015-11-11 21:12:35 +08:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${no_warn}" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -fvisibility=hidden -fvisibility-inlines-hidden ${no_warn}" )
2012-08-20 23:36:36 +08:00
2017-11-28 22:03:40 +08:00
set ( CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3 -ffast-math" )
2017-12-06 20:49:45 +08:00
if ( NOT IOS_ARCH STREQUAL "armv7" AND NOT IOS_ARCH STREQUAL "armv7s" )
2017-11-28 22:03:40 +08:00
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer" )
endif ( )
2014-10-01 15:44:28 +08:00
2011-08-23 19:19:58 +08:00
if ( HAVE_FLAG_SEARCH_PATHS_FIRST )
2012-10-17 07:18:30 +08:00
set ( CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}" )
set ( CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}" )
2011-08-23 19:19:58 +08:00
endif ( HAVE_FLAG_SEARCH_PATHS_FIRST )
set ( CMAKE_PLATFORM_HAS_INSTALLNAME 1 )
set ( CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names" )
set ( CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names" )
set ( CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader," )
set ( CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader," )
set ( CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a" )
# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
if ( NOT DEFINED CMAKE_INSTALL_NAME_TOOL )
2012-10-17 07:18:30 +08:00
find_program ( CMAKE_INSTALL_NAME_TOOL install_name_tool )
2011-08-23 19:19:58 +08:00
endif ( NOT DEFINED CMAKE_INSTALL_NAME_TOOL )
# Setup iOS developer location
if ( IPHONEOS )
2012-10-17 07:18:30 +08:00
set ( _CMAKE_IOS_DEVELOPER_ROOT "/Developer/Platforms/iPhoneOS.platform/Developer" )
2011-08-23 19:19:58 +08:00
else ( )
2012-10-17 07:18:30 +08:00
if ( IPHONESIMULATOR )
set ( _CMAKE_IOS_DEVELOPER_ROOT "/Developer/Platforms/iPhoneSimulator.platform/Developer" )
endif ( )
2011-08-23 19:19:58 +08:00
endif ( )
# Find installed iOS SDKs
file ( GLOB _CMAKE_IOS_SDKS "${_CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*" )
2012-10-17 07:18:30 +08:00
# Find and use the most recent iOS sdk
if ( _CMAKE_IOS_SDKS )
list ( SORT _CMAKE_IOS_SDKS )
list ( REVERSE _CMAKE_IOS_SDKS )
list ( GET _CMAKE_IOS_SDKS 0 _CMAKE_IOS_SDK_ROOT )
2011-08-23 19:19:58 +08:00
2012-10-17 07:18:30 +08:00
# Set the sysroot default to the most recent SDK
set ( CMAKE_OSX_SYSROOT ${ _CMAKE_IOS_SDK_ROOT } CACHE PATH "Sysroot used for iOS support" )
2011-08-23 19:19:58 +08:00
2012-10-17 07:18:30 +08:00
# 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
set ( CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_BIT)" CACHE string "Build architecture for iOS" )
2011-08-23 19:19:58 +08:00
2012-10-17 07:18:30 +08:00
# Set the default based on this file and not the environment variable
set ( CMAKE_FIND_ROOT_PATH ${ _CMAKE_IOS_DEVELOPER_ROOT } ${ _CMAKE_IOS_SDK_ROOT } CACHE string "iOS library search path root" )
2011-08-23 19:19:58 +08:00
2012-10-17 07:18:30 +08:00
# default to searching for frameworks first
set ( CMAKE_FIND_FRAMEWORK FIRST )
2011-08-23 19:19:58 +08:00
2012-10-17 07:18:30 +08:00
# set up the default search directories for frameworks
set ( CMAKE_SYSTEM_FRAMEWORK_PATH
$ { _ C M A K E _ I O S _ S D K _ R O O T } / S y s t e m / L i b r a r y / F r a m e w o r k s
$ { _ C M A K E _ I O S _ S D K _ R O O T } / S y s t e m / L i b r a r y / P r i v a t e F r a m e w o r k s
$ { _ C M A K E _ I O S _ S D K _ R O O T } / D e v e l o p e r / L i b r a r y / F r a m e w o r k s
)
2011-08-23 19:19:58 +08:00
endif ( _CMAKE_IOS_SDKS )
if ( "${CMAKE_BACKWARDS_COMPATIBILITY}" MATCHES "^1\\.[0-6]$" )
2012-10-17 07:18:30 +08:00
set ( CMAKE_SHARED_MODULE_CREATE_C_FLAGS "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -flat_namespace -undefined suppress" )
2011-08-23 19:19:58 +08:00
endif ( "${CMAKE_BACKWARDS_COMPATIBILITY}" MATCHES "^1\\.[0-6]$" )
if ( NOT XCODE )
2012-10-17 07:18:30 +08:00
# Enable shared library versioning. This flag is not actually referenced
# but the fact that the setting exists will cause the generators to support
# soname computation.
set ( CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name" )
2011-08-23 19:19:58 +08:00
endif ( NOT XCODE )
# Xcode does not support -isystem yet.
if ( XCODE )
2012-10-17 07:18:30 +08:00
set ( CMAKE_INCLUDE_SYSTEM_FLAG_C )
set ( CMAKE_INCLUDE_SYSTEM_FLAG_CXX )
2011-08-23 19:19:58 +08:00
endif ( XCODE )
# Need to list dependent shared libraries on link line. When building
# with -isysroot (for universal binaries), the linker always looks for
# dependent libraries under the sysroot. Listing them on the link
# line works around the problem.
set ( CMAKE_LINK_DEPENDENT_LIBRARY_FILES 1 )
set ( CMAKE_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w )
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w )
set ( CMAKE_C_CREATE_SHARED_LIBRARY
2012-10-17 07:18:30 +08:00
" < C M A K E _ C _ C O M P I L E R > < L A N G U A G E _ C O M P I L E _ F L A G S > < C M A K E _ S H A R E D _ L I B R A R Y _ C R E A T E _ C _ F L A G S > < L I N K _ F L A G S > - o < T A R G E T > - i n s t a l l _ n a m e < T A R G E T _ I N S T A L L N A M E _ D I R > < T A R G E T _ S O N A M E > < O B J E C T S > < L I N K _ L I B R A R I E S > " )
2011-08-23 19:19:58 +08:00
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY
2012-10-17 07:18:30 +08:00
" < C M A K E _ C X X _ C O M P I L E R > < L A N G U A G E _ C O M P I L E _ F L A G S > < C M A K E _ S H A R E D _ L I B R A R Y _ C R E A T E _ C X X _ F L A G S > < L I N K _ F L A G S > - o < T A R G E T > - i n s t a l l _ n a m e < T A R G E T _ I N S T A L L N A M E _ D I R > < T A R G E T _ S O N A M E > < O B J E C T S > < L I N K _ L I B R A R I E S > " )
2011-08-23 19:19:58 +08:00
set ( CMAKE_CXX_CREATE_SHARED_MODULE
2012-10-17 07:18:30 +08:00
" < C M A K E _ C X X _ C O M P I L E R > < L A N G U A G E _ C O M P I L E _ F L A G S > < C M A K E _ S H A R E D _ M O D U L E _ C R E A T E _ C X X _ F L A G S > < L I N K _ F L A G S > - o < T A R G E T > < O B J E C T S > < L I N K _ L I B R A R I E S > " )
2011-08-23 19:19:58 +08:00
set ( CMAKE_C_CREATE_SHARED_MODULE
2012-10-17 07:18:30 +08:00
" < C M A K E _ C _ C O M P I L E R > < L A N G U A G E _ C O M P I L E _ F L A G S > < C M A K E _ S H A R E D _ M O D U L E _ C R E A T E _ C _ F L A G S > < L I N K _ F L A G S > - o < T A R G E T > < O B J E C T S > < L I N K _ L I B R A R I E S > " )
2011-08-23 19:19:58 +08:00
set ( CMAKE_C_CREATE_MACOSX_FRAMEWORK
2012-10-17 07:18:30 +08:00
" < C M A K E _ C _ C O M P I L E R > < L A N G U A G E _ C O M P I L E _ F L A G S > < C M A K E _ S H A R E D _ L I B R A R Y _ C R E A T E _ C _ F L A G S > < L I N K _ F L A G S > - o < T A R G E T > - i n s t a l l _ n a m e < T A R G E T _ I N S T A L L N A M E _ D I R > < T A R G E T _ S O N A M E > < O B J E C T S > < L I N K _ L I B R A R I E S > " )
2011-08-23 19:19:58 +08:00
set ( CMAKE_CXX_CREATE_MACOSX_FRAMEWORK
2012-10-17 07:18:30 +08:00
" < C M A K E _ C X X _ C O M P I L E R > < L A N G U A G E _ C O M P I L E _ F L A G S > < C M A K E _ S H A R E D _ L I B R A R Y _ C R E A T E _ C X X _ F L A G S > < L I N K _ F L A G S > - o < T A R G E T > - i n s t a l l _ n a m e < T A R G E T _ I N S T A L L N A M E _ D I R > < T A R G E T _ S O N A M E > < O B J E C T S > < L I N K _ L I B R A R I E S > " )
2011-08-23 19:19:58 +08:00
# Add the install directory of the running cmake to the search directories
# CMAKE_ROOT is CMAKE_INSTALL_PREFIX/share/cmake, so we need to go two levels up
get_filename_component ( _CMAKE_INSTALL_DIR "${CMAKE_ROOT}" PATH )
get_filename_component ( _CMAKE_INSTALL_DIR "${_CMAKE_INSTALL_DIR}" PATH )
2012-10-17 07:18:30 +08:00
2011-08-23 19:19:58 +08:00
# List common installation prefixes. These will be used for all search types
list ( APPEND CMAKE_SYSTEM_PREFIX_PATH
2012-10-17 07:18:30 +08:00
# Standard
$ { _ C M A K E _ I O S _ D E V E L O P E R _ R O O T } / u s r
$ { _ C M A K E _ I O S _ S D K _ R O O T } / u s r
2011-08-23 19:19:58 +08:00
2012-10-17 07:18:30 +08:00
# CMake install location
" $ { _ C M A K E _ I N S T A L L _ D I R } "
2011-08-23 19:19:58 +08:00
2012-10-17 07:18:30 +08:00
# Project install destination.
" $ { C M A K E _ I N S T A L L _ P R E F I X } "
2013-08-21 21:26:54 +08:00
)