Merge pull request #1950

f5bd3465 IOS CMAKE build settings (Jaquee)
d8a88d05 add IOS CMAKE toolchain (Jaquee)
This commit is contained in:
Riccardo Spagni 2017-04-11 00:26:15 +02:00
commit e9ca165b1a
No known key found for this signature in database
GPG Key ID: 55432DF31CCD4FCD
7 changed files with 206 additions and 21 deletions

View File

@ -27,6 +27,9 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# #
# Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers # Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
if (IOS)
INCLUDE(CmakeLists_IOS.txt)
endif()
cmake_minimum_required(VERSION 2.8.7) cmake_minimum_required(VERSION 2.8.7)
@ -77,7 +80,7 @@ if (ARM_TEST STREQUAL "arm")
endif() endif()
endif() endif()
if (ARM_ID STREQUAL "aarch64") if (ARM_ID STREQUAL "aarch64" OR ARM_ID STREQUAL "arm64")
set(ARM 1) set(ARM 1)
set(ARM8 1) set(ARM8 1)
endif() endif()
@ -312,7 +315,7 @@ else()
endif() endif()
# Handle OpenSSL, used for sha256sum on binary updates # Handle OpenSSL, used for sha256sum on binary updates
if (APPLE) if (APPLE AND NOT IOS)
if (NOT OpenSSL_DIR) if (NOT OpenSSL_DIR)
EXECUTE_PROCESS(COMMAND brew --prefix openssl EXECUTE_PROCESS(COMMAND brew --prefix openssl
OUTPUT_VARIABLE OPENSSL_ROOT_DIR OUTPUT_VARIABLE OPENSSL_ROOT_DIR
@ -322,7 +325,7 @@ if (APPLE)
endif() endif()
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
if(STATIC) if(STATIC AND NOT IOS)
if(UNIX) if(UNIX)
set(OPENSSL_LIBRARIES "${OPENSSL_LIBRARIES};${CMAKE_DL_LIBS}") set(OPENSSL_LIBRARIES "${OPENSSL_LIBRARIES};${CMAKE_DL_LIBS}")
endif() endif()
@ -337,7 +340,7 @@ endif()
add_subdirectory(external) add_subdirectory(external)
# Final setup for miniupnpc # Final setup for miniupnpc
if(UPNP_STATIC) if(UPNP_STATIC OR IOS)
add_definitions("-DUPNP_STATIC") add_definitions("-DUPNP_STATIC")
else() else()
add_definitions("-DUPNP_DYNAMIC") add_definitions("-DUPNP_DYNAMIC")
@ -541,8 +544,9 @@ else()
endif(ARM) endif(ARM)
if(ANDROID AND NOT BUILD_GUI_DEPS STREQUAL "ON") if(ANDROID AND NOT BUILD_GUI_DEPS STREQUAL "ON" OR IOS)
#From Android 5: "only position independent executables (PIE) are supported" #From Android 5: "only position independent executables (PIE) are supported"
message(STATUS "Enabling PIE executable")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -pie") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -pie")
@ -651,7 +655,7 @@ list(APPEND EXTRA_LIBRARIES ${CMAKE_DL_LIBS})
if(ANDROID) if(ANDROID)
set(ATOMIC libatomic.a) set(ATOMIC libatomic.a)
endif() endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND ARCH_WIDTH EQUAL "32") if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND ARCH_WIDTH EQUAL "32" AND NOT IOS)
find_library(ATOMIC atomic) find_library(ATOMIC atomic)
list(APPEND EXTRA_LIBRARIES ${ATOMIC}) list(APPEND EXTRA_LIBRARIES ${ATOMIC})
endif() endif()

164
CMakeLists_IOS.txt Normal file
View File

