Skip to content

Commit c214c81

Browse files
mobilebenras0219-msft
authored andcommitted
#436 Building iOS doesn’t seem to work (#776)
This moves iOS.cmake into the file so there is on need to add it. Also allows for boost to be static libs versus framework
1 parent 8edc9a4 commit c214c81

File tree

6 files changed

+244
-26
lines changed

6 files changed

+244
-26
lines changed

Build_iOS/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ cmake_minimum_required(VERSION 2.6)
33

44
enable_testing()
55

6-
set(TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ios-cmake/toolchain/iOS.cmake")
6+
if (CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET)
7+
set (ENV{CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET} ${CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET})
8+
endif()
9+
10+
set(TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/iOS.cmake")
711

812
set(SIM_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build.i386" CACHE INTERNAL "")
913
set(SIM_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../Release" CACHE INTERNAL "")

Build_iOS/fix_ios_cmake_compiler.patch

Lines changed: 0 additions & 18 deletions
This file was deleted.

Build_iOS/iOS.cmake

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
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 or SIMULATOR64
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+
# Standard settings
32+
set (CMAKE_SYSTEM_NAME Darwin)
33+
set (CMAKE_SYSTEM_VERSION 1)
34+
set (UNIX True)
35+
set (APPLE True)
36+
set (IOS True)
37+
38+
# Required as of cmake 2.8.10
39+
set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
40+
41+
# Allow external setting of CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET. This is clumsy
42+
# but it provides flexibility of not having to hardcode the deployment version in the file or have
43+
# numerous copies of the file
44+
if ($ENV{CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET})
45+
set(CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET $ENV{CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET})
46+
endif ($ENV{CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET})
47+
48+
# Determine the cmake host system version so we know where to find the iOS SDKs
49+
find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
50+
if (CMAKE_UNAME)
51+
exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
52+
string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
53+
endif (CMAKE_UNAME)
54+
55+
# Use clang. Use xcrun to determine the location
56+
EXEC_PROGRAM(xcrun ARGS -find clang OUTPUT_VARIABLE APPLE_CLANG)
57+
EXEC_PROGRAM(xcrun ARGS -find clang++ OUTPUT_VARIABLE APPLE_CLANGPP)
58+
set (CMAKE_C_COMPILER ${APPLE_CLANG})
59+
set (CMAKE_CXX_COMPILER ${APPLE_CLANGPP})
60+
61+
set (CMAKE_AR ar CACHE FILEPATH "" FORCE)
62+
63+
set (CMAKE_THREAD_LIBS_INIT "-lpthread")
64+
set (CMAKE_HAVE_THREADS_LIBRARY 1)
65+
set (CMAKE_USE_WIN32_THREADS_INIT 0)
66+
set (CMAKE_USE_PTHREADS_INIT 1)
67+
68+
# Skip the platform compiler checks for cross compiling
69+
set (CMAKE_CXX_COMPILER_WORKS TRUE)
70+
set (CMAKE_C_COMPILER_WORKS TRUE)
71+
72+
# All iOS/Darwin specific settings - some may be redundant
73+
set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
74+
set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
75+
set (CMAKE_SHARED_MODULE_PREFIX "lib")
76+
set (CMAKE_SHARED_MODULE_SUFFIX ".so")
77+
set (CMAKE_MODULE_EXISTS 1)
78+
set (CMAKE_DL_LIBS "")
79+
80+
set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
81+
set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
82+
set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
83+
set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
84+
85+
# Hidden visibilty is required for cxx on iOS
86+
set (CMAKE_C_FLAGS_INIT "")
87+
set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden")
88+
89+
set (CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "" CACHE STRING "Force unset of CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN" FORCE)
90+
91+
set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
92+
set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
93+
94+
set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
95+
set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
96+
set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
97+
set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
98+
set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
99+
set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
100+
set (CMAKE_MACOSX_BUNDLE ON)
101+
set (CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED OFF)
102+
103+
104+
# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
105+
# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
106+
# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
107+
# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
108+
if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
109+
find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
110+
endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
111+
112+
# Setup iOS platform unless specified manually with IOS_PLATFORM
113+
if (NOT DEFINED IOS_PLATFORM)
114+
set (IOS_PLATFORM "OS")
115+
endif (NOT DEFINED IOS_PLATFORM)
116+
set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
117+
118+
# Setup building for arm64 or not
119+
if (NOT DEFINED BUILD_ARM64)
120+
set (BUILD_ARM64 true)
121+
endif (NOT DEFINED BUILD_ARM64)
122+
set (BUILD_ARM64 ${BUILD_ARM64} CACHE STRING "Build arm64 arch or not")
123+
124+
# Check the platform selection and setup for developer root
125+
if (${IOS_PLATFORM} STREQUAL "OS")
126+
set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
127+
128+
# This causes the installers to properly locate the output libraries
129+
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
130+
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
131+
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
132+
133+
# This causes the installers to properly locate the output libraries
134+
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
135+
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64")
136+
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
137+
138+
# This causes the installers to properly locate the output libraries
139+
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
140+
else (${IOS_PLATFORM} STREQUAL "OS")
141+
message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
142+
endif (${IOS_PLATFORM} STREQUAL "OS")
143+
144+
# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
145+
# Note Xcode 4.3 changed the installation location, choose the most recent one available
146+
exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR)
147+
set (XCODE_POST_43_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
148+
set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
149+
if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
150+
if (EXISTS ${XCODE_POST_43_ROOT})
151+
set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
152+
elseif(EXISTS ${XCODE_PRE_43_ROOT})
153+
set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
154+
endif (EXISTS ${XCODE_POST_43_ROOT})
155+
endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
156+
set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
157+
158+
# Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT
159+
if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
160+
file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
161+
if (_CMAKE_IOS_SDKS)
162+
list (SORT _CMAKE_IOS_SDKS)
163+
list (REVERSE _CMAKE_IOS_SDKS)
164+
list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
165+
else (_CMAKE_IOS_SDKS)
166+
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.")
167+
endif (_CMAKE_IOS_SDKS)
168+
message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
169+
endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
170+
set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
171+
172+
# Set the sysroot default to the most recent SDK
173+
set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
174+
175+
# set the architecture for iOS
176+
if (${IOS_PLATFORM} STREQUAL "OS")
177+
set (IOS_ARCH armv7 armv7s arm64)
178+
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
179+
set (IOS_ARCH i386)
180+
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64")
181+
set (IOS_ARCH x86_64)
182+
endif (${IOS_PLATFORM} STREQUAL "OS")
183+
184+
set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")
185+
186+
# Set the find root to the iOS developer roots and to user defined paths
187+
set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root")
188+
189+
# default to searching for frameworks first
190+
set (CMAKE_FIND_FRAMEWORK FIRST)
191+
192+
# set up the default search directories for frameworks
193+
set (CMAKE_SYSTEM_FRAMEWORK_PATH
194+
${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
195+
${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
196+
${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
197+
)
198+
199+
# only search the iOS sdks, not the remainder of the host filesystem
200+
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
201+
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
202+
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
203+
204+
205+
# This little macro lets you set any XCode specific property
206+
macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
207+
set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
208+
endmacro (set_xcode_property)
209+
210+
211+
# This macro lets you find executable programs on the host system
212+
macro (find_host_package)
213+
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
214+
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
215+
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
216+
set (IOS FALSE)
217+
218+
find_package(${ARGN})
219+
220+
set (IOS TRUE)
221+
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
222+
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
223+
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
224+
endmacro (find_host_package)
225+

Release/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ set(ANDROID_STL_FLAGS)
115115
# Platform (not compiler) specific settings
116116
if(IOS)
117117
# The cxx_flags must be reset here, because the ios-cmake toolchain file unfortunately sets "-headerpad_max_install_names" which is not a valid clang flag.
118-
set(CMAKE_CXX_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden")
118+
set(CMAKE_CXX_FLAGS "-fvisibility=hidden")
119119
elseif(ANDROID)
120120
if(ARM)
121121
set(LIBCXX_STL "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/thumb/libgnustl_static.a")

Release/cmake/cpprest_find_boost.cmake

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ function(cpprest_find_boost)
44
endif()
55

66
if(IOS)
7-
set(IOS_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../Build_iOS")
8-
set(Boost_LIBRARIES "${IOS_SOURCE_DIR}/boost.framework/boost" CACHE INTERNAL "")
9-
set(Boost_INCLUDE_DIR "${IOS_SOURCE_DIR}/boost.framework/Headers" CACHE INTERNAL "")
7+
if (EXISTS "${PROJECT_SOURCE_DIR}/../Build_iOS/boost")
8+
set(IOS_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../Build_iOS")
9+
set(Boost_LIBRARIES "${IOS_SOURCE_DIR}/boost/lib" CACHE INTERNAL "")
10+
set(Boost_INCLUDE_DIR "${IOS_SOURCE_DIR}/boost/include" CACHE INTERNAL "")
11+
else()
12+
set(IOS_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../Build_iOS")
13+
set(Boost_LIBRARIES "${IOS_SOURCE_DIR}/boost.framework/boost" CACHE INTERNAL "")
14+
set(Boost_INCLUDE_DIR "${IOS_SOURCE_DIR}/boost.framework/Headers" CACHE INTERNAL "")
15+
endif()
1016
elseif(ANDROID)
1117
set(Boost_COMPILER "-clang")
1218
if(ARM)
@@ -42,8 +48,9 @@ function(cpprest_find_boost)
4248
endif()
4349
set(_prev "${_lib}")
4450
endforeach()
45-
target_link_libraries(cpprestsdk_boost_internal INTERFACE "$<BUILD_INTERFACE:${_libs}>")
46-
51+
if (NOT IOS OR NOT EXISTS "${PROJECT_SOURCE_DIR}/../Build_iOS/boost")
52+
target_link_libraries(cpprestsdk_boost_internal INTERFACE "$<BUILD_INTERFACE:${_libs}>")
53+
endif()
4754
else()
4855
if(ANDROID)
4956
target_link_libraries(cpprestsdk_boost_internal INTERFACE

Release/src/http/client/http_client_asio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#include <unordered_set>
4848
#include <memory>
4949

50-
#if defined(__GNUC__)
50+
#if defined(__GNUC__) && !defined(__clang__)
5151

5252
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
5353
#define AND_CAPTURE_MEMBER_FUNCTION_POINTERS

0 commit comments

Comments
 (0)