toolchain-ios.cmake 4.31 KB
Newer Older
Ghislain MARY's avatar
Ghislain MARY committed
1
############################################################################
2
# toolchain-ios.cmake
Ghislain MARY's avatar
Ghislain MARY committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# Copyright (C) 2014  Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
############################################################################

# Building for iOS is only available under APPLE systems
if(NOT APPLE)
	message(FATAL_ERROR "You need to build using a Mac OS X system")
26
endif()
Ghislain MARY's avatar
Ghislain MARY committed
27

Ghislain MARY's avatar
Ghislain MARY committed
28 29 30 31 32
execute_process(COMMAND xcode-select -print-path
	RESULT_VARIABLE XCODE_SELECT_RESULT
	OUTPUT_VARIABLE XCODE_PATH
	OUTPUT_STRIP_TRAILING_WHITESPACE
)
Ghislain MARY's avatar
Ghislain MARY committed
33 34
if(NOT ${XCODE_SELECT_RESULT} EQUAL 0)
	message(FATAL_ERROR "xcode-select failed: ${XCODE_SELECT_RESULT}. You may need to install Xcode.")
35
endif()
Ghislain MARY's avatar
Ghislain MARY committed
36

jehan's avatar
jehan committed
37 38
string(TOLOWER ${PLATFORM}  PLATFORM_LOWER)

Ghislain MARY's avatar
Ghislain MARY committed
39 40 41 42 43 44 45
execute_process(COMMAND xcrun --sdk iphone${PLATFORM_LOWER} --show-sdk-version
	RESULT_VARIABLE XCRUN_SHOW_SDK_VERSION_RESULT
	OUTPUT_VARIABLE IOS_SDK_VERSION
	OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT ${XCRUN_SHOW_SDK_VERSION_RESULT} EQUAL 0)
	message(FATAL_ERROR "xcrun failed: ${XCRUN_SHOW_SDK_VERSION_RESULT}. You may need to install Xcode.")
jehan's avatar
jehan committed
46 47
endif()

Ghislain MARY's avatar
Ghislain MARY committed
48 49 50 51 52 53 54
execute_process(COMMAND xcrun --sdk iphone${PLATFORM_LOWER} --show-sdk-path
	RESULT_VARIABLE XCRUN_SHOW_SDK_PATH_RESULT
	OUTPUT_VARIABLE CMAKE_OSX_SYSROOT
	OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT ${XCRUN_SHOW_SDK_PATH_RESULT} EQUAL 0)
	message(FATAL_ERROR "xcrun failed: ${XCRUN_SHOW_SDK_PATH_RESULT}. You may need to install Xcode.")
55
endif()
Ghislain MARY's avatar
Ghislain MARY committed
56

Ghislain MARY's avatar
Ghislain MARY committed
57 58 59 60 61 62 63 64 65
execute_process(COMMAND xcrun --sdk iphone${PLATFORM_LOWER} --find clang
	RESULT_VARIABLE XCRUN_FIND_CLANG_RESULT
	OUTPUT_VARIABLE IOS_CLANG_PATH
	OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT ${XCRUN_FIND_CLANG_RESULT} EQUAL 0)
	message(FATAL_ERROR "xcrun failed: ${XCRUN_FIND_CLANG_RESULT}. You may need to install Xcode.")
endif()
get_filename_component(IOS_TOOLCHAIN_PATH "${IOS_CLANG_PATH}" DIRECTORY)
Ghislain MARY's avatar
Ghislain MARY committed
66

Ghislain MARY's avatar
Ghislain MARY committed
67 68 69 70 71 72 73 74 75 76 77 78
message(STATUS "Using sysroot path: ${CMAKE_OSX_SYSROOT}")
message(STATUS "Using sdk version: ${IOS_SDK_VERSION}")
set(SDK_BIN_PATH "${CMAKE_OSX_SYSROOT}/../../usr/bin")

set(IOS_TOOLCHAIN_CC "${IOS_TOOLCHAIN_PATH}/clang")
set(IOS_TOOLCHAIN_CXX "${IOS_TOOLCHAIN_PATH}/clang++")
set(IOS_TOOLCHAIN_OBJC "${IOS_TOOLCHAIN_PATH}/clang")
set(IOS_TOOLCHAIN_LD "${IOS_TOOLCHAIN_PATH}/ld")
set(IOS_TOOLCHAIN_AR "${IOS_TOOLCHAIN_PATH}/ar")
set(IOS_TOOLCHAIN_RANLIB "${IOS_TOOLCHAIN_PATH}/ranlib")
set(IOS_TOOLCHAIN_STRIP "${IOS_TOOLCHAIN_PATH}/strip")
set(IOS_TOOLCHAIN_NM "${IOS_TOOLCHAIN_PATH}/nm")
Ghislain MARY's avatar
Ghislain MARY committed
79

80 81
execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERSION_RAW OUTPUT_STRIP_TRAILING_WHITESPACE)
STRING(REGEX REPLACE "Xcode ([^\n]*).*" "\\1" XCODE_VERSION "${XCODE_VERSION_RAW}")
Ghislain MARY's avatar
Ghislain MARY committed
82 83 84 85 86 87 88

include(CMakeForceCompiler)

set(CMAKE_CROSSCOMPILING TRUE)

# Define name of the target system
set(CMAKE_SYSTEM_NAME "Darwin")
89
set(IOS True)
Ghislain MARY's avatar
Ghislain MARY committed
90

91 92 93 94 95 96
# The following variables are needed to build correctly with Xcode
if(CMAKE_GENERATOR STREQUAL "Xcode")
	set(CMAKE_MACOSX_BUNDLE YES)
	set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
endif()

Ghislain MARY's avatar
Ghislain MARY committed
97
# Define the compiler
98 99
CMAKE_FORCE_C_COMPILER(${IOS_TOOLCHAIN_CC} Clang)
CMAKE_FORCE_CXX_COMPILER(${IOS_TOOLCHAIN_CXX} Clang)
Ghislain MARY's avatar
Ghislain MARY committed
100

101
set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT} ${CMAKE_INSTALL_PREFIX})
Ghislain MARY's avatar
Ghislain MARY committed
102 103 104 105 106
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
107
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
108 109 110

#important: the GUI identifier is required so that executables can be launched on iOS devices/simulators
set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.linphone.\${PRODUCT_NAME:identifier}")