@ -0,0 +1,164 @@
# Portions Copyright (c) 2017, The Monero Project
# This file is based off of the https://code.google.com/archive/p/ios-cmake/
# It has been altered for Monero iOS development
#
#
# Options:
#
# IOS_PLATFORM = OS (default) or SIMULATOR or SIMULATOR64
# This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders
# OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch.
# SIMULATOR - used to build for the Simulator platforms, which have an x86 arch.
#
# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder
# By default this location is automatcially chosen based on the IOS_PLATFORM value above.
# If set manually, it will override the default location and force the user of a particular Developer Platform
#
# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
# By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.
# In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path.
# If set manually, this will force the use of a specific SDK version
# Standard settings
set (CMAKE_SYSTEM_NAME Darwin)
set (CMAKE_SYSTEM_VERSION 1)
set (UNIX True)
set (APPLE True)
set (IOS True)
# Required as of cmake 2.8.10
set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
# Determine the cmake host system version so we know where to find the iOS SDKs
find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
if (CMAKE_UNAME)
exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
endif (CMAKE_UNAME)
# Force the compilers to gcc for iOS
include (CMakeForceCompiler)
# set (MAKE_C_COMPILER "/usr/bin/gcc Apple")
# set (CMAKE_CXX_COMPILER "/usr/bin/g++ Apple")
set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
# Skip the platform compiler checks for cross compiling
set (CMAKE_CXX_COMPILER_WORKS TRUE)
set (CMAKE_C_COMPILER_WORKS TRUE)
# All iOS/Darwin specific settings - some may be redundant
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}")
# Hidden visibilty is required for cxx on iOS
set (CMAKE_C_FLAGS_INIT "")
set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden")
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}")
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")
# Setup iOS platform unless specified manually with IOS_PLATFORM
if (NOT DEFINED IOS_PLATFORM)
set (IOS_PLATFORM "OS")
endif (NOT DEFINED IOS_PLATFORM)
set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
# Setup building for arm64 or not
if (NOT DEFINED BUILD_ARM64)
set (BUILD_ARM64 true)
endif (NOT DEFINED BUILD_ARM64)
set (BUILD_ARM64 ${BUILD_ARM64} CACHE STRING "Build arm64 arch or not")
# Check the platform selection and setup for developer root
if (${IOS_PLATFORM} STREQUAL "OS")
set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
# This causes the installers to properly locate the output libraries
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
set (SIMULATOR true)
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
# This causes the installers to properly locate the output libraries
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64")
set (SIMULATOR true)
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
# This causes the installers to properly locate the output libraries
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
else (${IOS_PLATFORM} STREQUAL "OS")
message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
endif (${IOS_PLATFORM} STREQUAL "OS")
# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
# Note Xcode 4.3 changed the installation location, choose the most recent one available
exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR)
set (XCODE_POST_43_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
if (EXISTS ${XCODE_POST_43_ROOT})
set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
elseif(EXISTS ${XCODE_PRE_43_ROOT})
set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
endif (EXISTS ${XCODE_POST_43_ROOT})
endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
# Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT
if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
if (_CMAKE_IOS_SDKS)
list (SORT _CMAKE_IOS_SDKS)
list (REVERSE _CMAKE_IOS_SDKS)
list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
else (_CMAKE_IOS_SDKS)
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.")
endif (_CMAKE_IOS_SDKS)
message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
# Set the sysroot default to the most recent SDK
set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
# set the architecture for iOS
if (NOT DEFINED ARCH)
set (ARCH armv7)
endif()
set (IOS_ARCH ${ARCH})
set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")
message(STATUS "ios arch: ${IOS_ARCH}")
# Set the find root to the iOS developer roots and to user defined paths
set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root")
# default to searching for frameworks first
set (CMAKE_FIND_FRAMEWORK FIRST)
# set up the default search directories for frameworks
set (CMAKE_SYSTEM_FRAMEWORK_PATH
${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
)
message(STATUS "IOS CMAKE conf finished")

View File

@ -34,11 +34,12 @@
# We always compile if we are building statically to reduce static dependency issues... # We always compile if we are building statically to reduce static dependency issues...
# ...except for FreeBSD, because FreeBSD is a special case that doesn't play well with # ...except for FreeBSD, because FreeBSD is a special case that doesn't play well with
# others. # others.
if(NOT IOS)
find_package(Miniupnpc QUIET) find_package(Miniupnpc QUIET)
endif()
# If we have the correct shared version and we're not building static, use it # If we have the correct shared version and we're not building static, use it
if(STATIC) if(STATIC OR IOS)
set(USE_SHARED_MINIUPNPC false) set(USE_SHARED_MINIUPNPC false)
elseif(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER) elseif(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER)
set(USE_SHARED_MINIUPNPC true) set(USE_SHARED_MINIUPNPC true)

View File

@ -215,6 +215,11 @@ endif ()
if (INSTALL_VENDORED_LIBUNBOUND) if (INSTALL_VENDORED_LIBUNBOUND)
if(IOS)
set(lib_folder lib-${ARCH})
else()
set(lib_folder lib)
endif()
install(TARGETS unbound install(TARGETS unbound
ARCHIVE DESTINATION lib) ARCHIVE DESTINATION ${lib_folder})
endif() endif()

View File

@ -101,18 +101,24 @@ add_subdirectory(crypto)
add_subdirectory(ringct) add_subdirectory(ringct)
add_subdirectory(cryptonote_basic) add_subdirectory(cryptonote_basic)
add_subdirectory(cryptonote_core) add_subdirectory(cryptonote_core)
add_subdirectory(blockchain_db) if(NOT IOS)
add_subdirectory(blockchain_db)
endif()
add_subdirectory(mnemonics) add_subdirectory(mnemonics)
add_subdirectory(rpc) if(NOT IOS)
add_subdirectory(rpc)
endif()
add_subdirectory(wallet) add_subdirectory(wallet)
add_subdirectory(p2p) if(NOT IOS)
add_subdirectory(p2p)
endif()
add_subdirectory(cryptonote_protocol) add_subdirectory(cryptonote_protocol)
if(NOT IOS)
add_subdirectory(simplewallet) add_subdirectory(simplewallet)
add_subdirectory(daemonizer) add_subdirectory(daemonizer)
add_subdirectory(daemon) add_subdirectory(daemon)
add_subdirectory(blockchain_utilities)
add_subdirectory(blockchain_utilities) endif()
if(PER_BLOCK_CHECKPOINT) if(PER_BLOCK_CHECKPOINT)
add_subdirectory(blocks) add_subdirectory(blocks)

View File

@ -93,7 +93,7 @@ endif()
# Because of the way Qt works on android with JNI, the code does not live in the main android thread # Because of the way Qt works on android with JNI, the code does not live in the main android thread
# So this code runs with a 1 MB default stack size. # So this code runs with a 1 MB default stack size.
# This will force the use of the heap for the allocation of the scratchpad # This will force the use of the heap for the allocation of the scratchpad
if (ANDROID) if (ANDROID OR IOS)
if( BUILD_GUI_DEPS ) if( BUILD_GUI_DEPS )
add_definitions(-DFORCE_USE_HEAP=1) add_definitions(-DFORCE_USE_HEAP=1)
endif() endif()

View File

@ -132,8 +132,13 @@ if (BUILD_GUI_DEPS)
list(APPEND objlibs $<TARGET_OBJECTS:obj_${lib}>) # matches naming convention in src/CMakeLists.txt list(APPEND objlibs $<TARGET_OBJECTS:obj_${lib}>) # matches naming convention in src/CMakeLists.txt
endforeach() endforeach()
add_library(wallet_merged STATIC ${objlibs}) add_library(wallet_merged STATIC ${objlibs})
if(IOS)
set(lib_folder lib-${ARCH})
else()
set(lib_folder lib)
endif()
install(TARGETS wallet_merged install(TARGETS wallet_merged
ARCHIVE DESTINATION lib) ARCHIVE DESTINATION ${lib_folder})
install(FILES ${wallet_api_headers} install(FILES ${wallet_api_headers}
DESTINATION include/wallet) DESTINATION include/wallet)