From 18c3d8bd2ed431194cf3facb95a8e6ecc09abc46 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 13 Jun 2022 12:58:17 -0400 Subject: [PATCH 01/33] initial ios junk --- .gitmodules | 3 +++ contrib/ios.sh | 32 ++++++++++++++++++++++++++++++++ external/ios-cmake | 1 + 3 files changed, 36 insertions(+) create mode 100755 contrib/ios.sh create mode 160000 external/ios-cmake diff --git a/.gitmodules b/.gitmodules index 60d5d96217..e557d532a7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -36,3 +36,6 @@ [submodule "external/oxen-encoding"] path = external/oxen-encoding url = https://github.com/oxen-io/oxen-encoding.git +[submodule "external/ios-cmake"] + path = external/ios-cmake + url = https://github.com/leetal/ios-cmake diff --git a/contrib/ios.sh b/contrib/ios.sh new file mode 100755 index 0000000000..8c0c7fd6f5 --- /dev/null +++ b/contrib/ios.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# Build the shit for iphone, only builds embeded lokinet + +set -e +set +x +if ! [ -f LICENSE ] || ! [ -d llarp ]; then + echo "You need to run this as ./contrib/ios.sh from the top-level lokinet project directory" +fi + +mkdir -p build/iphone +cd build/iphone +cmake \ + -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE=../../external/iso-cmake/ios.toolchain.cmake \ + -DBUILD_STATIC_DEPS=ON \ + -DBUILD_PACKAGE=OFF \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_TESTING=OFF \ + -DBUILD_LIBLOKINET=ON \ + -DWITH_TESTS=OFF \ + -DNATIVE_BUILD=OFF \ + -DSTATIC_LINK=ON \ + -DWITH_SYSTEMD=OFF \ + -DFORCE_OXENMQ_SUBMODULE=ON \ + -DFORCE_OXENC_SUBMODULE=ON \ + -DSUBMODULE_CHECK=ON \ + -DWITH_LTO=ON \ + -DCMAKE_BUILD_TYPE=Release \ + "$@" \ + ../.. +ninja lokinet-shared diff --git a/external/ios-cmake b/external/ios-cmake new file mode 160000 index 0000000000..ab8607a7f5 --- /dev/null +++ b/external/ios-cmake @@ -0,0 +1 @@ +Subproject commit ab8607a7f57970d99d590d420ecd8e2d7f9a9c77 From cbdd54e453fd12f7f18130a143d49def7de51cb3 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 13 Jun 2022 13:15:32 -0400 Subject: [PATCH 02/33] i hate apple --- CMakeLists.txt | 6 +++++- contrib/ios.sh | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 83f6d3e410..6af72d6932 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,11 @@ if(APPLE AND BUILD_DAEMON) set(LANGS ${LANGS} OBJC Swift) endif() -find_program(CCACHE_PROGRAM ccache) + +if(NOT CMAKE_GENERATOR MATCHES "Xcode") + find_program(CCACHE_PROGRAM ccache) +endif() + if(CCACHE_PROGRAM) foreach(lang ${LANGS}) if(NOT DEFINED CMAKE_${lang}_COMPILER_LAUNCHER AND NOT CMAKE_${lang}_COMPILER MATCHES ".*/ccache") diff --git a/contrib/ios.sh b/contrib/ios.sh index 8c0c7fd6f5..a40f376a7b 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -3,7 +3,7 @@ # Build the shit for iphone, only builds embeded lokinet set -e -set +x +set -x if ! [ -f LICENSE ] || ! [ -d llarp ]; then echo "You need to run this as ./contrib/ios.sh from the top-level lokinet project directory" fi @@ -11,8 +11,8 @@ fi mkdir -p build/iphone cd build/iphone cmake \ - -G Ninja \ - -DCMAKE_TOOLCHAIN_FILE=../../external/iso-cmake/ios.toolchain.cmake \ + -G Xcode \ + -DCMAKE_TOOLCHAIN_FILE=../../external/ios-cmake/ios.toolchain.cmake \ -DBUILD_STATIC_DEPS=ON \ -DBUILD_PACKAGE=OFF \ -DBUILD_SHARED_LIBS=OFF \ @@ -26,7 +26,8 @@ cmake \ -DFORCE_OXENC_SUBMODULE=ON \ -DSUBMODULE_CHECK=ON \ -DWITH_LTO=ON \ + -DPLATFORM=OS64COMBINED \ -DCMAKE_BUILD_TYPE=Release \ "$@" \ ../.. -ninja lokinet-shared +xcrun build lokinet-shared From 5cc6089df1616fcc72c99cc639e83ca528b027b9 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 13 Jun 2022 13:17:33 -0400 Subject: [PATCH 03/33] squash --- contrib/ios.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/ios.sh b/contrib/ios.sh index a40f376a7b..e7f8d0e134 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -11,7 +11,7 @@ fi mkdir -p build/iphone cd build/iphone cmake \ - -G Xcode \ + -G Ninja \ -DCMAKE_TOOLCHAIN_FILE=../../external/ios-cmake/ios.toolchain.cmake \ -DBUILD_STATIC_DEPS=ON \ -DBUILD_PACKAGE=OFF \ @@ -25,9 +25,9 @@ cmake \ -DFORCE_OXENMQ_SUBMODULE=ON \ -DFORCE_OXENC_SUBMODULE=ON \ -DSUBMODULE_CHECK=ON \ - -DWITH_LTO=ON \ + -DWITH_LTO=OFF \ -DPLATFORM=OS64COMBINED \ -DCMAKE_BUILD_TYPE=Release \ "$@" \ ../.. -xcrun build lokinet-shared +ninja lokinet-shared From 4b54f7245f02325e70b45a304ce24d6e2451f626 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 13 Jun 2022 13:18:09 -0400 Subject: [PATCH 04/33] Revert "squash" This reverts commit 2ee2ceb6636832b423066060443ed93ffe648274. --- contrib/ios.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/ios.sh b/contrib/ios.sh index e7f8d0e134..a40f376a7b 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -11,7 +11,7 @@ fi mkdir -p build/iphone cd build/iphone cmake \ - -G Ninja \ + -G Xcode \ -DCMAKE_TOOLCHAIN_FILE=../../external/ios-cmake/ios.toolchain.cmake \ -DBUILD_STATIC_DEPS=ON \ -DBUILD_PACKAGE=OFF \ @@ -25,9 +25,9 @@ cmake \ -DFORCE_OXENMQ_SUBMODULE=ON \ -DFORCE_OXENC_SUBMODULE=ON \ -DSUBMODULE_CHECK=ON \ - -DWITH_LTO=OFF \ + -DWITH_LTO=ON \ -DPLATFORM=OS64COMBINED \ -DCMAKE_BUILD_TYPE=Release \ "$@" \ ../.. -ninja lokinet-shared +xcrun build lokinet-shared From 76eeddc2606cb3efa2da5b87761563d9aeeacd82 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 13 Jun 2022 16:59:33 -0400 Subject: [PATCH 05/33] squash --- llarp/CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index 8be49a2369..d4079ed9b6 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -263,6 +263,13 @@ if(BUILD_LIBLOKINET) install(TARGETS lokinet-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT liblokinet) endif() add_log_tag(lokinet-shared) + if(CMAKE_GENERATOR MATCHES "Xcode") + option(CODE_SIGN_IDENT "for codesign magic on ios" "iPhone Developer") + option(DEV_TEAM_ID "for codesign magic on ios" "SUQ8J2PCT7") + set_property (TARGET lokinet-shared PROPERTY XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CODE_SIGN_IDENT}) + set_property (TARGET lokinet-shared PROPERTY XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${DEV_TEAM_ID}) + endif() + endif() if(APPLE) From e56eef14fc376957a454c705df2e87c0b015fc70 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 14 Jun 2022 09:47:37 -0400 Subject: [PATCH 06/33] squash --- contrib/ios.sh | 10 +++++----- llarp/CMakeLists.txt | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/contrib/ios.sh b/contrib/ios.sh index a40f376a7b..9aabdbefe0 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -9,7 +9,6 @@ if ! [ -f LICENSE ] || ! [ -d llarp ]; then fi mkdir -p build/iphone -cd build/iphone cmake \ -G Xcode \ -DCMAKE_TOOLCHAIN_FILE=../../external/ios-cmake/ios.toolchain.cmake \ @@ -27,7 +26,8 @@ cmake \ -DSUBMODULE_CHECK=ON \ -DWITH_LTO=ON \ -DPLATFORM=OS64COMBINED \ - -DCMAKE_BUILD_TYPE=Release \ - "$@" \ - ../.. -xcrun build lokinet-shared + -DCMAKE_BUILD_TYPE=Debug \ + -S . -B build/iphone \ + "$@" + +cmake --build build/iphone diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index d4079ed9b6..d7a7034156 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -130,7 +130,7 @@ add_library(liblokinet dht/taglookup.cpp endpoint_base.cpp - + exit/context.cpp exit/endpoint.cpp exit/exit_messages.cpp @@ -223,7 +223,7 @@ add_library(liblokinet set_target_properties(liblokinet PROPERTIES OUTPUT_NAME lokinet) enable_lto(lokinet-util lokinet-platform liblokinet) - + if(TRACY_ROOT) target_sources(liblokinet PRIVATE ${TRACY_ROOT}/TracyClient.cpp) endif() @@ -269,7 +269,7 @@ if(BUILD_LIBLOKINET) set_property (TARGET lokinet-shared PROPERTY XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CODE_SIGN_IDENT}) set_property (TARGET lokinet-shared PROPERTY XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${DEV_TEAM_ID}) endif() - + endif() if(APPLE) From 0cad6e98e0efdc59ab341ebf0e51727b6d1b6709 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 14 Jun 2022 10:10:25 -0400 Subject: [PATCH 07/33] it actually start to build omg --- CMakeLists.txt | 15 +++++++++++++++ contrib/ios.sh | 8 ++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6af72d6932..a44c6d3dc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -302,6 +302,21 @@ if(ANDROID) add_subdirectory(jni) endif() + + +if(CMAKE_GENERATOR MATCHES "Xcode") + if(NOT CODE_SIGN_IDENT) + set(CODE_SIGN_IDENT "iPhone Developer") + endif() + if(NOT DEV_TEAM_ID) + set(DEV_TEAM_ID "SUQ8J2PCT7") + endif() + message(STATUS "code sign with: ${CODE_SIGN_IDENT} using dev id: ${DEV_TEAM_ID}") + set_property (TARGET lokinet-shared PROPERTY XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CODE_SIGN_IDENT}) + set_property (TARGET lokinet-shared PROPERTY XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${DEV_TEAM_ID}) +endif() + + add_subdirectory(docs) # uninstall target diff --git a/contrib/ios.sh b/contrib/ios.sh index 9aabdbefe0..1bf762edf2 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -11,7 +11,8 @@ fi mkdir -p build/iphone cmake \ -G Xcode \ - -DCMAKE_TOOLCHAIN_FILE=../../external/ios-cmake/ios.toolchain.cmake \ + -DCMAKE_OSX_SYSROOT=$( xcrun --sdk iphoneos --show-sdk-path ) \ + -DCMAKE_TOOLCHAIN_FILE=external/ios-cmake/ios.toolchain.cmake \ -DBUILD_STATIC_DEPS=ON \ -DBUILD_PACKAGE=OFF \ -DBUILD_SHARED_LIBS=OFF \ @@ -21,8 +22,11 @@ cmake \ -DNATIVE_BUILD=OFF \ -DSTATIC_LINK=ON \ -DWITH_SYSTEMD=OFF \ + -DWITH_BOOTSTRAP=OFF \ + -DBUILD_DAEMON=OFF \ -DFORCE_OXENMQ_SUBMODULE=ON \ -DFORCE_OXENC_SUBMODULE=ON \ + -DFORCE_NLOHMANN_SUBMODULE=ON \ -DSUBMODULE_CHECK=ON \ -DWITH_LTO=ON \ -DPLATFORM=OS64COMBINED \ @@ -30,4 +34,4 @@ cmake \ -S . -B build/iphone \ "$@" -cmake --build build/iphone +cmake --build build/iphone --target lokinet-shared From 1da239f9dd25558d5fb06ec10df7d175c91b596a Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 14 Jun 2022 13:08:44 -0400 Subject: [PATCH 08/33] squash --- CMakeLists.txt | 14 +++++++++++-- cmake/StaticBuild.cmake | 44 ++++++++++++++++++++++++++++++++++++++--- contrib/ios.sh | 15 ++++++++------ 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a44c6d3dc8..e5f7fb0f0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,9 @@ if(APPLE AND BUILD_DAEMON) endif() -if(NOT CMAKE_GENERATOR MATCHES "Xcode") +option(WITH_CCACHE "enable ccache" ON) + +if(WITH_CCACHE) find_program(CCACHE_PROGRAM ccache) endif() @@ -201,7 +203,15 @@ if (WOW64_CROSS_COMPILE OR WIN64_CROSS_COMPILE) include(cmake/cross_compile.cmake) endif() -if(NOT APPLE) +if(APPLE) + if(IOS AND ARCH STREQUAL "arm64") + message(STATUS "IOS: Changing arch from arm64 to armv8") + add_compile_options(-march=armv8) + elseif(IOS AND ARCH STREQUAL "x86_64") + message(STATUS "IOS: Changing arch from x86_64 to x86-64") + add_compile_options(-march=x86-64) + endif() +else() if(NATIVE_BUILD) if(CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le) add_compile_options(-mcpu=native -mtune=native) diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake index 3ddbe97579..048de7a043 100644 --- a/cmake/StaticBuild.cmake +++ b/cmake/StaticBuild.cmake @@ -108,12 +108,17 @@ endfunction() set(cross_host "") set(cross_rc "") + if(CMAKE_CROSSCOMPILING) + if(APPLE_TARGET_TRIPLE) + set(ARCH_TRIPLET "${APPLE_TARGET_TRIPLE}") + endif() set(cross_host "--host=${ARCH_TRIPLET}") if (ARCH_TRIPLET MATCHES mingw AND CMAKE_RC_COMPILER) set(cross_rc "WINDRES=${CMAKE_RC_COMPILER}") endif() endif() + if(ANDROID) set(android_toolchain_suffix linux-android) set(android_compiler_suffix linux-android23) @@ -162,7 +167,7 @@ if(WITH_LTO) set(deps_CFLAGS "${deps_CFLAGS} -flto") endif() -if(APPLE) +if(APPLE AND NOT IOS) set(deps_CFLAGS "${deps_CFLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}") set(deps_CXXFLAGS "${deps_CXXFLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}") endif() @@ -175,6 +180,18 @@ else() endif() +if(APPLE) + foreach(lang C CXX) + string(APPEND deps_${lang}FLAGS " ${CMAKE_${lang}_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT} ${CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG}${CMAKE_OSX_DEPLOYMENT_TARGET}") + set(deps_noarch_${lang}FLAGS "${deps_${lang}FLAGS}") + foreach(arch ${CMAKE_OSX_ARCHITECTURES}) + string(APPEND deps_${lang}FLAGS " -arch ${arch}") + endforeach() + endforeach() +endif() + + + # Builds a target; takes the target name (e.g. "readline") and builds it in an external project with # target name suffixed with `_external`. Its upper-case value is used to get the download details # (from the variables set above). The following options are supported and passed through to @@ -243,6 +260,15 @@ if(CMAKE_CROSSCOMPILING) elseif(ANDROID) set(openssl_system_env SYSTEM=Linux MACHINE=${android_machine} LD=${deps_ld} RANLIB=${deps_ranlib} AR=${deps_ar}) set(openssl_extra_opts no-asm) + elseif(IOS) + get_filename_component(apple_toolchain "${CMAKE_C_COMPILER}" DIRECTORY) + get_filename_component(apple_sdk "${CMAKE_OSX_SYSROOT}" NAME) + if(NOT ${apple_toolchain} MATCHES Xcode OR NOT ${apple_sdk} MATCHES "iPhone(OS|Simulator)") + message(FATAL_ERROR "didn't find your toolchain and sdk correctly from ${CMAKE_C_COMPILER}/${CMAKE_OSX_SYSROOT}: found toolchain=${apple_toolchain}, sdk=${apple_sdk}") + endif() + set(openssl_system_env CROSS_COMPILE=${apple_toolchain}/ CROSS_TOP=${CMAKE_DEVELOPER_ROOT} CROSS_SDK=${apple_sdk}) + set(openssl_configure ./Configure iphoneos-cross) + set(openssl_cc "clang") elseif(ARCH_TRIPLET STREQUAL mips64-linux-gnuabi64) set(openssl_system_env SYSTEM=Linux MACHINE=mips64) set(openssl_configure_command ./Configure linux64-mips64) @@ -294,13 +320,19 @@ build_external(expat ) add_static_target(expat expat_external libexpat.a) + +set(unbound_extra) +if(APPLE AND IOS) + set(unbound_extra CPP=cpp) +endif() + build_external(unbound DEPENDS openssl_external expat_external CONFIGURE_COMMAND ./configure ${cross_host} ${cross_rc} --prefix=${DEPS_DESTDIR} --disable-shared --enable-static --with-libunbound-only --with-pic --$,enable,disable>-flto --with-ssl=${DEPS_DESTDIR} --with-libexpat=${DEPS_DESTDIR} - "CC=${deps_cc}" "CFLAGS=${deps_CFLAGS}" + "CC=${deps_cc}" "CFLAGS=${deps_CFLAGS}" ${unbound_extra} ) add_static_target(libunbound unbound_external libunbound.a) if(NOT WIN32) @@ -331,10 +363,16 @@ if(CMAKE_CROSSCOMPILING AND ARCH_TRIPLET MATCHES mingw) PATCH_COMMAND ${PROJECT_SOURCE_DIR}/contrib/apply-patches.sh ${PROJECT_SOURCE_DIR}/contrib/patches/libzmq-mingw-wepoll.patch ${PROJECT_SOURCE_DIR}/contrib/patches/libzmq-mingw-closesocket.patch) endif() +set(zmq_cross_host "${cross_host}") +if(IOS AND cross_host MATCHES "-ios$") + # zmq doesn't like "-ios" for the host, so replace it with -darwin + string(REGEX REPLACE "-ios$" "-darwin" zmq_cross_host ${cross_host}) +endif() + build_external(zmq DEPENDS sodium_external ${zmq_patch} - CONFIGURE_COMMAND ./configure ${cross_host} --prefix=${DEPS_DESTDIR} --enable-static --disable-shared + CONFIGURE_COMMAND ./configure ${zmq_cross_host} --prefix=${DEPS_DESTDIR} --enable-static --disable-shared --disable-curve-keygen --enable-curve --disable-drafts --disable-libunwind --with-libsodium --without-pgm --without-norm --without-vmci --without-docs --with-pic --disable-Werror --disable-libbsd ${zmq_extra} "CC=${deps_cc}" "CXX=${deps_cxx}" "CFLAGS=${deps_CFLAGS} -fstack-protector" "CXXFLAGS=${deps_CXXFLAGS} -fstack-protector" diff --git a/contrib/ios.sh b/contrib/ios.sh index 1bf762edf2..9241da6cff 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -8,11 +8,16 @@ if ! [ -f LICENSE ] || ! [ -d llarp ]; then echo "You need to run this as ./contrib/ios.sh from the top-level lokinet project directory" fi +_sdk=${SDK:-iphoneos} + mkdir -p build/iphone cmake \ - -G Xcode \ - -DCMAKE_OSX_SYSROOT=$( xcrun --sdk iphoneos --show-sdk-path ) \ - -DCMAKE_TOOLCHAIN_FILE=external/ios-cmake/ios.toolchain.cmake \ + -G Ninja \ + -DWITH_CCACHE=OFF \ + -DCMAKE_C_COMPILER=$(xcrun --find --sdk ${_sdk} clang ) \ + -DCMAKE_CXX_COMPILER=$(xcrun --find --sdk ${_sdk} clang++ ) \ + -DCMAKE_OSX_SYSROOT=$( xcrun --sdk ${_sdk} --show-sdk-path ) \ + -DCMAKE_TOOLCHAIN_FILE=contrib/cross/ios.toolchain.cmake \ -DBUILD_STATIC_DEPS=ON \ -DBUILD_PACKAGE=OFF \ -DBUILD_SHARED_LIBS=OFF \ @@ -28,9 +33,7 @@ cmake \ -DFORCE_OXENC_SUBMODULE=ON \ -DFORCE_NLOHMANN_SUBMODULE=ON \ -DSUBMODULE_CHECK=ON \ - -DWITH_LTO=ON \ - -DPLATFORM=OS64COMBINED \ - -DCMAKE_BUILD_TYPE=Debug \ + -DWITH_LTO=OFF \ -S . -B build/iphone \ "$@" From 2b9e2e73ce36258ae69be07b3156b5311d4f1d08 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 14 Jun 2022 13:08:57 -0400 Subject: [PATCH 09/33] remove submodule --- .gitmodules | 3 --- external/ios-cmake | 1 - 2 files changed, 4 deletions(-) delete mode 160000 external/ios-cmake diff --git a/.gitmodules b/.gitmodules index e557d532a7..60d5d96217 100644 --- a/.gitmodules +++ b/.gitmodules @@ -36,6 +36,3 @@ [submodule "external/oxen-encoding"] path = external/oxen-encoding url = https://github.com/oxen-io/oxen-encoding.git -[submodule "external/ios-cmake"] - path = external/ios-cmake - url = https://github.com/leetal/ios-cmake diff --git a/external/ios-cmake b/external/ios-cmake deleted file mode 160000 index ab8607a7f5..0000000000 --- a/external/ios-cmake +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ab8607a7f57970d99d590d420ecd8e2d7f9a9c77 From 17e5ed8cbb6ea78c6273ad3c688158d3e5f4ae94 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 14 Jun 2022 13:10:34 -0400 Subject: [PATCH 10/33] squash --- contrib/cross/ios.toolchain.cmake | 728 ++++++++++++++++++++++++++++++ contrib/ios/readme.txt | 12 + 2 files changed, 740 insertions(+) create mode 100644 contrib/cross/ios.toolchain.cmake create mode 100644 contrib/ios/readme.txt diff --git a/contrib/cross/ios.toolchain.cmake b/contrib/cross/ios.toolchain.cmake new file mode 100644 index 0000000000..644832062c --- /dev/null +++ b/contrib/cross/ios.toolchain.cmake @@ -0,0 +1,728 @@ +# This file downloaded from https://github.com/leetal/ios-cmake; it +# contained this header regarding the source works' licences: +# +# This file is part of the ios-cmake project. It was retrieved from +# https://github.com/cristeab/ios-cmake.git, which is a fork of +# https://code.google.com/p/ios-cmake/. Which in turn is based off of +# the Platform/Darwin.cmake and Platform/UnixPaths.cmake files which +# are included with CMake 2.8.4 +# +# The ios-cmake project is licensed under the new BSD license. +# +# Copyright (c) 2014, Bogdan Cristea and LTE Engineering Software, +# Kitware, Inc., Insight Software Consortium. All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# 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. +# +# Updated by Alex Stewart (alexs.mac@gmail.com) +# +# ***************************************************************************** +# Now maintained by Alexander Widerberg (widerbergaren [at] gmail.com) +# under the BSD-3-Clause license +# https://github.com/leetal/ios-cmake +# ***************************************************************************** +# +# INFORMATION / HELP +# +# The following arguments control the behaviour of this toolchain: +# +# PLATFORM: (default "OS") +# OS = Build for iPhoneOS. +# OS64 = Build for arm64 iphoneOS. +# OS64COMBINED = Build for arm64 x86_64 iphoneOS. Combined into FAT STATIC lib (supported on 3.14+ of CMakewith "-G Xcode" argument ONLY) +# SIMULATOR = Build for x86 i386 iphoneOS Simulator. +# SIMULATOR64 = Build for x86_64 iphoneOS Simulator. +# TVOS = Build for arm64 tvOS. +# TVOSCOMBINED = Build for arm64 x86_64 tvOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY) +# SIMULATOR_TVOS = Build for x86_64 tvOS Simulator. +# WATCHOS = Build for armv7k arm64_32 for watchOS. +# WATCHOSCOMBINED = Build for armv7k arm64_32 x86_64 watchOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY) +# SIMULATOR_WATCHOS = Build for x86_64 for watchOS Simulator. +# +# CMAKE_OSX_SYSROOT: Path to the SDK to use. By default this is +# automatically determined from PLATFORM and xcodebuild, but +# can also be manually specified (although this should not be required). +# +# CMAKE_DEVELOPER_ROOT: Path to the Developer directory for the platform +# being compiled for. By default this is automatically determined from +# CMAKE_OSX_SYSROOT, but can also be manually specified (although this should +# not be required). +# +# DEPLOYMENT_TARGET: Minimum SDK version to target. Default 2.0 on watchOS and 9.0 on tvOS+iOS +# +# ENABLE_BITCODE: (1|0) Enables or disables bitcode support. Default 1 (true) +# +# ENABLE_ARC: (1|0) Enables or disables ARC support. Default 1 (true, ARC enabled by default) +# +# ENABLE_VISIBILITY: (1|0) Enables or disables symbol visibility support. Default 0 (false, visibility hidden by default) +# +# ENABLE_STRICT_TRY_COMPILE: (1|0) Enables or disables strict try_compile() on all Check* directives (will run linker +# to actually check if linking is possible). Default 0 (false, will set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY) +# +# ARCHS: (armv7 armv7s armv7k arm64 arm64_32 i386 x86_64) If specified, will override the default architectures for the given PLATFORM +# OS = armv7 armv7s arm64 (if applicable) +# OS64 = arm64 (if applicable) +# SIMULATOR = i386 +# SIMULATOR64 = x86_64 +# TVOS = arm64 +# SIMULATOR_TVOS = x86_64 (i386 has since long been deprecated) +# WATCHOS = armv7k arm64_32 (if applicable) +# SIMULATOR_WATCHOS = x86_64 (i386 has since long been deprecated) +# +# This toolchain defines the following variables for use externally: +# +# XCODE_VERSION: Version number (not including Build version) of Xcode detected. +# SDK_VERSION: Version of SDK being used. +# CMAKE_OSX_ARCHITECTURES: Architectures being compiled for (generated from PLATFORM). +# APPLE_TARGET_TRIPLE: Used by autoconf build systems. NOTE: If "ARCHS" are overridden, this will *NOT* be set! +# +# This toolchain defines the following macros for use externally: +# +# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE XCODE_VARIANT) +# A convenience macro for setting xcode specific properties on targets. +# Available variants are: All, Release, RelWithDebInfo, Debug, MinSizeRel +# example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1" "all"). +# +# find_host_package (PROGRAM ARGS) +# A macro used to find executable programs on the host system, not within the +# environment. Thanks to the android-cmake project for providing the +# command. +# +# ******************************** DEPRECATIONS ******************************* +# +# IOS_DEPLOYMENT_TARGET: (Deprecated) Alias to DEPLOYMENT_TARGET +# CMAKE_IOS_DEVELOPER_ROOT: (Deprecated) Alias to CMAKE_DEVELOPER_ROOT +# IOS_PLATFORM: (Deprecated) Alias to PLATFORM +# IOS_ARCH: (Deprecated) Alias to ARCHS +# +# ***************************************************************************** +# + +# Fix for PThread library not in path +set(CMAKE_THREAD_LIBS_INIT "-lpthread") +set(CMAKE_HAVE_THREADS_LIBRARY 1) +set(CMAKE_USE_WIN32_THREADS_INIT 0) +set(CMAKE_USE_PTHREADS_INIT 1) + +# Cache what generator is used +set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE) + +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14") + set(MODERN_CMAKE YES) +endif() + +# Get the Xcode version being used. +execute_process(COMMAND xcodebuild -version + OUTPUT_VARIABLE XCODE_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}") +string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}") + +######## ALIASES (DEPRECATION WARNINGS) + +if(DEFINED IOS_PLATFORM) + set(PLATFORM ${IOS_PLATFORM}) + message(DEPRECATION "IOS_PLATFORM argument is DEPRECATED. Consider using the new PLATFORM argument instead.") +endif() + +if(DEFINED IOS_DEPLOYMENT_TARGET) + set(DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET}) + message(DEPRECATION "IOS_DEPLOYMENT_TARGET argument is DEPRECATED. Consider using the new DEPLOYMENT_TARGET argument instead.") +endif() + +if(DEFINED CMAKE_IOS_DEVELOPER_ROOT) + set(CMAKE_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT}) + message(DEPRECATION "CMAKE_IOS_DEVELOPER_ROOT argument is DEPRECATED. Consider using the new CMAKE_DEVELOPER_ROOT argument instead.") +endif() + +if(DEFINED IOS_ARCH) + set(ARCHS ${IOS_ARCH}) + message(DEPRECATION "IOS_ARCH argument is DEPRECATED. Consider using the new ARCHS argument instead.") +endif() + +######## END ALIASES + +# Unset the FORCE on cache variables if in try_compile() +set(FORCE_CACHE FORCE) +get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) +if(_CMAKE_IN_TRY_COMPILE) + unset(FORCE_CACHE) +endif() + +# Default to building for iPhoneOS if not specified otherwise, and we cannot +# determine the platform from the CMAKE_OSX_ARCHITECTURES variable. The use +# of CMAKE_OSX_ARCHITECTURES is such that try_compile() projects can correctly +# determine the value of PLATFORM from the root project, as +# CMAKE_OSX_ARCHITECTURES is propagated to them by CMake. +if(NOT DEFINED PLATFORM) + if (CMAKE_OSX_ARCHITECTURES) + if(CMAKE_OSX_ARCHITECTURES MATCHES ".*arm.*" AND CMAKE_OSX_SYSROOT MATCHES ".*iphoneos.*") + set(PLATFORM "OS") + elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*") + set(PLATFORM "SIMULATOR") + elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*") + set(PLATFORM "SIMULATOR64") + elseif(CMAKE_OSX_ARCHITECTURES MATCHES "arm64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvos.*") + set(PLATFORM "TVOS") + elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvsimulator.*") + set(PLATFORM "SIMULATOR_TVOS") + elseif(CMAKE_OSX_ARCHITECTURES MATCHES ".*armv7k.*" AND CMAKE_OSX_SYSROOT MATCHES ".*watchos.*") + set(PLATFORM "WATCHOS") + elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*watchsimulator.*") + set(PLATFORM "SIMULATOR_WATCHOS") + endif() + endif() + if (NOT PLATFORM) + set(PLATFORM "OS") + endif() +endif() + +set(PLATFORM_INT "${PLATFORM}" CACHE STRING "Type of platform for which the build targets.") + +# Handle the case where we are targeting iOS and a version above 10.3.4 (32-bit support dropped officially) +if(PLATFORM_INT STREQUAL "OS" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4) + set(PLATFORM_INT "OS64") + message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.") +elseif(PLATFORM_INT STREQUAL "SIMULATOR" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4) + set(PLATFORM_INT "SIMULATOR64") + message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.") +endif() + +# Determine the platform name and architectures for use in xcodebuild commands +# from the specified PLATFORM name. +if(PLATFORM_INT STREQUAL "OS") + set(SDK_NAME iphoneos) + if(NOT ARCHS) + set(ARCHS armv7 armv7s arm64) + set(APPLE_TARGET_TRIPLE_INT arm-apple-ios) + endif() +elseif(PLATFORM_INT STREQUAL "OS64") + set(SDK_NAME iphoneos) + if(NOT ARCHS) + if (XCODE_VERSION VERSION_GREATER 10.0) + set(ARCHS arm64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example + else() + set(ARCHS arm64) + endif() + set(APPLE_TARGET_TRIPLE_INT aarch64-apple-ios) + endif() +elseif(PLATFORM_INT STREQUAL "OS64COMBINED") + set(SDK_NAME iphoneos) + if(MODERN_CMAKE) + if(NOT ARCHS) + if (XCODE_VERSION VERSION_GREATER 10.0) + set(ARCHS arm64 x86_64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example + else() + set(ARCHS arm64 x86_64) + endif() + set(APPLE_TARGET_TRIPLE_INT aarch64-x86_64-apple-ios) + endif() + else() + message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the OS64COMBINED setting work") + endif() +elseif(PLATFORM_INT STREQUAL "SIMULATOR") + set(SDK_NAME iphonesimulator) + if(NOT ARCHS) + set(ARCHS i386) + set(APPLE_TARGET_TRIPLE_INT i386-apple-ios) + endif() + message(DEPRECATION "SIMULATOR IS DEPRECATED. Consider using SIMULATOR64 instead.") +elseif(PLATFORM_INT STREQUAL "SIMULATOR64") + set(SDK_NAME iphonesimulator) + if(NOT ARCHS) + set(ARCHS x86_64) + set(APPLE_TARGET_TRIPLE_INT x86_64-apple-ios) + endif() +elseif(PLATFORM_INT STREQUAL "TVOS") + set(SDK_NAME appletvos) + if(NOT ARCHS) + set(ARCHS arm64) + set(APPLE_TARGET_TRIPLE_INT aarch64-apple-tvos) + endif() +elseif (PLATFORM_INT STREQUAL "TVOSCOMBINED") + set(SDK_NAME appletvos) + if(MODERN_CMAKE) + if(NOT ARCHS) + set(ARCHS arm64 x86_64) + set(APPLE_TARGET_TRIPLE_INT aarch64-x86_64-apple-tvos) + endif() + else() + message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the TVOSCOMBINED setting work") + endif() +elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS") + set(SDK_NAME appletvsimulator) + if(NOT ARCHS) + set(ARCHS x86_64) + set(APPLE_TARGET_TRIPLE_INT x86_64-apple-tvos) + endif() +elseif(PLATFORM_INT STREQUAL "WATCHOS") + set(SDK_NAME watchos) + if(NOT ARCHS) + if (XCODE_VERSION VERSION_GREATER 10.0) + set(ARCHS armv7k arm64_32) + set(APPLE_TARGET_TRIPLE_INT aarch64_32-apple-watchos) + else() + set(ARCHS armv7k) + set(APPLE_TARGET_TRIPLE_INT arm-apple-watchos) + endif() + endif() +elseif(PLATFORM_INT STREQUAL "WATCHOSCOMBINED") + set(SDK_NAME watchos) + if(MODERN_CMAKE) + if(NOT ARCHS) + if (XCODE_VERSION VERSION_GREATER 10.0) + set(ARCHS armv7k arm64_32 i386) + set(APPLE_TARGET_TRIPLE_INT aarch64_32-i386-apple-watchos) + else() + set(ARCHS armv7k i386) + set(APPLE_TARGET_TRIPLE_INT arm-i386-apple-watchos) + endif() + endif() + else() + message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the WATCHOSCOMBINED setting work") + endif() +elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") + set(SDK_NAME watchsimulator) + if(NOT ARCHS) + set(ARCHS i386) + set(APPLE_TARGET_TRIPLE_INT i386-apple-watchos) + endif() +else() + message(FATAL_ERROR "Invalid PLATFORM: ${PLATFORM_INT}") +endif() + +if(MODERN_CMAKE AND PLATFORM_INT MATCHES ".*COMBINED" AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode") + message(FATAL_ERROR "The COMBINED options only work with Xcode generator, -G Xcode") +endif() + +# If user did not specify the SDK root to use, then query xcodebuild for it. +execute_process(COMMAND xcodebuild -version -sdk ${SDK_NAME} Path + OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_INT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +if (NOT DEFINED CMAKE_OSX_SYSROOT_INT AND NOT DEFINED CMAKE_OSX_SYSROOT) + message(SEND_ERROR "Please make sure that Xcode is installed and that the toolchain" + "is pointing to the correct path. Please run:" + "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer" + "and see if that fixes the problem for you.") + message(FATAL_ERROR "Invalid CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT} " + "does not exist.") +elseif(DEFINED CMAKE_OSX_SYSROOT_INT) + set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT_INT}" CACHE INTERNAL "") +endif() + +# Set Xcode property for SDKROOT as well if Xcode generator is used +if(USED_CMAKE_GENERATOR MATCHES "Xcode") + set(CMAKE_OSX_SYSROOT "${SDK_NAME}" CACHE INTERNAL "") + if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM) + set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "123456789A" CACHE INTERNAL "") + endif() +endif() + +# Specify minimum version of deployment target. +if(NOT DEFINED DEPLOYMENT_TARGET) + if (PLATFORM_INT STREQUAL "WATCHOS" OR PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") + # Unless specified, SDK version 2.0 is used by default as minimum target version (watchOS). + set(DEPLOYMENT_TARGET "2.0" + CACHE STRING "Minimum SDK version to build for." ) + else() + # Unless specified, SDK version 9.0 is used by default as minimum target version (iOS, tvOS). + set(DEPLOYMENT_TARGET "9.0" + CACHE STRING "Minimum SDK version to build for." ) + endif() + message(STATUS "Using the default min-version since DEPLOYMENT_TARGET not provided!") +endif() + +# Use bitcode or not +if(NOT DEFINED ENABLE_BITCODE AND NOT ARCHS MATCHES "((^|;|, )(i386|x86_64))+") + # Unless specified, enable bitcode support by default + message(STATUS "Enabling bitcode support by default. ENABLE_BITCODE not provided!") + set(ENABLE_BITCODE TRUE) +elseif(NOT DEFINED ENABLE_BITCODE) + message(STATUS "Disabling bitcode support by default on simulators. ENABLE_BITCODE not provided for override!") + set(ENABLE_BITCODE FALSE) +endif() +set(ENABLE_BITCODE_INT ${ENABLE_BITCODE} CACHE BOOL "Whether or not to enable bitcode" ${FORCE_CACHE}) +# Use ARC or not +if(NOT DEFINED ENABLE_ARC) + # Unless specified, enable ARC support by default + set(ENABLE_ARC TRUE) + message(STATUS "Enabling ARC support by default. ENABLE_ARC not provided!") +endif() +set(ENABLE_ARC_INT ${ENABLE_ARC} CACHE BOOL "Whether or not to enable ARC" ${FORCE_CACHE}) +# Use hidden visibility or not +if(NOT DEFINED ENABLE_VISIBILITY) + # Unless specified, disable symbols visibility by default + set(ENABLE_VISIBILITY FALSE) + message(STATUS "Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!") +endif() +set(ENABLE_VISIBILITY_INT ${ENABLE_VISIBILITY} CACHE BOOL "Whether or not to hide symbols (-fvisibility=hidden)" ${FORCE_CACHE}) +# Set strict compiler checks or not +if(NOT DEFINED ENABLE_STRICT_TRY_COMPILE) + # Unless specified, disable strict try_compile() + set(ENABLE_STRICT_TRY_COMPILE FALSE) + message(STATUS "Using NON-strict compiler checks by default. ENABLE_STRICT_TRY_COMPILE not provided!") +endif() +set(ENABLE_STRICT_TRY_COMPILE_INT ${ENABLE_STRICT_TRY_COMPILE} CACHE BOOL "Whether or not to use strict compiler checks" ${FORCE_CACHE}) +# Get the SDK version information. +execute_process(COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion + OUTPUT_VARIABLE SDK_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + +# Find the Developer root for the specific iOS platform being compiled for +# from CMAKE_OSX_SYSROOT. Should be ../../ from SDK specified in +# CMAKE_OSX_SYSROOT. There does not appear to be a direct way to obtain +# this information from xcrun or xcodebuild. +if (NOT DEFINED CMAKE_DEVELOPER_ROOT AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode") + get_filename_component(PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT} PATH) + get_filename_component(CMAKE_DEVELOPER_ROOT ${PLATFORM_SDK_DIR} PATH) + if (NOT DEFINED CMAKE_DEVELOPER_ROOT) + message(FATAL_ERROR "Invalid CMAKE_DEVELOPER_ROOT: " + "${CMAKE_DEVELOPER_ROOT} does not exist.") + endif() +endif() +# Find the C & C++ compilers for the specified SDK. +if(NOT CMAKE_C_COMPILER) + execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang + OUTPUT_VARIABLE CMAKE_C_COMPILER + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}") +endif() +if(NOT CMAKE_CXX_COMPILER) + execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang++ + OUTPUT_VARIABLE CMAKE_CXX_COMPILER + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + message(STATUS "Using CXX compiler: ${CMAKE_CXX_COMPILER}") +endif() +# Find (Apple's) libtool. +execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find libtool + OUTPUT_VARIABLE BUILD_LIBTOOL + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +message(STATUS "Using libtool: ${BUILD_LIBTOOL}") +# Configure libtool to be used instead of ar + ranlib to build static libraries. +# This is required on Xcode 7+, but should also work on previous versions of +# Xcode. +set(CMAKE_C_CREATE_STATIC_LIBRARY + "${BUILD_LIBTOOL} -static -o ") +set(CMAKE_CXX_CREATE_STATIC_LIBRARY + "${BUILD_LIBTOOL} -static -o ") +# Find the toolchain's provided install_name_tool if none is found on the host +if(NOT CMAKE_INSTALL_NAME_TOOL) + execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find install_name_tool + OUTPUT_VARIABLE CMAKE_INSTALL_NAME_TOOL_INT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(CMAKE_INSTALL_NAME_TOOL ${CMAKE_INSTALL_NAME_TOOL_INT} CACHE STRING "" ${FORCE_CACHE}) +endif() +# Get the version of Darwin (OS X) of the host. +execute_process(COMMAND uname -r + OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +if(SDK_NAME MATCHES "iphone") + set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" ${FORCE_CACHE}) +endif() +# CMake 3.14+ support building for iOS, watchOS and tvOS out of the box. +if(MODERN_CMAKE) + if(SDK_NAME MATCHES "appletv") + set(CMAKE_SYSTEM_NAME tvOS CACHE INTERNAL "" ${FORCE_CACHE}) + elseif(SDK_NAME MATCHES "watch") + set(CMAKE_SYSTEM_NAME watchOS CACHE INTERNAL "" ${FORCE_CACHE}) + endif() + # Provide flags for a combined FAT library build on newer CMake versions + if(PLATFORM_INT MATCHES ".*COMBINED") + set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "NO" CACHE INTERNAL "" ${FORCE_CACHE}) + set(CMAKE_IOS_INSTALL_COMBINED YES CACHE INTERNAL "" ${FORCE_CACHE}) + message(STATUS "Will combine built (static) artifacts into FAT lib...") + endif() +elseif(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.10") + # Legacy code path prior to CMake 3.14 or fallback if no SDK_NAME specified + set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" ${FORCE_CACHE}) +else() + # Legacy code path prior to CMake 3.14 or fallback if no SDK_NAME specified + set(CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL "" ${FORCE_CACHE}) +endif() +# Standard settings. +set(CMAKE_SYSTEM_VERSION ${SDK_VERSION} CACHE INTERNAL "") +set(UNIX TRUE CACHE BOOL "") +set(APPLE TRUE CACHE BOOL "") +set(IOS TRUE CACHE BOOL "") +set(CMAKE_AR ar CACHE FILEPATH "" FORCE) +set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE) +set(CMAKE_STRIP strip CACHE FILEPATH "" FORCE) +# Set the architectures for which to build. +set(CMAKE_OSX_ARCHITECTURES ${ARCHS} CACHE STRING "Build architecture for iOS") +# Change the type of target generated for try_compile() so it'll work when cross-compiling, weak compiler checks +if(ENABLE_STRICT_TRY_COMPILE_INT) + message(STATUS "Using strict compiler checks (default in CMake).") +else() + set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +endif() +# All iOS/Darwin specific settings - some may be redundant. +set(CMAKE_MACOSX_BUNDLE YES) +set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO") +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_C_COMPILER_ABI ELF) +set(CMAKE_CXX_COMPILER_ABI ELF) +set(CMAKE_C_HAS_ISYSROOT 1) +set(CMAKE_CXX_HAS_ISYSROOT 1) +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}") + +if(ARCHS MATCHES "((^|;|, )(arm64|arm64e|x86_64))+") + set(CMAKE_C_SIZEOF_DATA_PTR 8) + set(CMAKE_CXX_SIZEOF_DATA_PTR 8) + if(ARCHS MATCHES "((^|;|, )(arm64|arm64e))+") + set(CMAKE_SYSTEM_PROCESSOR "aarch64") + else() + set(CMAKE_SYSTEM_PROCESSOR "x86_64") + endif() +else() + set(CMAKE_C_SIZEOF_DATA_PTR 4) + set(CMAKE_CXX_SIZEOF_DATA_PTR 4) + set(CMAKE_SYSTEM_PROCESSOR "arm") +endif() + +# Note that only Xcode 7+ supports the newer more specific: +# -m${SDK_NAME}-version-min flags, older versions of Xcode use: +# -m(ios/ios-simulator)-version-min instead. +if(${CMAKE_VERSION} VERSION_LESS "3.11") + if(PLATFORM_INT STREQUAL "OS" OR PLATFORM_INT STREQUAL "OS64") + if(XCODE_VERSION VERSION_LESS 7.0) + set(SDK_NAME_VERSION_FLAGS + "-mios-version-min=${DEPLOYMENT_TARGET}") + else() + # Xcode 7.0+ uses flags we can build directly from SDK_NAME. + set(SDK_NAME_VERSION_FLAGS + "-m${SDK_NAME}-version-min=${DEPLOYMENT_TARGET}") + endif() + elseif(PLATFORM_INT STREQUAL "TVOS") + set(SDK_NAME_VERSION_FLAGS + "-mtvos-version-min=${DEPLOYMENT_TARGET}") + elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS") + set(SDK_NAME_VERSION_FLAGS + "-mtvos-simulator-version-min=${DEPLOYMENT_TARGET}") + elseif(PLATFORM_INT STREQUAL "WATCHOS") + set(SDK_NAME_VERSION_FLAGS + "-mwatchos-version-min=${DEPLOYMENT_TARGET}") + elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") + set(SDK_NAME_VERSION_FLAGS + "-mwatchos-simulator-version-min=${DEPLOYMENT_TARGET}") + else() + # SIMULATOR or SIMULATOR64 both use -mios-simulator-version-min. + set(SDK_NAME_VERSION_FLAGS + "-mios-simulator-version-min=${DEPLOYMENT_TARGET}") + endif() +else() + # Newer versions of CMake sets the version min flags correctly + set(CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} CACHE STRING + "Set CMake deployment target" ${FORCE_CACHE}) +endif() + +if(DEFINED APPLE_TARGET_TRIPLE_INT) + set(APPLE_TARGET_TRIPLE ${APPLE_TARGET_TRIPLE_INT} CACHE STRING + "Autoconf target triple compatible variable" ${FORCE_CACHE}) +endif() + +if(ENABLE_BITCODE_INT) + set(BITCODE "-fembed-bitcode") + set(CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE "bitcode" CACHE INTERNAL "") + set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES" CACHE INTERNAL "") +else() + set(BITCODE "") + set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO" CACHE INTERNAL "") +endif() + +if(ENABLE_ARC_INT) + set(FOBJC_ARC "-fobjc-arc") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES" CACHE INTERNAL "") +else() + set(FOBJC_ARC "-fno-objc-arc") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "NO" CACHE INTERNAL "") +endif() + +if(NOT ENABLE_VISIBILITY_INT) + set(VISIBILITY "-fvisibility=hidden") + set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "YES" CACHE INTERNAL "") +else() + set(VISIBILITY "") + set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "NO" CACHE INTERNAL "") +endif() + +if(NOT IOS_TOOLCHAIN_HAS_RUN) + #Check if Xcode generator is used, since that will handle these flags automagically + if(USED_CMAKE_GENERATOR MATCHES "Xcode") + message(STATUS "Not setting any manual command-line buildflags, since Xcode is selected as generator.") + else() + set(CMAKE_C_FLAGS + "${SDK_NAME_VERSION_FLAGS} ${BITCODE} -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_C_FLAGS}") + # Hidden visibilty is required for C++ on iOS. + set(CMAKE_CXX_FLAGS + "${SDK_NAME_VERSION_FLAGS} ${BITCODE} ${VISIBILITY} -fvisibility-inlines-hidden -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g ${CMAKE_CXX_FLAGS_DEBUG}") + set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG -Os -ffast-math ${CMAKE_CXX_FLAGS_MINSIZEREL}") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG -O2 -g -ffast-math ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -ffast-math ${CMAKE_CXX_FLAGS_RELEASE}") + set(CMAKE_C_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") + set(CMAKE_CXX_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") + set(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp") + + # In order to ensure that the updated compiler flags are used in try_compile() + # tests, we have to forcibly set them in the CMake cache, not merely set them + # in the local scope. + set(VARS_TO_FORCE_IN_CACHE + CMAKE_C_FLAGS + CMAKE_CXX_FLAGS + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS_MINSIZEREL + CMAKE_CXX_FLAGS_RELEASE + CMAKE_C_LINK_FLAGS + CMAKE_CXX_LINK_FLAGS) + foreach(VAR_TO_FORCE ${VARS_TO_FORCE_IN_CACHE}) + set(${VAR_TO_FORCE} "${${VAR_TO_FORCE}}" CACHE STRING "" ${FORCE_CACHE}) + endforeach() + endif() + + ## Print status messages to inform of the current state + message(STATUS "Configuring ${SDK_NAME} build for platform: ${PLATFORM_INT}, architecture(s): ${ARCHS}") + message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT_INT}") + if(DEFINED APPLE_TARGET_TRIPLE) + message(STATUS "Autoconf target triple: ${APPLE_TARGET_TRIPLE}") + endif() + message(STATUS "Using minimum deployment version: ${DEPLOYMENT_TARGET}" + " (SDK version: ${SDK_VERSION})") + if(MODERN_CMAKE) + message(STATUS "Merging integrated CMake 3.14+ iOS,tvOS,watchOS,macOS toolchain(s) with this toolchain!") + endif() + if(USED_CMAKE_GENERATOR MATCHES "Xcode") + message(STATUS "Using Xcode version: ${XCODE_VERSION}") + endif() + if(DEFINED SDK_NAME_VERSION_FLAGS) + message(STATUS "Using version flags: ${SDK_NAME_VERSION_FLAGS}") + endif() + message(STATUS "Using a data_ptr size of: ${CMAKE_CXX_SIZEOF_DATA_PTR}") + message(STATUS "Using install_name_tool: ${CMAKE_INSTALL_NAME_TOOL}") + if(ENABLE_BITCODE_INT) + message(STATUS "Enabling bitcode support.") + else() + message(STATUS "Disabling bitcode support.") + endif() + + if(ENABLE_ARC_INT) + message(STATUS "Enabling ARC support.") + else() + message(STATUS "Disabling ARC support.") + endif() + + if(NOT ENABLE_VISIBILITY_INT) + message(STATUS "Hiding symbols (-fvisibility=hidden).") + endif() +endif() + +set(CMAKE_PLATFORM_HAS_INSTALLNAME 1) +set(CMAKE_SHARED_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks") +set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names") +set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -Wl,-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 ".tbd" ".dylib" ".so" ".a") +set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name") + +# Set the find root to the iOS developer roots and to user defined paths. +set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT_INT} ${CMAKE_PREFIX_PATH} CACHE STRING "Root path that will be prepended + to all search paths") +# Default to searching for frameworks first. +set(CMAKE_FIND_FRAMEWORK FIRST) +# Set up the default search directories for frameworks. +set(CMAKE_FRAMEWORK_PATH + ${CMAKE_DEVELOPER_ROOT}/Library/PrivateFrameworks + ${CMAKE_OSX_SYSROOT_INT}/System/Library/Frameworks + ${CMAKE_FRAMEWORK_PATH} CACHE STRING "Frameworks search paths" ${FORCE_CACHE}) + +set(IOS_TOOLCHAIN_HAS_RUN TRUE CACHE BOOL "Has the CMake toolchain run already?" ${FORCE_CACHE}) + +# By default, search both the specified iOS SDK and the remainder of the host filesystem. +if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH CACHE STRING "" ${FORCE_CACHE}) +endif() +if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH CACHE STRING "" ${FORCE_CACHE}) +endif() +if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH CACHE STRING "" ${FORCE_CACHE}) +endif() +if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH CACHE STRING "" ${FORCE_CACHE}) +endif() + +# +# Some helper-macros below to simplify and beautify the CMakeFile +# + +# This little macro lets you set any Xcode specific property. +macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE XCODE_RELVERSION) + set(XCODE_RELVERSION_I "${XCODE_RELVERSION}") + if(XCODE_RELVERSION_I STREQUAL "All") + set_property(TARGET ${TARGET} PROPERTY + XCODE_ATTRIBUTE_${XCODE_PROPERTY} "${XCODE_VALUE}") + else() + set_property(TARGET ${TARGET} PROPERTY + XCODE_ATTRIBUTE_${XCODE_PROPERTY}[variant=${XCODE_RELVERSION_I}] "${XCODE_VALUE}") + endif() +endmacro(set_xcode_property) + +# This macro lets you find executable programs on the host system. +macro(find_host_package) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) + set(IOS FALSE) + find_package(${ARGN}) + set(IOS TRUE) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) +endmacro(find_host_package) diff --git a/contrib/ios/readme.txt b/contrib/ios/readme.txt new file mode 100644 index 0000000000..88ab3187bc --- /dev/null +++ b/contrib/ios/readme.txt @@ -0,0 +1,12 @@ +the internet is gripped by a spectre, the spectre of developing for the apple iphone. +our scientists have yet to reverse engineer the correct way to use the apple build process as dictated on the official apple documentation so we have a made a hack to make it work until that occurs. + +the build process for embedded lokinet on iphone is as follows: + +* obtain holy water, sprinkle onto keyboard and single button trackpad accordingly. +* run ./contrib/ios.sh +* after it runs and the proper number of goats have been offered to the slaughter you will get a static object archive somewhere in ./build/iphone/ + +additional cmake flags can be passed to ./contrib/ios.sh as command line arguments like so: + + $ ./contrib/ios.sh -DPLATFORM=SIMULATOR64 From 5a7fa2a8b16651ae087e782da9c075b8a41a4df5 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 14 Jun 2022 14:00:05 -0400 Subject: [PATCH 11/33] tmp --- CMakeLists.txt | 6 +----- cmake/StaticBuild.cmake | 20 +++++++------------- contrib/ios.sh | 11 +++-------- 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5f7fb0f0c..c95a7eff94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,11 +14,7 @@ if(APPLE AND BUILD_DAEMON) endif() -option(WITH_CCACHE "enable ccache" ON) - -if(WITH_CCACHE) - find_program(CCACHE_PROGRAM ccache) -endif() +find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) foreach(lang ${LANGS}) diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake index 048de7a043..75914e6d70 100644 --- a/cmake/StaticBuild.cmake +++ b/cmake/StaticBuild.cmake @@ -105,17 +105,17 @@ function(add_static_target target ext_target libname) endfunction() - set(cross_host "") set(cross_rc "") if(CMAKE_CROSSCOMPILING) if(APPLE_TARGET_TRIPLE) - set(ARCH_TRIPLET "${APPLE_TARGET_TRIPLE}") - endif() - set(cross_host "--host=${ARCH_TRIPLET}") - if (ARCH_TRIPLET MATCHES mingw AND CMAKE_RC_COMPILER) - set(cross_rc "WINDRES=${CMAKE_RC_COMPILER}") + set(cross_host "--host=${APPLE_TARGET_TRIPLE}") + else() + set(cross_host "--host=${ARCH_TRIPLET}") + if (ARCH_TRIPLET MATCHES mingw AND CMAKE_RC_COMPILER) + set(cross_rc "WINDRES=${CMAKE_RC_COMPILER}") + endif() endif() endif() @@ -167,12 +167,6 @@ if(WITH_LTO) set(deps_CFLAGS "${deps_CFLAGS} -flto") endif() -if(APPLE AND NOT IOS) - set(deps_CFLAGS "${deps_CFLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}") - set(deps_CXXFLAGS "${deps_CXXFLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}") -endif() - - if("${CMAKE_GENERATOR}" STREQUAL "Unix Makefiles") set(_make $(MAKE)) else() @@ -266,7 +260,7 @@ if(CMAKE_CROSSCOMPILING) if(NOT ${apple_toolchain} MATCHES Xcode OR NOT ${apple_sdk} MATCHES "iPhone(OS|Simulator)") message(FATAL_ERROR "didn't find your toolchain and sdk correctly from ${CMAKE_C_COMPILER}/${CMAKE_OSX_SYSROOT}: found toolchain=${apple_toolchain}, sdk=${apple_sdk}") endif() - set(openssl_system_env CROSS_COMPILE=${apple_toolchain}/ CROSS_TOP=${CMAKE_DEVELOPER_ROOT} CROSS_SDK=${apple_sdk}) + set(openssl_system_env CROSS_COMPILE=${apple_toolchain} CROSS_TOP=${CMAKE_DEVELOPER_ROOT} CROSS_SDK=${apple_sdk}) set(openssl_configure ./Configure iphoneos-cross) set(openssl_cc "clang") elseif(ARCH_TRIPLET STREQUAL mips64-linux-gnuabi64) diff --git a/contrib/ios.sh b/contrib/ios.sh index 9241da6cff..331599afcd 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -8,16 +8,10 @@ if ! [ -f LICENSE ] || ! [ -d llarp ]; then echo "You need to run this as ./contrib/ios.sh from the top-level lokinet project directory" fi -_sdk=${SDK:-iphoneos} - mkdir -p build/iphone cmake \ -G Ninja \ - -DWITH_CCACHE=OFF \ - -DCMAKE_C_COMPILER=$(xcrun --find --sdk ${_sdk} clang ) \ - -DCMAKE_CXX_COMPILER=$(xcrun --find --sdk ${_sdk} clang++ ) \ - -DCMAKE_OSX_SYSROOT=$( xcrun --sdk ${_sdk} --show-sdk-path ) \ - -DCMAKE_TOOLCHAIN_FILE=contrib/cross/ios.toolchain.cmake \ + -DCMAKE_CXX_COMPILER_LAUNCHER= -DCMAKE_C_COMPILER_LAUNCHER= \ -DBUILD_STATIC_DEPS=ON \ -DBUILD_PACKAGE=OFF \ -DBUILD_SHARED_LIBS=OFF \ @@ -35,6 +29,7 @@ cmake \ -DSUBMODULE_CHECK=ON \ -DWITH_LTO=OFF \ -S . -B build/iphone \ - "$@" + $@ \ + -DCMAKE_TOOLCHAIN_FILE=contrib/cross/ios.toolchain.cmake cmake --build build/iphone --target lokinet-shared From e3aa9e83555e08d6f311cc2fbd0cacadf30251ae Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 16:41:16 -0400 Subject: [PATCH 12/33] OH MY FUCKING SWEET BABY JESUS SON OF THE VIRGIN MARY IT FUCKING COMPILES FOR IPHONE --- .gitmodules | 3 ++ CMakeLists.txt | 8 +++-- cmake/StaticBuild.cmake | 57 +++++++++++++++++++++--------------- cmake/combine_archives.cmake | 30 +++++++++++++++++++ contrib/ios.sh | 9 +++--- crypto/CMakeLists.txt | 2 +- external/CMakeLists.txt | 3 +- llarp/CMakeLists.txt | 26 ++++++++++++---- 8 files changed, 100 insertions(+), 38 deletions(-) create mode 100644 cmake/combine_archives.cmake diff --git a/.gitmodules b/.gitmodules index 60d5d96217..23ec941b04 100644 --- a/.gitmodules +++ b/.gitmodules @@ -36,3 +36,6 @@ [submodule "external/oxen-encoding"] path = external/oxen-encoding url = https://github.com/oxen-io/oxen-encoding.git +[submodule "external/libuv"] + path = external/libuv + url = https://github.com/libuv/libuv diff --git a/CMakeLists.txt b/CMakeLists.txt index c95a7eff94..fe144d6a74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,11 +48,12 @@ endif() # Core options -option(USE_AVX2 "enable avx2 code" OFF) +option(USE_AVX2 "enable avx2 code" ON) option(USE_NETNS "enable networking namespace support. Linux only" OFF) option(NATIVE_BUILD "optimise for host system and FPU" ON) option(EMBEDDED_CFG "optimise for older hardware or embedded systems" OFF) -option(BUILD_LIBLOKINET "build liblokinet.so" ON) +option(BUILD_LIBLOKINET "build liblokinet.so" OFF) +option(BUILD_EMBEDDED_LOKINET "build embedded lokinet" OFF) option(XSAN "use sanitiser, if your system has it (requires -DCMAKE_BUILD_TYPE=Debug)" OFF) option(USE_JEMALLOC "Link to jemalloc for memory allocations, if found" ON) option(TESTNET "testnet build" OFF) @@ -73,8 +74,10 @@ option(STATIC_LINK "link statically against dependencies" ${BUILD_STATIC_DEPS}) if(BUILD_STATIC_DEPS AND NOT STATIC_LINK) message(FATAL_ERROR "Option BUILD_STATIC_DEPS requires STATIC_LINK to be enabled as well") endif() + if(BUILD_STATIC_DEPS) set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) + include(cmake/combine_archives.cmake) include(StaticBuild) endif() @@ -140,6 +143,7 @@ find_package(PkgConfig REQUIRED) if(NOT BUILD_STATIC_DEPS) pkg_check_modules(LIBUV libuv>=1.18.0 IMPORTED_TARGET) endif() + if(LIBUV_FOUND AND NOT BUILD_STATIC_DEPS) add_library(libuv INTERFACE) target_link_libraries(libuv INTERFACE PkgConfig::LIBUV) diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake index 75914e6d70..6e575b7e8d 100644 --- a/cmake/StaticBuild.cmake +++ b/cmake/StaticBuild.cmake @@ -48,13 +48,6 @@ set(ZMQ_SOURCE zeromq-${ZMQ_VERSION}.tar.gz) set(ZMQ_HASH SHA512=e198ef9f82d392754caadd547537666d4fba0afd7d027749b3adae450516bcf284d241d4616cad3cb4ad9af8c10373d456de92dc6d115b037941659f141e7c0e CACHE STRING "libzmq source hash") -set(LIBUV_VERSION 1.44.1 CACHE STRING "libuv version") -set(LIBUV_MIRROR ${LOCAL_MIRROR} https://dist.libuv.org/dist/v${LIBUV_VERSION} - CACHE STRING "libuv mirror(s)") -set(LIBUV_SOURCE libuv-v${LIBUV_VERSION}.tar.gz) -set(LIBUV_HASH SHA512=b4f8944e2c79e3a6a31ded6cccbe4c0eeada50db6bc8a448d7015642795012a4b80ffeef7ca455bb093c59a8950d0e1430566c3c2fa87b73f82699098162d834 - CACHE STRING "libuv source hash") - set(ZLIB_VERSION 1.2.12 CACHE STRING "zlib version") set(ZLIB_MIRROR ${LOCAL_MIRROR} https://zlib.net CACHE STRING "zlib mirror(s)") @@ -224,16 +217,6 @@ function(build_external target) BUILD_BYPRODUCTS ${arg_BUILD_BYPRODUCTS} ) endfunction() - -build_external(libuv - CONFIGURE_COMMAND ./autogen.sh && ./configure ${cross_host} ${cross_rc} --prefix=${DEPS_DESTDIR} --with-pic --disable-shared --enable-static "CC=${deps_cc}" "CFLAGS=${deps_CFLAGS}" - BUILD_BYPRODUCTS - ${DEPS_DESTDIR}/lib/libuv.a - ${DEPS_DESTDIR}/include/uv.h - ) -add_static_target(libuv libuv_external libuv.a) -target_link_libraries(libuv INTERFACE ${CMAKE_DL_LIBS}) - build_external(zlib CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env "CC=${deps_cc}" "CFLAGS=${deps_CFLAGS} -fPIC" ${cross_extra} ./configure --prefix=${DEPS_DESTDIR} --static @@ -286,11 +269,35 @@ elseif(CMAKE_C_FLAGS MATCHES "-march=armv7") endif() + +set(openssl_configure ./config) +set(openssl_system_env "") +set(openssl_cc "${deps_cc}") +if(CMAKE_CROSSCOMPILING) + if(ARCH_TRIPLET STREQUAL x86_64-w64-mingw32) + set(openssl_system_env SYSTEM=MINGW64 RC=${CMAKE_RC_COMPILER}) + elseif(ARCH_TRIPLET STREQUAL i686-w64-mingw32) + set(openssl_system_env SYSTEM=MINGW64 RC=${CMAKE_RC_COMPILER}) + elseif(ANDROID) + set(openssl_system_env SYSTEM=Linux MACHINE=${openssl_machine} ${cross_rc}) + set(openssl_extra_opts no-asm) + elseif(IOS) + get_filename_component(apple_toolchain "${CMAKE_C_COMPILER}" DIRECTORY) + get_filename_component(apple_sdk "${CMAKE_OSX_SYSROOT}" NAME) + if(NOT ${apple_toolchain} MATCHES Xcode OR NOT ${apple_sdk} MATCHES "iPhone(OS|Simulator)") + message(FATAL_ERROR "didn't find your toolchain and sdk correctly from ${CMAKE_C_COMPILER}/${CMAKE_OSX_SYSROOT}: found toolchain=${apple_toolchain}, sdk=${apple_sdk}") + endif() + set(openssl_system_env CROSS_COMPILE=${apple_toolchain}/ CROSS_TOP=${CMAKE_DEVELOPER_ROOT} CROSS_SDK=${apple_sdk}) + set(openssl_configure ./Configure iphoneos-cross) + set(openssl_cc "clang") + endif() +endif() + build_external(openssl - CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env CC=${deps_cc} ${openssl_system_env} ${openssl_configure_command} - --prefix=${DEPS_DESTDIR} ${openssl_extra_opts} no-shared no-capieng no-dso no-dtls1 no-ec_nistp_64_gcc_128 no-gost - no-heartbeats no-md2 no-rc5 no-rdrand no-rfc3779 no-sctp no-ssl-trace no-ssl2 no-ssl3 - no-static-engine no-tests no-weak-ssl-ciphers no-zlib no-zlib-dynamic "CFLAGS=${deps_CFLAGS}" + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env CC=${openssl_cc} ${openssl_system_env} ${openssl_configure} + --prefix=${DEPS_DESTDIR} ${openssl_extra_opts} no-shared no-capieng no-dso no-dtls1 no-ec_nistp_64_gcc_128 no-gost + no-heartbeats no-md2 no-rc5 no-rdrand no-rfc3779 no-sctp no-ssl-trace no-ssl2 no-ssl3 no-engine + no-static-engine no-tests no-weak-ssl-ciphers no-zlib-dynamic "CFLAGS=${deps_CFLAGS}" INSTALL_COMMAND ${_make} install_sw BUILD_BYPRODUCTS ${DEPS_DESTDIR}/lib/libssl.a ${DEPS_DESTDIR}/lib/libcrypto.a @@ -301,7 +308,6 @@ add_static_target(OpenSSL::Crypto openssl_external libcrypto.a) if(WIN32) target_link_libraries(OpenSSL::Crypto INTERFACE "ws2_32;crypt32;iphlpapi") endif() - set(OPENSSL_INCLUDE_DIR ${DEPS_DESTDIR}/include) set(OPENSSL_CRYPTO_LIBRARY ${DEPS_DESTDIR}/lib/libcrypto.a ${DEPS_DESTDIR}/lib/libssl.a) set(OPENSSL_VERSION 1.1.1) @@ -323,7 +329,7 @@ endif() build_external(unbound DEPENDS openssl_external expat_external CONFIGURE_COMMAND ./configure ${cross_host} ${cross_rc} --prefix=${DEPS_DESTDIR} --disable-shared - --enable-static --with-libunbound-only --with-pic + --enable-static --with-libunbound-only --with-pic --disable-gost --$,enable,disable>-flto --with-ssl=${DEPS_DESTDIR} --with-libexpat=${DEPS_DESTDIR} "CC=${deps_cc}" "CFLAGS=${deps_CFLAGS}" ${unbound_extra} @@ -341,7 +347,10 @@ build_external(sodium CONFIGURE_COMMAND ./configure ${cross_host} ${cross_rc} -- --enable-static --with-pic "CC=${deps_cc}" "CFLAGS=${deps_CFLAGS}") add_static_target(sodium sodium_external libsodium.a) -build_external(sqlite3) +build_external(sqlite3 CONFIGURE_COMMAND ./configure ${cross_host} ${cross_rc} --prefix=${DEPS_DESTDIR} --enable-static --disable-shared --disable-readline --with-pic "CC=${deps_cc}" "CFLAGS=${deps_CFLAGS}" + BUILD_COMMAND true + INSTALL_COMMAND make install-includeHEADERS install-libLTLIBRARIES) + add_static_target(sqlite3 sqlite3_external libsqlite3.a) diff --git a/cmake/combine_archives.cmake b/cmake/combine_archives.cmake new file mode 100644 index 0000000000..4e5a8051ca --- /dev/null +++ b/cmake/combine_archives.cmake @@ -0,0 +1,30 @@ +function(combine_archives output_archive) + set(FULL_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib${output_archive}.a) + set(output_archive_dummy_file ${CMAKE_CURRENT_BINARY_DIR}/${output_archive}.dummy.cpp) + add_custom_command(OUTPUT ${output_archive_dummy_file} + COMMAND touch ${output_archive_dummy_file} + DEPENDS ${ARGN}) + add_library(${output_archive} STATIC EXCLUDE_FROM_ALL ${output_archive_dummy_file}) + + if(NOT APPLE) + set(mri_file ${CMAKE_CURRENT_BINARY_DIR}/${output_archive}.mri) + set(mri_content "create ${FULL_OUTPUT_PATH}\n") + foreach(in_archive ${ARGN}) + string(APPEND mri_content "addlib $\n") + endforeach() + string(APPEND mri_content "save\nend\n") + file(GENERATE OUTPUT ${mri_file} CONTENT "${mri_content}") + + add_custom_command(TARGET ${output_archive} + POST_BUILD + COMMAND ar -M < ${mri_file}) + else() + set(merge_libs) + foreach(in_archive ${ARGN}) + list(APPEND merge_libs $) + endforeach() + add_custom_command(TARGET ${output_archive} + POST_BUILD + COMMAND /usr/bin/libtool -static -o ${FULL_OUTPUT_PATH} ${merge_libs}) + endif() +endfunction(combine_archives) diff --git a/contrib/ios.sh b/contrib/ios.sh index 331599afcd..ce96a26e17 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -11,12 +11,13 @@ fi mkdir -p build/iphone cmake \ -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE=./contrib/cross/ios.toolchain.cmake -DPLATFORM=OS -DDEPLOYMENT_TARGET=13 -DENABLE_VISIBILITY=ON -DENABLE_BITCODE=OFF \ -DCMAKE_CXX_COMPILER_LAUNCHER= -DCMAKE_C_COMPILER_LAUNCHER= \ -DBUILD_STATIC_DEPS=ON \ -DBUILD_PACKAGE=OFF \ -DBUILD_SHARED_LIBS=OFF \ -DBUILD_TESTING=OFF \ - -DBUILD_LIBLOKINET=ON \ + -DBUILD_EMBEDDED_LOKINET=ON \ -DWITH_TESTS=OFF \ -DNATIVE_BUILD=OFF \ -DSTATIC_LINK=ON \ @@ -26,10 +27,10 @@ cmake \ -DFORCE_OXENMQ_SUBMODULE=ON \ -DFORCE_OXENC_SUBMODULE=ON \ -DFORCE_NLOHMANN_SUBMODULE=ON \ + -DFORCE_LIBUV_SUBMODULE=ON \ -DSUBMODULE_CHECK=ON \ -DWITH_LTO=OFF \ -S . -B build/iphone \ - $@ \ - -DCMAKE_TOOLCHAIN_FILE=contrib/cross/ios.toolchain.cmake + $@ -cmake --build build/iphone --target lokinet-shared +cmake --build build/iphone --target lokinet-embedded diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 083d6bfb6c..82876bbe1f 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -47,7 +47,7 @@ set(NTRU_AVX_SRC include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-mavx2 COMPILER_SUPPORTS_AVX2) check_cxx_compiler_flag(-mfma COMPILER_SUPPORTS_FMA) -if(COMPILER_SUPPORTS_AVX2 AND COMPILER_SUPPORTS_FMA AND (NOT ANDROID)) +if(COMPILER_SUPPORTS_AVX2 AND COMPILER_SUPPORTS_FMA AND WITH_AVX2) target_sources(lokinet-cryptography PRIVATE ${NTRU_AVX_SRC}) set_property(SOURCE ${NTRU_AVX_SRC} APPEND PROPERTY COMPILE_FLAGS "-mavx2 -mfma") message(STATUS "Building libntrup with runtime AVX2/FMA support") diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index b851ff9868..36226d2004 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -55,6 +55,7 @@ system_or_submodule(OXENC oxenc liboxenc>=1.0.3 oxen-encoding) system_or_submodule(OXENMQ oxenmq liboxenmq>=1.2.12 oxen-mq) set(JSON_BuildTests OFF CACHE INTERNAL "") system_or_submodule(NLOHMANN nlohmann_json nlohmann_json>=3.7.0 nlohmann) +system_or_submodule(LIBUV uv libuv libuv) # TODO: select better version if(WITH_HIVE) @@ -75,7 +76,7 @@ target_link_libraries(sqlite_orm INTERFACE sqlite3) add_library(uvw INTERFACE) target_include_directories(uvw INTERFACE uvw/src) -target_link_libraries(uvw INTERFACE libuv) +target_link_libraries(uvw INTERFACE uv::uv) # ngtcp2 needs some massaging to build nicely: include(ngtcp2_lib) diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index d7a7034156..a84ffe1b28 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -263,12 +263,26 @@ if(BUILD_LIBLOKINET) install(TARGETS lokinet-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT liblokinet) endif() add_log_tag(lokinet-shared) - if(CMAKE_GENERATOR MATCHES "Xcode") - option(CODE_SIGN_IDENT "for codesign magic on ios" "iPhone Developer") - option(DEV_TEAM_ID "for codesign magic on ios" "SUQ8J2PCT7") - set_property (TARGET lokinet-shared PROPERTY XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CODE_SIGN_IDENT}) - set_property (TARGET lokinet-shared PROPERTY XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${DEV_TEAM_ID}) - endif() +endif() + +if(BUILD_EMBEDDED_LOKINET) + add_library(lokinet-embedded-api STATIC lokinet_shared.cpp) + target_link_libraries(lokinet-embedded-api PUBLIC liblokinet) + add_log_tag(lokinet-embedded-api) + combine_archives(lokinet-embedded + lokinet-embedded-api + lokinet-platform lokinet-util lokinet-cryptography sqlite3 ngtcp2_static + liblokinet + sodium + zlib + OpenSSL::SSL OpenSSL::Crypto + expat + libunbound + libzmq + oxenmq) + install(TARGETS + ARCHIVE DESTINATION ${lib_folder} + EXCLUDE_FROM_ALL) endif() From 02d4f78902a3ca1e9660650b5903845263c3f29c Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 16:48:16 -0400 Subject: [PATCH 13/33] cleanups --- CMakeLists.txt | 15 --------------- llarp/CMakeLists.txt | 4 ---- 2 files changed, 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe144d6a74..36b9992e09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -312,21 +312,6 @@ if(ANDROID) add_subdirectory(jni) endif() - - -if(CMAKE_GENERATOR MATCHES "Xcode") - if(NOT CODE_SIGN_IDENT) - set(CODE_SIGN_IDENT "iPhone Developer") - endif() - if(NOT DEV_TEAM_ID) - set(DEV_TEAM_ID "SUQ8J2PCT7") - endif() - message(STATUS "code sign with: ${CODE_SIGN_IDENT} using dev id: ${DEV_TEAM_ID}") - set_property (TARGET lokinet-shared PROPERTY XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CODE_SIGN_IDENT}) - set_property (TARGET lokinet-shared PROPERTY XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${DEV_TEAM_ID}) -endif() - - add_subdirectory(docs) # uninstall target diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index a84ffe1b28..87b7ac32f3 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -280,10 +280,6 @@ if(BUILD_EMBEDDED_LOKINET) libunbound libzmq oxenmq) - install(TARGETS - ARCHIVE DESTINATION ${lib_folder} - EXCLUDE_FROM_ALL) - endif() if(APPLE) From a7930579d478884adfe2aea301febdb7d984d70c Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 16:51:56 -0400 Subject: [PATCH 14/33] add iphone to ci --- .drone.jsonnet | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.drone.jsonnet b/.drone.jsonnet index 87aaf71ff1..a367d16373 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -279,6 +279,35 @@ local mac_builder(name, ], }; +// iphone builder +local iphone_builder(name, + build_type='Release', + werror=true, + cmake_extra='', + extra_cmds=[], + jobs=6, + allow_fail=false) = { + kind: 'pipeline', + type: 'exec', + name: name, + platform: { os: 'darwin', arch: 'amd64' }, + steps: [ + { name: 'submodules', commands: submodule_commands }, + { + name: 'build', + environment: { SSH_KEY: { from_secret: 'SSH_KEY' } }, + commands: [ + 'echo "Building on ${DRONE_STAGE_MACHINE}"', + // If you don't do this then the C compiler doesn't have an include path containing + // basic system headers. WTF apple: + 'export SDKROOT="$(xcrun --sdk iphoneos --show-sdk-path)"', + 'ulimit -n 1024', // because macos sets ulimit to 256 for some reason yeah idk + './contrib/ios.sh ' + ci_mirror_opts, + ] + extra_cmds, + }, + ], +}; + local docs_pipeline(name, image, extra_cmds=[], allow_fail=false) = { kind: 'pipeline', type: 'docker', @@ -405,4 +434,6 @@ local docs_pipeline(name, image, extra_cmds=[], allow_fail=false) = { // Macos builds: mac_builder('macOS (Release)'), mac_builder('macOS (Debug)', build_type='Debug'), + // iphone builds: + iphone_builder('iOS (embedded lokinet)', build_type='Debug'), ] From e5496a16204b5f2c56a95dac101c981afaf68e2c Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 17:11:15 -0400 Subject: [PATCH 15/33] all the stuff for the ci pipeline, probably --- .drone.jsonnet | 5 ++++- contrib/ci/drone-static-upload.sh | 4 ++++ contrib/ios.sh | 34 ++++++++++++++++++++++++++++--- llarp/CMakeLists.txt | 9 ++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index a367d16373..7b69dc9c11 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -301,6 +301,7 @@ local iphone_builder(name, // If you don't do this then the C compiler doesn't have an include path containing // basic system headers. WTF apple: 'export SDKROOT="$(xcrun --sdk iphoneos --show-sdk-path)"', + 'export CMAKE_BUILD_PARALLEL_LEVEL=6', 'ulimit -n 1024', // because macos sets ulimit to 256 for some reason yeah idk './contrib/ios.sh ' + ci_mirror_opts, ] + extra_cmds, @@ -435,5 +436,7 @@ local docs_pipeline(name, image, extra_cmds=[], allow_fail=false) = { mac_builder('macOS (Release)'), mac_builder('macOS (Debug)', build_type='Debug'), // iphone builds: - iphone_builder('iOS (embedded lokinet)', build_type='Debug'), + iphone_builder('iOS (embedded lokinet)', build_type='Debug', extra_cmds=[ + 'UPLOAD_OS=iphone ./contrib/ci/drone-static-upload.sh' + ]), ] diff --git a/contrib/ci/drone-static-upload.sh b/contrib/ci/drone-static-upload.sh index 9449ff6dd9..313021a5f2 100755 --- a/contrib/ci/drone-static-upload.sh +++ b/contrib/ci/drone-static-upload.sh @@ -47,6 +47,10 @@ elif [ -e build-docs ]; then archive="$base.tar.xz" cp -av build-docs/docs/mkdocs.yml build-docs/docs/markdown "$base" tar cJvf "$archive" "$base" +elif [ -e build/iphone/ ]; then + archive="$base.tar.xz" + cp -av build/iphone/ "$base" + tar cJvf "$archive" "$base" else cp -av daemon/lokinet daemon/lokinet-vpn "$base" cp -av ../contrib/bootstrap/mainnet.signed "$base/bootstrap.signed" diff --git a/contrib/ios.sh b/contrib/ios.sh index ce96a26e17..76d2e8a497 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -8,7 +8,9 @@ if ! [ -f LICENSE ] || ! [ -d llarp ]; then echo "You need to run this as ./contrib/ios.sh from the top-level lokinet project directory" fi -mkdir -p build/iphone + +mkdir -p build/iphone/{sim,device} + cmake \ -G Ninja \ -DCMAKE_TOOLCHAIN_FILE=./contrib/cross/ios.toolchain.cmake -DPLATFORM=OS -DDEPLOYMENT_TARGET=13 -DENABLE_VISIBILITY=ON -DENABLE_BITCODE=OFF \ @@ -30,7 +32,33 @@ cmake \ -DFORCE_LIBUV_SUBMODULE=ON \ -DSUBMODULE_CHECK=ON \ -DWITH_LTO=OFF \ - -S . -B build/iphone \ + -S . -B build/iphone/device \ + $@ + +cmake \ + -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE=./contrib/cross/ios.toolchain.cmake -DPLATFORM=SIMULATOR64 -DDEPLOYMENT_TARGET=13 -DENABLE_VISIBILITY=ON -DENABLE_BITCODE=OFF \ + -DCMAKE_CXX_COMPILER_LAUNCHER= -DCMAKE_C_COMPILER_LAUNCHER= \ + -DBUILD_STATIC_DEPS=ON \ + -DBUILD_PACKAGE=OFF \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_TESTING=OFF \ + -DBUILD_EMBEDDED_LOKINET=ON \ + -DWITH_TESTS=OFF \ + -DNATIVE_BUILD=OFF \ + -DSTATIC_LINK=ON \ + -DWITH_SYSTEMD=OFF \ + -DWITH_BOOTSTRAP=OFF \ + -DBUILD_DAEMON=OFF \ + -DFORCE_OXENMQ_SUBMODULE=ON \ + -DFORCE_OXENC_SUBMODULE=ON \ + -DFORCE_NLOHMANN_SUBMODULE=ON \ + -DFORCE_LIBUV_SUBMODULE=ON \ + -DSUBMODULE_CHECK=ON \ + -DWITH_LTO=OFF \ + -S . -B build/iphone/sim \ $@ -cmake --build build/iphone --target lokinet-embedded +for targ in device sim ; do + cmake --build build/iphone/$targ --target lokinet-embedded +done diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index 87b7ac32f3..c426efd07d 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -273,6 +273,7 @@ if(BUILD_EMBEDDED_LOKINET) lokinet-embedded-api lokinet-platform lokinet-util lokinet-cryptography sqlite3 ngtcp2_static liblokinet + uv::uv sodium zlib OpenSSL::SSL OpenSSL::Crypto @@ -280,6 +281,14 @@ if(BUILD_EMBEDDED_LOKINET) libunbound libzmq oxenmq) + if(IOS) + set(lib_folder lib-${ARCH}) + else() + set(lib_folder lib) + endif() + install(TARGETS lokinet-embedded + ARCHIVE DESTINATION ${lib_folder} + EXCLUDE_FROM_ALL) endif() if(APPLE) From e343417241c69d7735919d51ba94eb5a387d9d96 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 17:14:46 -0400 Subject: [PATCH 16/33] squashme --- contrib/android-configure.sh | 4 +++- contrib/windows.sh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/contrib/android-configure.sh b/contrib/android-configure.sh index 2130b07cf2..80ba046051 100755 --- a/contrib/android-configure.sh +++ b/contrib/android-configure.sh @@ -37,7 +37,9 @@ for abi in $build_abis; do -DWITH_SYSTEMD=OFF \ -DFORCE_OXENMQ_SUBMODULE=ON \ -DFORCE_OXENC_SUBMODULE=ON \ - -DSUBMODULE_CHECK=OFF \ + -DFORCE_NLOHMANN_SUBMODULE=ON \ + -DFORCE_LIBUV_SUBMODULE=ON \ + -DSUBMODULE_CHECK=ON \ -DWITH_LTO=OFF \ -DCMAKE_BUILD_TYPE=Release \ $@ $root diff --git a/contrib/windows.sh b/contrib/windows.sh index 7520936e9e..e4fa53b18f 100755 --- a/contrib/windows.sh +++ b/contrib/windows.sh @@ -24,7 +24,9 @@ cmake \ -DWITH_SYSTEMD=OFF \ -DFORCE_OXENMQ_SUBMODULE=ON \ -DFORCE_OXENC_SUBMODULE=ON \ - -DSUBMODULE_CHECK=OFF \ + -DFORCE_NLOHMANN_SUBMODULE=ON \ + -DFORCE_LIBUV_SUBMODULE=ON \ + -DSUBMODULE_CHECK=ON \ -DWITH_LTO=OFF \ -DCMAKE_BUILD_TYPE=Release \ $@ .. From 0c5563002032c632d87acff10a5693a9d097eb49 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 17:15:41 -0400 Subject: [PATCH 17/33] squashme --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 36b9992e09..c578b85685 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ endif() # Core options -option(USE_AVX2 "enable avx2 code" ON) +option(USE_AVX2 "enable avx2 code" OFF) option(USE_NETNS "enable networking namespace support. Linux only" OFF) option(NATIVE_BUILD "optimise for host system and FPU" ON) option(EMBEDDED_CFG "optimise for older hardware or embedded systems" OFF) From aee729689fafd435a243d58d8bb35cfe5de475a2 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 17:16:57 -0400 Subject: [PATCH 18/33] format --- .drone.jsonnet | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 7b69dc9c11..91610b453f 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -281,12 +281,12 @@ local mac_builder(name, // iphone builder local iphone_builder(name, - build_type='Release', - werror=true, - cmake_extra='', - extra_cmds=[], - jobs=6, - allow_fail=false) = { + build_type='Release', + werror=true, + cmake_extra='', + extra_cmds=[], + jobs=6, + allow_fail=false) = { kind: 'pipeline', type: 'exec', name: name, @@ -437,6 +437,6 @@ local docs_pipeline(name, image, extra_cmds=[], allow_fail=false) = { mac_builder('macOS (Debug)', build_type='Debug'), // iphone builds: iphone_builder('iOS (embedded lokinet)', build_type='Debug', extra_cmds=[ - 'UPLOAD_OS=iphone ./contrib/ci/drone-static-upload.sh' + 'UPLOAD_OS=iphone ./contrib/ci/drone-static-upload.sh', ]), ] From 8d5ae3847750499fc9abaa851f9c59c382f19791 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 17:19:36 -0400 Subject: [PATCH 19/33] WITH_ to USE_ --- crypto/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 82876bbe1f..837a4a4901 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -47,7 +47,7 @@ set(NTRU_AVX_SRC include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-mavx2 COMPILER_SUPPORTS_AVX2) check_cxx_compiler_flag(-mfma COMPILER_SUPPORTS_FMA) -if(COMPILER_SUPPORTS_AVX2 AND COMPILER_SUPPORTS_FMA AND WITH_AVX2) +if(COMPILER_SUPPORTS_AVX2 AND COMPILER_SUPPORTS_FMA AND USE_AVX2) target_sources(lokinet-cryptography PRIVATE ${NTRU_AVX_SRC}) set_property(SOURCE ${NTRU_AVX_SRC} APPEND PROPERTY COMPILE_FLAGS "-mavx2 -mfma") message(STATUS "Building libntrup with runtime AVX2/FMA support") From 9af52aff109136729cd2db4653c83d580c74825f Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 17:22:02 -0400 Subject: [PATCH 20/33] squashme --- crypto/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 837a4a4901..f6718f3f7d 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -47,7 +47,7 @@ set(NTRU_AVX_SRC include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-mavx2 COMPILER_SUPPORTS_AVX2) check_cxx_compiler_flag(-mfma COMPILER_SUPPORTS_FMA) -if(COMPILER_SUPPORTS_AVX2 AND COMPILER_SUPPORTS_FMA AND USE_AVX2) +if(COMPILER_SUPPORTS_AVX2 AND COMPILER_SUPPORTS_FMA AND (NOT (ANDROID OR IOS))) target_sources(lokinet-cryptography PRIVATE ${NTRU_AVX_SRC}) set_property(SOURCE ${NTRU_AVX_SRC} APPEND PROPERTY COMPILE_FLAGS "-mavx2 -mfma") message(STATUS "Building libntrup with runtime AVX2/FMA support") From acf8a07dec5cc9749689dc1640bd0ef6f8904e49 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 17:23:30 -0400 Subject: [PATCH 21/33] submodule --- external/libuv | 1 + 1 file changed, 1 insertion(+) create mode 160000 external/libuv diff --git a/external/libuv b/external/libuv new file mode 160000 index 0000000000..8bcd689c04 --- /dev/null +++ b/external/libuv @@ -0,0 +1 @@ +Subproject commit 8bcd689c048af5aab26842ac5ff903fa3192d57c From a770bd52766b996b43215689977ee143c7ebbb76 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 17:26:47 -0400 Subject: [PATCH 22/33] fix up cross.sh --- contrib/cross.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/cross.sh b/contrib/cross.sh index 0b7d66328e..2e29ba66a4 100755 --- a/contrib/cross.sh +++ b/contrib/cross.sh @@ -25,7 +25,10 @@ cmake_opts="-DBUILD_STATIC_DEPS=ON \ -DSTATIC_LINK=ON \ -DWITH_SYSTEMD=OFF \ -DFORCE_OXENMQ_SUBMODULE=ON \ - -DSUBMODULE_CHECK=OFF \ + -DFORCE_OXENC_SUBMODULE=ON \ + -DFORCE_NLOHMANN_SUBMODULE=ON \ + -DFORCE_LIBUV_SUBMODULE=ON \ + -DSUBMODULE_CHECK=ON \ -DWITH_LTO=OFF \ -DWITH_BOOTSTRAP=OFF \ -DCMAKE_BUILD_TYPE=RelWithDeb" From 075dc79ea956baacf7b5b6ce4999a69a187647db Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 17:30:22 -0400 Subject: [PATCH 23/33] check libuv submodule --- external/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 36226d2004..ef2c28540b 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -23,6 +23,7 @@ if(SUBMODULE_CHECK) check_submodule(sqlite_orm) check_submodule(oxen-mq) check_submodule(oxen-encoding) + check_submodule(libuv) check_submodule(uvw) check_submodule(cpr) check_submodule(ngtcp2) From 7ff96789fd63e6c6ceac9b848aa380e845a63f01 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 17:36:57 -0400 Subject: [PATCH 24/33] build ios first --- .drone.jsonnet | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 91610b453f..65fc46ebb5 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -432,11 +432,11 @@ local docs_pipeline(name, image, extra_cmds=[], allow_fail=false) = { deb_builder(docker_base + 'ubuntu-jammy-builder', 'jammy', 'ubuntu/jammy'), deb_builder(docker_base + 'debian-sid-builder', 'sid', 'debian/sid', arch='arm64'), - // Macos builds: - mac_builder('macOS (Release)'), - mac_builder('macOS (Debug)', build_type='Debug'), // iphone builds: iphone_builder('iOS (embedded lokinet)', build_type='Debug', extra_cmds=[ 'UPLOAD_OS=iphone ./contrib/ci/drone-static-upload.sh', ]), + // Macos builds: + mac_builder('macOS (Release)'), + mac_builder('macOS (Debug)', build_type='Debug'), ] From 239d0ecfb35cc648bee4b61195526b26af55c191 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 17:46:44 -0400 Subject: [PATCH 25/33] only pack liblokinet-embedded.a in iphone ci pipeline --- contrib/ci/drone-static-upload.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/ci/drone-static-upload.sh b/contrib/ci/drone-static-upload.sh index 313021a5f2..9267ce136a 100755 --- a/contrib/ci/drone-static-upload.sh +++ b/contrib/ci/drone-static-upload.sh @@ -49,7 +49,10 @@ elif [ -e build-docs ]; then tar cJvf "$archive" "$base" elif [ -e build/iphone/ ]; then archive="$base.tar.xz" - cp -av build/iphone/ "$base" + mkdir -p "$base/sim" + mkdir -p "$base/device" + cp -av build/iphone/sim/llarp/liblokinet-embedded.a "$base/sim/liblokinet-embedded.a" + cp -av build/iphone/device/llarp/liblokinet-embedded.a "$base/device/liblokinet-embedded.a" tar cJvf "$archive" "$base" else cp -av daemon/lokinet daemon/lokinet-vpn "$base" From 89b499d66a30aec6ba713797f5739f85e4b425df Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 17:58:51 -0400 Subject: [PATCH 26/33] use uv static build when using submodule --- external/CMakeLists.txt | 4 ++-- llarp/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index ef2c28540b..0377d8786f 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -56,7 +56,7 @@ system_or_submodule(OXENC oxenc liboxenc>=1.0.3 oxen-encoding) system_or_submodule(OXENMQ oxenmq liboxenmq>=1.2.12 oxen-mq) set(JSON_BuildTests OFF CACHE INTERNAL "") system_or_submodule(NLOHMANN nlohmann_json nlohmann_json>=3.7.0 nlohmann) -system_or_submodule(LIBUV uv libuv libuv) # TODO: select better version +system_or_submodule(LIBUV uv_a libuv libuv) # TODO: select better version if(WITH_HIVE) @@ -77,7 +77,7 @@ target_link_libraries(sqlite_orm INTERFACE sqlite3) add_library(uvw INTERFACE) target_include_directories(uvw INTERFACE uvw/src) -target_link_libraries(uvw INTERFACE uv::uv) +target_link_libraries(uvw INTERFACE uv_a::uv_a) # ngtcp2 needs some massaging to build nicely: include(ngtcp2_lib) diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index c426efd07d..389550615d 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -273,7 +273,7 @@ if(BUILD_EMBEDDED_LOKINET) lokinet-embedded-api lokinet-platform lokinet-util lokinet-cryptography sqlite3 ngtcp2_static liblokinet - uv::uv + uv_a::uv_a sodium zlib OpenSSL::SSL OpenSSL::Crypto From 505173937c87c0901bc6f66651b9bc9334ace85b Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 15 Jun 2022 20:59:27 -0400 Subject: [PATCH 27/33] move logic out of ci into ios builder script --- .drone.jsonnet | 3 --- contrib/ios.sh | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 65fc46ebb5..29972c0641 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -298,9 +298,6 @@ local iphone_builder(name, environment: { SSH_KEY: { from_secret: 'SSH_KEY' } }, commands: [ 'echo "Building on ${DRONE_STAGE_MACHINE}"', - // If you don't do this then the C compiler doesn't have an include path containing - // basic system headers. WTF apple: - 'export SDKROOT="$(xcrun --sdk iphoneos --show-sdk-path)"', 'export CMAKE_BUILD_PARALLEL_LEVEL=6', 'ulimit -n 1024', // because macos sets ulimit to 256 for some reason yeah idk './contrib/ios.sh ' + ci_mirror_opts, diff --git a/contrib/ios.sh b/contrib/ios.sh index 76d2e8a497..8b6ce69ed6 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -8,6 +8,8 @@ if ! [ -f LICENSE ] || ! [ -d llarp ]; then echo "You need to run this as ./contrib/ios.sh from the top-level lokinet project directory" fi +unset SDKROOT +export SDKROOT="$(xcrun --sdk iphoneos --show-sdk-path)" mkdir -p build/iphone/{sim,device} From 7c978ccf141b5edef44264b7396ea12876b19ed1 Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 16 Jun 2022 07:32:02 -0400 Subject: [PATCH 28/33] restructure build for iphone --- contrib/ci/drone-static-upload.sh | 6 +-- contrib/ios.sh | 73 +++++++++---------------------- contrib/ios/ios-build.sh | 7 +++ contrib/ios/ios-configure.sh | 39 +++++++++++++++++ contrib/ios/readme.txt | 6 +-- 5 files changed, 70 insertions(+), 61 deletions(-) create mode 100755 contrib/ios/ios-build.sh create mode 100755 contrib/ios/ios-configure.sh diff --git a/contrib/ci/drone-static-upload.sh b/contrib/ci/drone-static-upload.sh index 9267ce136a..432dc97b00 100755 --- a/contrib/ci/drone-static-upload.sh +++ b/contrib/ci/drone-static-upload.sh @@ -49,11 +49,7 @@ elif [ -e build-docs ]; then tar cJvf "$archive" "$base" elif [ -e build/iphone/ ]; then archive="$base.tar.xz" - mkdir -p "$base/sim" - mkdir -p "$base/device" - cp -av build/iphone/sim/llarp/liblokinet-embedded.a "$base/sim/liblokinet-embedded.a" - cp -av build/iphone/device/llarp/liblokinet-embedded.a "$base/device/liblokinet-embedded.a" - tar cJvf "$archive" "$base" + mv build/iphone/*.tar.xz "$archive" else cp -av daemon/lokinet daemon/lokinet-vpn "$base" cp -av ../contrib/bootstrap/mainnet.signed "$base/bootstrap.signed" diff --git a/contrib/ios.sh b/contrib/ios.sh index 8b6ce69ed6..61e85a58da 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -8,59 +8,28 @@ if ! [ -f LICENSE ] || ! [ -d llarp ]; then echo "You need to run this as ./contrib/ios.sh from the top-level lokinet project directory" fi -unset SDKROOT -export SDKROOT="$(xcrun --sdk iphoneos --show-sdk-path)" -mkdir -p build/iphone/{sim,device} +root="$(readlink -f $(dirname $0)/../)" -cmake \ - -G Ninja \ - -DCMAKE_TOOLCHAIN_FILE=./contrib/cross/ios.toolchain.cmake -DPLATFORM=OS -DDEPLOYMENT_TARGET=13 -DENABLE_VISIBILITY=ON -DENABLE_BITCODE=OFF \ - -DCMAKE_CXX_COMPILER_LAUNCHER= -DCMAKE_C_COMPILER_LAUNCHER= \ - -DBUILD_STATIC_DEPS=ON \ - -DBUILD_PACKAGE=OFF \ - -DBUILD_SHARED_LIBS=OFF \ - -DBUILD_TESTING=OFF \ - -DBUILD_EMBEDDED_LOKINET=ON \ - -DWITH_TESTS=OFF \ - -DNATIVE_BUILD=OFF \ - -DSTATIC_LINK=ON \ - -DWITH_SYSTEMD=OFF \ - -DWITH_BOOTSTRAP=OFF \ - -DBUILD_DAEMON=OFF \ - -DFORCE_OXENMQ_SUBMODULE=ON \ - -DFORCE_OXENC_SUBMODULE=ON \ - -DFORCE_NLOHMANN_SUBMODULE=ON \ - -DFORCE_LIBUV_SUBMODULE=ON \ - -DSUBMODULE_CHECK=ON \ - -DWITH_LTO=OFF \ - -S . -B build/iphone/device \ - $@ +build_dir="$root/build/iphone" -cmake \ - -G Ninja \ - -DCMAKE_TOOLCHAIN_FILE=./contrib/cross/ios.toolchain.cmake -DPLATFORM=SIMULATOR64 -DDEPLOYMENT_TARGET=13 -DENABLE_VISIBILITY=ON -DENABLE_BITCODE=OFF \ - -DCMAKE_CXX_COMPILER_LAUNCHER= -DCMAKE_C_COMPILER_LAUNCHER= \ - -DBUILD_STATIC_DEPS=ON \ - -DBUILD_PACKAGE=OFF \ - -DBUILD_SHARED_LIBS=OFF \ - -DBUILD_TESTING=OFF \ - -DBUILD_EMBEDDED_LOKINET=ON \ - -DWITH_TESTS=OFF \ - -DNATIVE_BUILD=OFF \ - -DSTATIC_LINK=ON \ - -DWITH_SYSTEMD=OFF \ - -DWITH_BOOTSTRAP=OFF \ - -DBUILD_DAEMON=OFF \ - -DFORCE_OXENMQ_SUBMODULE=ON \ - -DFORCE_OXENC_SUBMODULE=ON \ - -DFORCE_NLOHMANN_SUBMODULE=ON \ - -DFORCE_LIBUV_SUBMODULE=ON \ - -DSUBMODULE_CHECK=ON \ - -DWITH_LTO=OFF \ - -S . -B build/iphone/sim \ - $@ +./contrib/ios/ios-configure.sh "$build_dir/device" OS $@ +./contrib/ios/ios-configure.sh "$build_dir/sim" SIMULATORARM64 $@ -for targ in device sim ; do - cmake --build build/iphone/$targ --target lokinet-embedded -done +./contrib/ios/ios-build.sh "$build_dir/device" +./contrib/ios/ios-build.sh "$build_dir/sim" + +pkg_name="iphone_lokinet_embedded_$(date +%s)" +pkg_dir="$build_dir/$pkg_name" +mkdir -p "$pkg_dir/include" +mkdir -p "$pkg_dir/lib/device" +mkdir -p "$pkg_dir/lib/sim" + +cp -a "$build_dir/device/llarp/liblokinet-embedded.a" "$pkg_dir/lib/device/" +cp -a "$build_dir/sim/llarp/liblokinet-embedded.a" "$pkg_dir/lib/sim/" +cp -a "$root"/include/lokinet{,/*}.h "$pkg_dir/include/" + +cd "$build_dir" +tar cfv "$pkg_name.tar" $pkg_name +cd - +xz -T 0 "$build_dir/$pkg_name.tar" diff --git a/contrib/ios/ios-build.sh b/contrib/ios/ios-build.sh new file mode 100755 index 0000000000..feeb5c3e36 --- /dev/null +++ b/contrib/ios/ios-build.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# +# Build the shit for iphone + +test -e $1 || ( echo "run ios-configure.sh first" ; exit 1 ) + +cmake --build $1 --target lokinet-embedded diff --git a/contrib/ios/ios-configure.sh b/contrib/ios/ios-configure.sh new file mode 100755 index 0000000000..c176d115c1 --- /dev/null +++ b/contrib/ios/ios-configure.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# +# configure step for ios + +root="$(readlink -f $(dirname $0)/../../)" + +unset SDKROOT +export SDKROOT="$(xcrun --sdk iphoneos --show-sdk-path)" + +targ=$1 +plat=$2 +shift +shift + +mkdir -p $targ + +cmake \ + -G Ninja \ + -DCMAKE_TOOLCHAIN_FILE=./contrib/cross/ios.toolchain.cmake -DPLATFORM=$plat -DDEPLOYMENT_TARGET=13 -DENABLE_VISIBILITY=ON -DENABLE_BITCODE=OFF \ + -DCMAKE_CXX_COMPILER_LAUNCHER= -DCMAKE_C_COMPILER_LAUNCHER= \ + -DBUILD_STATIC_DEPS=ON \ + -DBUILD_PACKAGE=OFF \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_TESTING=OFF \ + -DBUILD_EMBEDDED_LOKINET=ON \ + -DWITH_TESTS=OFF \ + -DNATIVE_BUILD=OFF \ + -DSTATIC_LINK=ON \ + -DWITH_SYSTEMD=OFF \ + -DWITH_BOOTSTRAP=OFF \ + -DBUILD_DAEMON=OFF \ + -DFORCE_OXENMQ_SUBMODULE=ON \ + -DFORCE_OXENC_SUBMODULE=ON \ + -DFORCE_NLOHMANN_SUBMODULE=ON \ + -DFORCE_LIBUV_SUBMODULE=ON \ + -DSUBMODULE_CHECK=ON \ + -DWITH_LTO=OFF \ + -S $root -B $targ \ + $@ diff --git a/contrib/ios/readme.txt b/contrib/ios/readme.txt index 88ab3187bc..98e32894dd 100644 --- a/contrib/ios/readme.txt +++ b/contrib/ios/readme.txt @@ -1,12 +1,10 @@ -the internet is gripped by a spectre, the spectre of developing for the apple iphone. our scientists have yet to reverse engineer the correct way to use the apple build process as dictated on the official apple documentation so we have a made a hack to make it work until that occurs. - the build process for embedded lokinet on iphone is as follows: * obtain holy water, sprinkle onto keyboard and single button trackpad accordingly. * run ./contrib/ios.sh -* after it runs and the proper number of goats have been offered to the slaughter you will get a static object archive somewhere in ./build/iphone/ +* after it runs and the proper number of goats have been offered to the slaughter you will get an xz's tarball in the build/iphone/ directory additional cmake flags can be passed to ./contrib/ios.sh as command line arguments like so: - $ ./contrib/ios.sh -DPLATFORM=SIMULATOR64 + $ ./contrib/ios.sh -DYOLO_SWAG=ON From e0b978e47827031c93b69f767647743fcf0a1f6e Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 16 Jun 2022 08:48:04 -0400 Subject: [PATCH 29/33] fix typos --- contrib/ios.sh | 2 +- contrib/ios/ios-configure.sh | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/contrib/ios.sh b/contrib/ios.sh index 61e85a58da..789921e0f8 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -14,7 +14,7 @@ root="$(readlink -f $(dirname $0)/../)" build_dir="$root/build/iphone" ./contrib/ios/ios-configure.sh "$build_dir/device" OS $@ -./contrib/ios/ios-configure.sh "$build_dir/sim" SIMULATORARM64 $@ +./contrib/ios/ios-configure.sh "$build_dir/sim" SIMULATOR64 $@ ./contrib/ios/ios-build.sh "$build_dir/device" ./contrib/ios/ios-build.sh "$build_dir/sim" diff --git a/contrib/ios/ios-configure.sh b/contrib/ios/ios-configure.sh index c176d115c1..56a94095bb 100755 --- a/contrib/ios/ios-configure.sh +++ b/contrib/ios/ios-configure.sh @@ -2,7 +2,9 @@ # # configure step for ios -root="$(readlink -f $(dirname $0)/../../)" +set -x + +root=$(readlink -f "$( dirname $0 )/../../") unset SDKROOT export SDKROOT="$(xcrun --sdk iphoneos --show-sdk-path)" @@ -16,7 +18,7 @@ mkdir -p $targ cmake \ -G Ninja \ - -DCMAKE_TOOLCHAIN_FILE=./contrib/cross/ios.toolchain.cmake -DPLATFORM=$plat -DDEPLOYMENT_TARGET=13 -DENABLE_VISIBILITY=ON -DENABLE_BITCODE=OFF \ + -DCMAKE_TOOLCHAIN_FILE="$root/contrib/cross/ios.toolchain.cmake" -DPLATFORM=$plat -DDEPLOYMENT_TARGET=13 -DENABLE_VISIBILITY=ON -DENABLE_BITCODE=OFF \ -DCMAKE_CXX_COMPILER_LAUNCHER= -DCMAKE_C_COMPILER_LAUNCHER= \ -DBUILD_STATIC_DEPS=ON \ -DBUILD_PACKAGE=OFF \ @@ -35,5 +37,5 @@ cmake \ -DFORCE_LIBUV_SUBMODULE=ON \ -DSUBMODULE_CHECK=ON \ -DWITH_LTO=OFF \ - -S $root -B $targ \ + -S "$root" -B $targ \ $@ From d00a60ed0c2a19d552fbd4be590b4655be290601 Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 16 Jun 2022 11:15:23 -0400 Subject: [PATCH 30/33] clean up static deps for cross targets --- cmake/StaticBuild.cmake | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake index 6e575b7e8d..168bdc5320 100644 --- a/cmake/StaticBuild.cmake +++ b/cmake/StaticBuild.cmake @@ -54,7 +54,7 @@ set(ZLIB_MIRROR ${LOCAL_MIRROR} https://zlib.net set(ZLIB_SOURCE zlib-${ZLIB_VERSION}.tar.gz) set(ZLIB_HASH SHA256=91844808532e5ce316b3c010929493c0244f3d37593afd6de04f71821d5136d9 CACHE STRING "zlib source hash") - + set(CURL_VERSION 7.83.1 CACHE STRING "curl version") set(CURL_MIRROR ${LOCAL_MIRROR} https://curl.haxx.se/download https://curl.askapache.com CACHE STRING "curl mirror(s)") @@ -217,7 +217,7 @@ function(build_external target) BUILD_BYPRODUCTS ${arg_BUILD_BYPRODUCTS} ) endfunction() - + build_external(zlib CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env "CC=${deps_cc}" "CFLAGS=${deps_CFLAGS} -fPIC" ${cross_extra} ./configure --prefix=${DEPS_DESTDIR} --static BUILD_BYPRODUCTS @@ -244,7 +244,7 @@ if(CMAKE_CROSSCOMPILING) message(FATAL_ERROR "didn't find your toolchain and sdk correctly from ${CMAKE_C_COMPILER}/${CMAKE_OSX_SYSROOT}: found toolchain=${apple_toolchain}, sdk=${apple_sdk}") endif() set(openssl_system_env CROSS_COMPILE=${apple_toolchain} CROSS_TOP=${CMAKE_DEVELOPER_ROOT} CROSS_SDK=${apple_sdk}) - set(openssl_configure ./Configure iphoneos-cross) + set(openssl_configure_command ./Configure iphoneos-cross) set(openssl_cc "clang") elseif(ARCH_TRIPLET STREQUAL mips64-linux-gnuabi64) set(openssl_system_env SYSTEM=Linux MACHINE=mips64) @@ -268,35 +268,10 @@ elseif(CMAKE_C_FLAGS MATCHES "-march=armv7") set(openssl_system_env SYSTEM=Linux MACHINE=armv7) endif() - - -set(openssl_configure ./config) -set(openssl_system_env "") -set(openssl_cc "${deps_cc}") -if(CMAKE_CROSSCOMPILING) - if(ARCH_TRIPLET STREQUAL x86_64-w64-mingw32) - set(openssl_system_env SYSTEM=MINGW64 RC=${CMAKE_RC_COMPILER}) - elseif(ARCH_TRIPLET STREQUAL i686-w64-mingw32) - set(openssl_system_env SYSTEM=MINGW64 RC=${CMAKE_RC_COMPILER}) - elseif(ANDROID) - set(openssl_system_env SYSTEM=Linux MACHINE=${openssl_machine} ${cross_rc}) - set(openssl_extra_opts no-asm) - elseif(IOS) - get_filename_component(apple_toolchain "${CMAKE_C_COMPILER}" DIRECTORY) - get_filename_component(apple_sdk "${CMAKE_OSX_SYSROOT}" NAME) - if(NOT ${apple_toolchain} MATCHES Xcode OR NOT ${apple_sdk} MATCHES "iPhone(OS|Simulator)") - message(FATAL_ERROR "didn't find your toolchain and sdk correctly from ${CMAKE_C_COMPILER}/${CMAKE_OSX_SYSROOT}: found toolchain=${apple_toolchain}, sdk=${apple_sdk}") - endif() - set(openssl_system_env CROSS_COMPILE=${apple_toolchain}/ CROSS_TOP=${CMAKE_DEVELOPER_ROOT} CROSS_SDK=${apple_sdk}) - set(openssl_configure ./Configure iphoneos-cross) - set(openssl_cc "clang") - endif() -endif() - build_external(openssl - CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env CC=${openssl_cc} ${openssl_system_env} ${openssl_configure} + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env CC=${openssl_cc} ${openssl_system_env} ${openssl_configure_command} --prefix=${DEPS_DESTDIR} ${openssl_extra_opts} no-shared no-capieng no-dso no-dtls1 no-ec_nistp_64_gcc_128 no-gost - no-heartbeats no-md2 no-rc5 no-rdrand no-rfc3779 no-sctp no-ssl-trace no-ssl2 no-ssl3 no-engine + no-heartbeats no-md2 no-rc5 no-rdrand no-rfc3779 no-sctp no-ssl-trace no-ssl2 no-ssl3 no-static-engine no-tests no-weak-ssl-ciphers no-zlib-dynamic "CFLAGS=${deps_CFLAGS}" INSTALL_COMMAND ${_make} install_sw BUILD_BYPRODUCTS @@ -323,7 +298,7 @@ add_static_target(expat expat_external libexpat.a) set(unbound_extra) if(APPLE AND IOS) - set(unbound_extra CPP=cpp) + set(unbound_extra CPP=cpp) endif() build_external(unbound From 8b831371b861f5c174655194870c0dc90680729d Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 6 Jul 2022 17:06:09 -0400 Subject: [PATCH 31/33] fix up compiler flags and make shit smaller --- CMakeLists.txt | 29 +++++++++++++++-------------- cmake/StaticBuild.cmake | 2 +- contrib/ios.sh | 17 +++++++++-------- contrib/ios/ios-configure.sh | 3 ++- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c578b85685..e2700ec23b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,23 +211,24 @@ if(APPLE) message(STATUS "IOS: Changing arch from x86_64 to x86-64") add_compile_options(-march=x86-64) endif() -else() - if(NATIVE_BUILD) - if(CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le) - add_compile_options(-mcpu=native -mtune=native) - else() - add_compile_options(-march=native -mtune=native) - endif() - elseif(NOT NON_PC_TARGET) - if (USE_AVX2) - add_compile_options(-march=haswell -mtune=haswell -mfpmath=sse) - else() - # Public binary releases - add_compile_options(-march=nocona -mtune=haswell -mfpmath=sse) - endif() +endif() + +if(NATIVE_BUILD) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le) + add_compile_options(-mcpu=native -mtune=native) + else() + add_compile_options(-march=native -mtune=native) + endif() +elseif(NOT NON_PC_TARGET) + if (USE_AVX2) + add_compile_options(-march=haswell -mtune=haswell -mfpmath=sse) + else() + # Public binary releases + add_compile_options(-march=nocona -mtune=haswell -mfpmath=sse) endif() endif() + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake index 168bdc5320..7a871e2968 100644 --- a/cmake/StaticBuild.cmake +++ b/cmake/StaticBuild.cmake @@ -243,7 +243,7 @@ if(CMAKE_CROSSCOMPILING) if(NOT ${apple_toolchain} MATCHES Xcode OR NOT ${apple_sdk} MATCHES "iPhone(OS|Simulator)") message(FATAL_ERROR "didn't find your toolchain and sdk correctly from ${CMAKE_C_COMPILER}/${CMAKE_OSX_SYSROOT}: found toolchain=${apple_toolchain}, sdk=${apple_sdk}") endif() - set(openssl_system_env CROSS_COMPILE=${apple_toolchain} CROSS_TOP=${CMAKE_DEVELOPER_ROOT} CROSS_SDK=${apple_sdk}) + set(openssl_system_env CROSS_COMPILE=${apple_toolchain}/ CROSS_TOP=${CMAKE_DEVELOPER_ROOT}/ CROSS_SDK=${apple_sdk}/) set(openssl_configure_command ./Configure iphoneos-cross) set(openssl_cc "clang") elseif(ARCH_TRIPLET STREQUAL mips64-linux-gnuabi64) diff --git a/contrib/ios.sh b/contrib/ios.sh index 789921e0f8..7e532f53eb 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -13,20 +13,21 @@ root="$(readlink -f $(dirname $0)/../)" build_dir="$root/build/iphone" -./contrib/ios/ios-configure.sh "$build_dir/device" OS $@ +./contrib/ios/ios-configure.sh "$build_dir/device" OS64 $@ ./contrib/ios/ios-configure.sh "$build_dir/sim" SIMULATOR64 $@ -./contrib/ios/ios-build.sh "$build_dir/device" -./contrib/ios/ios-build.sh "$build_dir/sim" +for targ in device sim ; do + ./contrib/ios/ios-build.sh "$build_dir/$targ" +done pkg_name="iphone_lokinet_embedded_$(date +%s)" pkg_dir="$build_dir/$pkg_name" -mkdir -p "$pkg_dir/include" -mkdir -p "$pkg_dir/lib/device" -mkdir -p "$pkg_dir/lib/sim" -cp -a "$build_dir/device/llarp/liblokinet-embedded.a" "$pkg_dir/lib/device/" -cp -a "$build_dir/sim/llarp/liblokinet-embedded.a" "$pkg_dir/lib/sim/" +mkdir -p "$pkg_dir"/{include,lib/{device,sim}} +for targ in device sim ; do + mkdir -p "$pkg_dir/lib/$targ" + cp -av "$build_dir/$targ/llarp/liblokinet-embedded.a" "$pkg_dir/lib/$targ/liblokinet-embedded.a" +done cp -a "$root"/include/lokinet{,/*}.h "$pkg_dir/include/" cd "$build_dir" diff --git a/contrib/ios/ios-configure.sh b/contrib/ios/ios-configure.sh index 56a94095bb..f994d3a572 100755 --- a/contrib/ios/ios-configure.sh +++ b/contrib/ios/ios-configure.sh @@ -19,7 +19,6 @@ mkdir -p $targ cmake \ -G Ninja \ -DCMAKE_TOOLCHAIN_FILE="$root/contrib/cross/ios.toolchain.cmake" -DPLATFORM=$plat -DDEPLOYMENT_TARGET=13 -DENABLE_VISIBILITY=ON -DENABLE_BITCODE=OFF \ - -DCMAKE_CXX_COMPILER_LAUNCHER= -DCMAKE_C_COMPILER_LAUNCHER= \ -DBUILD_STATIC_DEPS=ON \ -DBUILD_PACKAGE=OFF \ -DBUILD_SHARED_LIBS=OFF \ @@ -37,5 +36,7 @@ cmake \ -DFORCE_LIBUV_SUBMODULE=ON \ -DSUBMODULE_CHECK=ON \ -DWITH_LTO=OFF \ + -DCMAKE_CXX_FLAGS='-Oz' -DCMAKE_C_FLAGS='-Oz' \ + -DCMAKE_BUILD_TYPE=Release \ -S "$root" -B $targ \ $@ From 65d3c0ea3ae2ad9557e14576704270b1cff72e47 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 22 Jun 2022 10:33:45 -0400 Subject: [PATCH 32/33] fall back to null vpn platform when we have no implementation for the current target --- llarp/vpn/null.hpp | 96 ++++++++++++++++++++++++++++++++++++++++++ llarp/vpn/platform.cpp | 26 ++++-------- 2 files changed, 105 insertions(+), 17 deletions(-) create mode 100644 llarp/vpn/null.hpp diff --git a/llarp/vpn/null.hpp b/llarp/vpn/null.hpp new file mode 100644 index 0000000000..c247b99e9f --- /dev/null +++ b/llarp/vpn/null.hpp @@ -0,0 +1,96 @@ +#pragma once +#include +#include + +namespace llarp::vpn +{ + class NullInterface : public NetworkInterface + { + /// we use a pipe because it isnt going to poll itself + int m_pipe[2]; + + public: + NullInterface() + { + ::pipe(m_pipe); + } + + virtual ~NullInterface() + { + ::close(m_pipe[1]); + ::close(m_pipe[0]); + } + + int + PollFD() const override + { + return m_pipe[0]; + } + + /// the interface's name + std::string + IfName() const override + { + return ""; + } + + net::IPPacket + ReadNextPacket() override + { + return net::IPPacket{}; + } + + /// write a packet to the interface + /// returns false if we dropped it + bool WritePacket(net::IPPacket) override + { + return true; + } + }; + + class NopRouteManager : public IRouteManager + { + public: + void AddRoute(IPVariant_t, IPVariant_t) override{}; + + void DelRoute(IPVariant_t, IPVariant_t) override{}; + + void AddDefaultRouteViaInterface(std::string) override{}; + + void DelDefaultRouteViaInterface(std::string) override{}; + + void + AddRouteViaInterface(NetworkInterface&, IPRange) override{}; + + void + DelRouteViaInterface(NetworkInterface&, IPRange) override{}; + + std::vector GetGatewaysNotOnInterface(std::string) override + { + return {}; + } + }; + + class NullPlatform : public Platform + { + NopRouteManager _routes; + + public: + NullPlatform() : Platform{}, _routes{} + {} + + virtual ~NullPlatform() = default; + + std::shared_ptr + ObtainInterface(InterfaceInfo, AbstractRouter*) + { + return std::static_pointer_cast(std::make_shared()); + } + + IRouteManager& + RouteManager() override + { + return _routes; + } + }; +} // namespace llarp::vpn diff --git a/llarp/vpn/platform.cpp b/llarp/vpn/platform.cpp index 341e28fcba..b09586034b 100644 --- a/llarp/vpn/platform.cpp +++ b/llarp/vpn/platform.cpp @@ -1,6 +1,5 @@ -#include - +#include #ifdef _WIN32 #include "win32.hpp" #endif @@ -12,27 +11,20 @@ #endif #endif -#include - namespace llarp::vpn { std::shared_ptr MakeNativePlatform(llarp::Context* ctx) { (void)ctx; - std::shared_ptr plat; -#ifdef _WIN32 - plat = std::make_shared(); -#endif -#ifdef __linux__ -#ifdef ANDROID - plat = std::make_shared(ctx); -#else - plat = std::make_shared(); -#endif -#endif -#ifdef __APPLE__ - throw std::runtime_error{"not supported"}; + auto nullplat = std::make_shared(); + std::shared_ptr plat = nullplat; +#if defined(_WIN32) + plat = std::make_shared(); +#elif defined(ANDROID) + plat = std::make_shared(ctx); +#elif defined(__linux__) + plat = std::make_shared(); #endif return plat; } From 8a905db1cf1cfb81e9754f2991994e4dcaa2ccc1 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Fri, 8 Jul 2022 08:52:09 +1000 Subject: [PATCH 33/33] Updated the ios.sh to create fat libraries and generate a .xcframework --- .gitmodules | 3 + cmake/StaticBuild.cmake | 5 + contrib/cross/ios.toolchain.cmake | 728 ------------------------------ contrib/ios.sh | 69 ++- contrib/ios/ios-configure.sh | 2 +- external/ios-cmake | 1 + 6 files changed, 69 insertions(+), 739 deletions(-) delete mode 100644 contrib/cross/ios.toolchain.cmake create mode 160000 external/ios-cmake diff --git a/.gitmodules b/.gitmodules index 23ec941b04..56afbcada7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -39,3 +39,6 @@ [submodule "external/libuv"] path = external/libuv url = https://github.com/libuv/libuv +[submodule "external/ios-cmake"] + path = external/ios-cmake + url = https://github.com/leetal/ios-cmake diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake index 7a871e2968..cf736f275b 100644 --- a/cmake/StaticBuild.cmake +++ b/cmake/StaticBuild.cmake @@ -103,6 +103,11 @@ set(cross_rc "") if(CMAKE_CROSSCOMPILING) if(APPLE_TARGET_TRIPLE) + if(PLATFORM MATCHES "OS64" OR PLATFORM MATCHES "SIMULATORARM64") + set(APPLE_TARGET_TRIPLE aarch64-apple-ios) + elseif(PLATFORM MATCHES "SIMULATOR64") + set(APPLE_TARGET_TRIPLE x86_64-apple-ios) + endif() set(cross_host "--host=${APPLE_TARGET_TRIPLE}") else() set(cross_host "--host=${ARCH_TRIPLET}") diff --git a/contrib/cross/ios.toolchain.cmake b/contrib/cross/ios.toolchain.cmake deleted file mode 100644 index 644832062c..0000000000 --- a/contrib/cross/ios.toolchain.cmake +++ /dev/null @@ -1,728 +0,0 @@ -# This file downloaded from https://github.com/leetal/ios-cmake; it -# contained this header regarding the source works' licences: -# -# This file is part of the ios-cmake project. It was retrieved from -# https://github.com/cristeab/ios-cmake.git, which is a fork of -# https://code.google.com/p/ios-cmake/. Which in turn is based off of -# the Platform/Darwin.cmake and Platform/UnixPaths.cmake files which -# are included with CMake 2.8.4 -# -# The ios-cmake project is licensed under the new BSD license. -# -# Copyright (c) 2014, Bogdan Cristea and LTE Engineering Software, -# Kitware, Inc., Insight Software Consortium. All rights reserved. -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -# 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. -# -# Updated by Alex Stewart (alexs.mac@gmail.com) -# -# ***************************************************************************** -# Now maintained by Alexander Widerberg (widerbergaren [at] gmail.com) -# under the BSD-3-Clause license -# https://github.com/leetal/ios-cmake -# ***************************************************************************** -# -# INFORMATION / HELP -# -# The following arguments control the behaviour of this toolchain: -# -# PLATFORM: (default "OS") -# OS = Build for iPhoneOS. -# OS64 = Build for arm64 iphoneOS. -# OS64COMBINED = Build for arm64 x86_64 iphoneOS. Combined into FAT STATIC lib (supported on 3.14+ of CMakewith "-G Xcode" argument ONLY) -# SIMULATOR = Build for x86 i386 iphoneOS Simulator. -# SIMULATOR64 = Build for x86_64 iphoneOS Simulator. -# TVOS = Build for arm64 tvOS. -# TVOSCOMBINED = Build for arm64 x86_64 tvOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY) -# SIMULATOR_TVOS = Build for x86_64 tvOS Simulator. -# WATCHOS = Build for armv7k arm64_32 for watchOS. -# WATCHOSCOMBINED = Build for armv7k arm64_32 x86_64 watchOS. Combined into FAT STATIC lib (supported on 3.14+ of CMake with "-G Xcode" argument ONLY) -# SIMULATOR_WATCHOS = Build for x86_64 for watchOS Simulator. -# -# CMAKE_OSX_SYSROOT: Path to the SDK to use. By default this is -# automatically determined from PLATFORM and xcodebuild, but -# can also be manually specified (although this should not be required). -# -# CMAKE_DEVELOPER_ROOT: Path to the Developer directory for the platform -# being compiled for. By default this is automatically determined from -# CMAKE_OSX_SYSROOT, but can also be manually specified (although this should -# not be required). -# -# DEPLOYMENT_TARGET: Minimum SDK version to target. Default 2.0 on watchOS and 9.0 on tvOS+iOS -# -# ENABLE_BITCODE: (1|0) Enables or disables bitcode support. Default 1 (true) -# -# ENABLE_ARC: (1|0) Enables or disables ARC support. Default 1 (true, ARC enabled by default) -# -# ENABLE_VISIBILITY: (1|0) Enables or disables symbol visibility support. Default 0 (false, visibility hidden by default) -# -# ENABLE_STRICT_TRY_COMPILE: (1|0) Enables or disables strict try_compile() on all Check* directives (will run linker -# to actually check if linking is possible). Default 0 (false, will set CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY) -# -# ARCHS: (armv7 armv7s armv7k arm64 arm64_32 i386 x86_64) If specified, will override the default architectures for the given PLATFORM -# OS = armv7 armv7s arm64 (if applicable) -# OS64 = arm64 (if applicable) -# SIMULATOR = i386 -# SIMULATOR64 = x86_64 -# TVOS = arm64 -# SIMULATOR_TVOS = x86_64 (i386 has since long been deprecated) -# WATCHOS = armv7k arm64_32 (if applicable) -# SIMULATOR_WATCHOS = x86_64 (i386 has since long been deprecated) -# -# This toolchain defines the following variables for use externally: -# -# XCODE_VERSION: Version number (not including Build version) of Xcode detected. -# SDK_VERSION: Version of SDK being used. -# CMAKE_OSX_ARCHITECTURES: Architectures being compiled for (generated from PLATFORM). -# APPLE_TARGET_TRIPLE: Used by autoconf build systems. NOTE: If "ARCHS" are overridden, this will *NOT* be set! -# -# This toolchain defines the following macros for use externally: -# -# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE XCODE_VARIANT) -# A convenience macro for setting xcode specific properties on targets. -# Available variants are: All, Release, RelWithDebInfo, Debug, MinSizeRel -# example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1" "all"). -# -# find_host_package (PROGRAM ARGS) -# A macro used to find executable programs on the host system, not within the -# environment. Thanks to the android-cmake project for providing the -# command. -# -# ******************************** DEPRECATIONS ******************************* -# -# IOS_DEPLOYMENT_TARGET: (Deprecated) Alias to DEPLOYMENT_TARGET -# CMAKE_IOS_DEVELOPER_ROOT: (Deprecated) Alias to CMAKE_DEVELOPER_ROOT -# IOS_PLATFORM: (Deprecated) Alias to PLATFORM -# IOS_ARCH: (Deprecated) Alias to ARCHS -# -# ***************************************************************************** -# - -# Fix for PThread library not in path -set(CMAKE_THREAD_LIBS_INIT "-lpthread") -set(CMAKE_HAVE_THREADS_LIBRARY 1) -set(CMAKE_USE_WIN32_THREADS_INIT 0) -set(CMAKE_USE_PTHREADS_INIT 1) - -# Cache what generator is used -set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE) - -if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14") - set(MODERN_CMAKE YES) -endif() - -# Get the Xcode version being used. -execute_process(COMMAND xcodebuild -version - OUTPUT_VARIABLE XCODE_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) -string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}") -string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}") - -######## ALIASES (DEPRECATION WARNINGS) - -if(DEFINED IOS_PLATFORM) - set(PLATFORM ${IOS_PLATFORM}) - message(DEPRECATION "IOS_PLATFORM argument is DEPRECATED. Consider using the new PLATFORM argument instead.") -endif() - -if(DEFINED IOS_DEPLOYMENT_TARGET) - set(DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET}) - message(DEPRECATION "IOS_DEPLOYMENT_TARGET argument is DEPRECATED. Consider using the new DEPLOYMENT_TARGET argument instead.") -endif() - -if(DEFINED CMAKE_IOS_DEVELOPER_ROOT) - set(CMAKE_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT}) - message(DEPRECATION "CMAKE_IOS_DEVELOPER_ROOT argument is DEPRECATED. Consider using the new CMAKE_DEVELOPER_ROOT argument instead.") -endif() - -if(DEFINED IOS_ARCH) - set(ARCHS ${IOS_ARCH}) - message(DEPRECATION "IOS_ARCH argument is DEPRECATED. Consider using the new ARCHS argument instead.") -endif() - -######## END ALIASES - -# Unset the FORCE on cache variables if in try_compile() -set(FORCE_CACHE FORCE) -get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE) -if(_CMAKE_IN_TRY_COMPILE) - unset(FORCE_CACHE) -endif() - -# Default to building for iPhoneOS if not specified otherwise, and we cannot -# determine the platform from the CMAKE_OSX_ARCHITECTURES variable. The use -# of CMAKE_OSX_ARCHITECTURES is such that try_compile() projects can correctly -# determine the value of PLATFORM from the root project, as -# CMAKE_OSX_ARCHITECTURES is propagated to them by CMake. -if(NOT DEFINED PLATFORM) - if (CMAKE_OSX_ARCHITECTURES) - if(CMAKE_OSX_ARCHITECTURES MATCHES ".*arm.*" AND CMAKE_OSX_SYSROOT MATCHES ".*iphoneos.*") - set(PLATFORM "OS") - elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*") - set(PLATFORM "SIMULATOR") - elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*iphonesimulator.*") - set(PLATFORM "SIMULATOR64") - elseif(CMAKE_OSX_ARCHITECTURES MATCHES "arm64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvos.*") - set(PLATFORM "TVOS") - elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" AND CMAKE_OSX_SYSROOT MATCHES ".*appletvsimulator.*") - set(PLATFORM "SIMULATOR_TVOS") - elseif(CMAKE_OSX_ARCHITECTURES MATCHES ".*armv7k.*" AND CMAKE_OSX_SYSROOT MATCHES ".*watchos.*") - set(PLATFORM "WATCHOS") - elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386" AND CMAKE_OSX_SYSROOT MATCHES ".*watchsimulator.*") - set(PLATFORM "SIMULATOR_WATCHOS") - endif() - endif() - if (NOT PLATFORM) - set(PLATFORM "OS") - endif() -endif() - -set(PLATFORM_INT "${PLATFORM}" CACHE STRING "Type of platform for which the build targets.") - -# Handle the case where we are targeting iOS and a version above 10.3.4 (32-bit support dropped officially) -if(PLATFORM_INT STREQUAL "OS" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4) - set(PLATFORM_INT "OS64") - message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.") -elseif(PLATFORM_INT STREQUAL "SIMULATOR" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4) - set(PLATFORM_INT "SIMULATOR64") - message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.") -endif() - -# Determine the platform name and architectures for use in xcodebuild commands -# from the specified PLATFORM name. -if(PLATFORM_INT STREQUAL "OS") - set(SDK_NAME iphoneos) - if(NOT ARCHS) - set(ARCHS armv7 armv7s arm64) - set(APPLE_TARGET_TRIPLE_INT arm-apple-ios) - endif() -elseif(PLATFORM_INT STREQUAL "OS64") - set(SDK_NAME iphoneos) - if(NOT ARCHS) - if (XCODE_VERSION VERSION_GREATER 10.0) - set(ARCHS arm64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example - else() - set(ARCHS arm64) - endif() - set(APPLE_TARGET_TRIPLE_INT aarch64-apple-ios) - endif() -elseif(PLATFORM_INT STREQUAL "OS64COMBINED") - set(SDK_NAME iphoneos) - if(MODERN_CMAKE) - if(NOT ARCHS) - if (XCODE_VERSION VERSION_GREATER 10.0) - set(ARCHS arm64 x86_64) # Add arm64e when Apple have fixed the integration issues with it, libarclite_iphoneos.a is currently missung bitcode markers for example - else() - set(ARCHS arm64 x86_64) - endif() - set(APPLE_TARGET_TRIPLE_INT aarch64-x86_64-apple-ios) - endif() - else() - message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the OS64COMBINED setting work") - endif() -elseif(PLATFORM_INT STREQUAL "SIMULATOR") - set(SDK_NAME iphonesimulator) - if(NOT ARCHS) - set(ARCHS i386) - set(APPLE_TARGET_TRIPLE_INT i386-apple-ios) - endif() - message(DEPRECATION "SIMULATOR IS DEPRECATED. Consider using SIMULATOR64 instead.") -elseif(PLATFORM_INT STREQUAL "SIMULATOR64") - set(SDK_NAME iphonesimulator) - if(NOT ARCHS) - set(ARCHS x86_64) - set(APPLE_TARGET_TRIPLE_INT x86_64-apple-ios) - endif() -elseif(PLATFORM_INT STREQUAL "TVOS") - set(SDK_NAME appletvos) - if(NOT ARCHS) - set(ARCHS arm64) - set(APPLE_TARGET_TRIPLE_INT aarch64-apple-tvos) - endif() -elseif (PLATFORM_INT STREQUAL "TVOSCOMBINED") - set(SDK_NAME appletvos) - if(MODERN_CMAKE) - if(NOT ARCHS) - set(ARCHS arm64 x86_64) - set(APPLE_TARGET_TRIPLE_INT aarch64-x86_64-apple-tvos) - endif() - else() - message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the TVOSCOMBINED setting work") - endif() -elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS") - set(SDK_NAME appletvsimulator) - if(NOT ARCHS) - set(ARCHS x86_64) - set(APPLE_TARGET_TRIPLE_INT x86_64-apple-tvos) - endif() -elseif(PLATFORM_INT STREQUAL "WATCHOS") - set(SDK_NAME watchos) - if(NOT ARCHS) - if (XCODE_VERSION VERSION_GREATER 10.0) - set(ARCHS armv7k arm64_32) - set(APPLE_TARGET_TRIPLE_INT aarch64_32-apple-watchos) - else() - set(ARCHS armv7k) - set(APPLE_TARGET_TRIPLE_INT arm-apple-watchos) - endif() - endif() -elseif(PLATFORM_INT STREQUAL "WATCHOSCOMBINED") - set(SDK_NAME watchos) - if(MODERN_CMAKE) - if(NOT ARCHS) - if (XCODE_VERSION VERSION_GREATER 10.0) - set(ARCHS armv7k arm64_32 i386) - set(APPLE_TARGET_TRIPLE_INT aarch64_32-i386-apple-watchos) - else() - set(ARCHS armv7k i386) - set(APPLE_TARGET_TRIPLE_INT arm-i386-apple-watchos) - endif() - endif() - else() - message(FATAL_ERROR "Please make sure that you are running CMake 3.14+ to make the WATCHOSCOMBINED setting work") - endif() -elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") - set(SDK_NAME watchsimulator) - if(NOT ARCHS) - set(ARCHS i386) - set(APPLE_TARGET_TRIPLE_INT i386-apple-watchos) - endif() -else() - message(FATAL_ERROR "Invalid PLATFORM: ${PLATFORM_INT}") -endif() - -if(MODERN_CMAKE AND PLATFORM_INT MATCHES ".*COMBINED" AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode") - message(FATAL_ERROR "The COMBINED options only work with Xcode generator, -G Xcode") -endif() - -# If user did not specify the SDK root to use, then query xcodebuild for it. -execute_process(COMMAND xcodebuild -version -sdk ${SDK_NAME} Path - OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_INT - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) -if (NOT DEFINED CMAKE_OSX_SYSROOT_INT AND NOT DEFINED CMAKE_OSX_SYSROOT) - message(SEND_ERROR "Please make sure that Xcode is installed and that the toolchain" - "is pointing to the correct path. Please run:" - "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer" - "and see if that fixes the problem for you.") - message(FATAL_ERROR "Invalid CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT} " - "does not exist.") -elseif(DEFINED CMAKE_OSX_SYSROOT_INT) - set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT_INT}" CACHE INTERNAL "") -endif() - -# Set Xcode property for SDKROOT as well if Xcode generator is used -if(USED_CMAKE_GENERATOR MATCHES "Xcode") - set(CMAKE_OSX_SYSROOT "${SDK_NAME}" CACHE INTERNAL "") - if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM) - set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "123456789A" CACHE INTERNAL "") - endif() -endif() - -# Specify minimum version of deployment target. -if(NOT DEFINED DEPLOYMENT_TARGET) - if (PLATFORM_INT STREQUAL "WATCHOS" OR PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") - # Unless specified, SDK version 2.0 is used by default as minimum target version (watchOS). - set(DEPLOYMENT_TARGET "2.0" - CACHE STRING "Minimum SDK version to build for." ) - else() - # Unless specified, SDK version 9.0 is used by default as minimum target version (iOS, tvOS). - set(DEPLOYMENT_TARGET "9.0" - CACHE STRING "Minimum SDK version to build for." ) - endif() - message(STATUS "Using the default min-version since DEPLOYMENT_TARGET not provided!") -endif() - -# Use bitcode or not -if(NOT DEFINED ENABLE_BITCODE AND NOT ARCHS MATCHES "((^|;|, )(i386|x86_64))+") - # Unless specified, enable bitcode support by default - message(STATUS "Enabling bitcode support by default. ENABLE_BITCODE not provided!") - set(ENABLE_BITCODE TRUE) -elseif(NOT DEFINED ENABLE_BITCODE) - message(STATUS "Disabling bitcode support by default on simulators. ENABLE_BITCODE not provided for override!") - set(ENABLE_BITCODE FALSE) -endif() -set(ENABLE_BITCODE_INT ${ENABLE_BITCODE} CACHE BOOL "Whether or not to enable bitcode" ${FORCE_CACHE}) -# Use ARC or not -if(NOT DEFINED ENABLE_ARC) - # Unless specified, enable ARC support by default - set(ENABLE_ARC TRUE) - message(STATUS "Enabling ARC support by default. ENABLE_ARC not provided!") -endif() -set(ENABLE_ARC_INT ${ENABLE_ARC} CACHE BOOL "Whether or not to enable ARC" ${FORCE_CACHE}) -# Use hidden visibility or not -if(NOT DEFINED ENABLE_VISIBILITY) - # Unless specified, disable symbols visibility by default - set(ENABLE_VISIBILITY FALSE) - message(STATUS "Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!") -endif() -set(ENABLE_VISIBILITY_INT ${ENABLE_VISIBILITY} CACHE BOOL "Whether or not to hide symbols (-fvisibility=hidden)" ${FORCE_CACHE}) -# Set strict compiler checks or not -if(NOT DEFINED ENABLE_STRICT_TRY_COMPILE) - # Unless specified, disable strict try_compile() - set(ENABLE_STRICT_TRY_COMPILE FALSE) - message(STATUS "Using NON-strict compiler checks by default. ENABLE_STRICT_TRY_COMPILE not provided!") -endif() -set(ENABLE_STRICT_TRY_COMPILE_INT ${ENABLE_STRICT_TRY_COMPILE} CACHE BOOL "Whether or not to use strict compiler checks" ${FORCE_CACHE}) -# Get the SDK version information. -execute_process(COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion - OUTPUT_VARIABLE SDK_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - -# Find the Developer root for the specific iOS platform being compiled for -# from CMAKE_OSX_SYSROOT. Should be ../../ from SDK specified in -# CMAKE_OSX_SYSROOT. There does not appear to be a direct way to obtain -# this information from xcrun or xcodebuild. -if (NOT DEFINED CMAKE_DEVELOPER_ROOT AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode") - get_filename_component(PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT} PATH) - get_filename_component(CMAKE_DEVELOPER_ROOT ${PLATFORM_SDK_DIR} PATH) - if (NOT DEFINED CMAKE_DEVELOPER_ROOT) - message(FATAL_ERROR "Invalid CMAKE_DEVELOPER_ROOT: " - "${CMAKE_DEVELOPER_ROOT} does not exist.") - endif() -endif() -# Find the C & C++ compilers for the specified SDK. -if(NOT CMAKE_C_COMPILER) - execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang - OUTPUT_VARIABLE CMAKE_C_COMPILER - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}") -endif() -if(NOT CMAKE_CXX_COMPILER) - execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find clang++ - OUTPUT_VARIABLE CMAKE_CXX_COMPILER - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - message(STATUS "Using CXX compiler: ${CMAKE_CXX_COMPILER}") -endif() -# Find (Apple's) libtool. -execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find libtool - OUTPUT_VARIABLE BUILD_LIBTOOL - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) -message(STATUS "Using libtool: ${BUILD_LIBTOOL}") -# Configure libtool to be used instead of ar + ranlib to build static libraries. -# This is required on Xcode 7+, but should also work on previous versions of -# Xcode. -set(CMAKE_C_CREATE_STATIC_LIBRARY - "${BUILD_LIBTOOL} -static -o ") -set(CMAKE_CXX_CREATE_STATIC_LIBRARY - "${BUILD_LIBTOOL} -static -o ") -# Find the toolchain's provided install_name_tool if none is found on the host -if(NOT CMAKE_INSTALL_NAME_TOOL) - execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find install_name_tool - OUTPUT_VARIABLE CMAKE_INSTALL_NAME_TOOL_INT - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - set(CMAKE_INSTALL_NAME_TOOL ${CMAKE_INSTALL_NAME_TOOL_INT} CACHE STRING "" ${FORCE_CACHE}) -endif() -# Get the version of Darwin (OS X) of the host. -execute_process(COMMAND uname -r - OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) -if(SDK_NAME MATCHES "iphone") - set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" ${FORCE_CACHE}) -endif() -# CMake 3.14+ support building for iOS, watchOS and tvOS out of the box. -if(MODERN_CMAKE) - if(SDK_NAME MATCHES "appletv") - set(CMAKE_SYSTEM_NAME tvOS CACHE INTERNAL "" ${FORCE_CACHE}) - elseif(SDK_NAME MATCHES "watch") - set(CMAKE_SYSTEM_NAME watchOS CACHE INTERNAL "" ${FORCE_CACHE}) - endif() - # Provide flags for a combined FAT library build on newer CMake versions - if(PLATFORM_INT MATCHES ".*COMBINED") - set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "NO" CACHE INTERNAL "" ${FORCE_CACHE}) - set(CMAKE_IOS_INSTALL_COMBINED YES CACHE INTERNAL "" ${FORCE_CACHE}) - message(STATUS "Will combine built (static) artifacts into FAT lib...") - endif() -elseif(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.10") - # Legacy code path prior to CMake 3.14 or fallback if no SDK_NAME specified - set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" ${FORCE_CACHE}) -else() - # Legacy code path prior to CMake 3.14 or fallback if no SDK_NAME specified - set(CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL "" ${FORCE_CACHE}) -endif() -# Standard settings. -set(CMAKE_SYSTEM_VERSION ${SDK_VERSION} CACHE INTERNAL "") -set(UNIX TRUE CACHE BOOL "") -set(APPLE TRUE CACHE BOOL "") -set(IOS TRUE CACHE BOOL "") -set(CMAKE_AR ar CACHE FILEPATH "" FORCE) -set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE) -set(CMAKE_STRIP strip CACHE FILEPATH "" FORCE) -# Set the architectures for which to build. -set(CMAKE_OSX_ARCHITECTURES ${ARCHS} CACHE STRING "Build architecture for iOS") -# Change the type of target generated for try_compile() so it'll work when cross-compiling, weak compiler checks -if(ENABLE_STRICT_TRY_COMPILE_INT) - message(STATUS "Using strict compiler checks (default in CMake).") -else() - set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) -endif() -# All iOS/Darwin specific settings - some may be redundant. -set(CMAKE_MACOSX_BUNDLE YES) -set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO") -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_C_COMPILER_ABI ELF) -set(CMAKE_CXX_COMPILER_ABI ELF) -set(CMAKE_C_HAS_ISYSROOT 1) -set(CMAKE_CXX_HAS_ISYSROOT 1) -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}") - -if(ARCHS MATCHES "((^|;|, )(arm64|arm64e|x86_64))+") - set(CMAKE_C_SIZEOF_DATA_PTR 8) - set(CMAKE_CXX_SIZEOF_DATA_PTR 8) - if(ARCHS MATCHES "((^|;|, )(arm64|arm64e))+") - set(CMAKE_SYSTEM_PROCESSOR "aarch64") - else() - set(CMAKE_SYSTEM_PROCESSOR "x86_64") - endif() -else() - set(CMAKE_C_SIZEOF_DATA_PTR 4) - set(CMAKE_CXX_SIZEOF_DATA_PTR 4) - set(CMAKE_SYSTEM_PROCESSOR "arm") -endif() - -# Note that only Xcode 7+ supports the newer more specific: -# -m${SDK_NAME}-version-min flags, older versions of Xcode use: -# -m(ios/ios-simulator)-version-min instead. -if(${CMAKE_VERSION} VERSION_LESS "3.11") - if(PLATFORM_INT STREQUAL "OS" OR PLATFORM_INT STREQUAL "OS64") - if(XCODE_VERSION VERSION_LESS 7.0) - set(SDK_NAME_VERSION_FLAGS - "-mios-version-min=${DEPLOYMENT_TARGET}") - else() - # Xcode 7.0+ uses flags we can build directly from SDK_NAME. - set(SDK_NAME_VERSION_FLAGS - "-m${SDK_NAME}-version-min=${DEPLOYMENT_TARGET}") - endif() - elseif(PLATFORM_INT STREQUAL "TVOS") - set(SDK_NAME_VERSION_FLAGS - "-mtvos-version-min=${DEPLOYMENT_TARGET}") - elseif(PLATFORM_INT STREQUAL "SIMULATOR_TVOS") - set(SDK_NAME_VERSION_FLAGS - "-mtvos-simulator-version-min=${DEPLOYMENT_TARGET}") - elseif(PLATFORM_INT STREQUAL "WATCHOS") - set(SDK_NAME_VERSION_FLAGS - "-mwatchos-version-min=${DEPLOYMENT_TARGET}") - elseif(PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") - set(SDK_NAME_VERSION_FLAGS - "-mwatchos-simulator-version-min=${DEPLOYMENT_TARGET}") - else() - # SIMULATOR or SIMULATOR64 both use -mios-simulator-version-min. - set(SDK_NAME_VERSION_FLAGS - "-mios-simulator-version-min=${DEPLOYMENT_TARGET}") - endif() -else() - # Newer versions of CMake sets the version min flags correctly - set(CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} CACHE STRING - "Set CMake deployment target" ${FORCE_CACHE}) -endif() - -if(DEFINED APPLE_TARGET_TRIPLE_INT) - set(APPLE_TARGET_TRIPLE ${APPLE_TARGET_TRIPLE_INT} CACHE STRING - "Autoconf target triple compatible variable" ${FORCE_CACHE}) -endif() - -if(ENABLE_BITCODE_INT) - set(BITCODE "-fembed-bitcode") - set(CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE "bitcode" CACHE INTERNAL "") - set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES" CACHE INTERNAL "") -else() - set(BITCODE "") - set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO" CACHE INTERNAL "") -endif() - -if(ENABLE_ARC_INT) - set(FOBJC_ARC "-fobjc-arc") - set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES" CACHE INTERNAL "") -else() - set(FOBJC_ARC "-fno-objc-arc") - set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "NO" CACHE INTERNAL "") -endif() - -if(NOT ENABLE_VISIBILITY_INT) - set(VISIBILITY "-fvisibility=hidden") - set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "YES" CACHE INTERNAL "") -else() - set(VISIBILITY "") - set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "NO" CACHE INTERNAL "") -endif() - -if(NOT IOS_TOOLCHAIN_HAS_RUN) - #Check if Xcode generator is used, since that will handle these flags automagically - if(USED_CMAKE_GENERATOR MATCHES "Xcode") - message(STATUS "Not setting any manual command-line buildflags, since Xcode is selected as generator.") - else() - set(CMAKE_C_FLAGS - "${SDK_NAME_VERSION_FLAGS} ${BITCODE} -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_C_FLAGS}") - # Hidden visibilty is required for C++ on iOS. - set(CMAKE_CXX_FLAGS - "${SDK_NAME_VERSION_FLAGS} ${BITCODE} ${VISIBILITY} -fvisibility-inlines-hidden -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_CXX_FLAGS}") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g ${CMAKE_CXX_FLAGS_DEBUG}") - set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DNDEBUG -Os -ffast-math ${CMAKE_CXX_FLAGS_MINSIZEREL}") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG -O2 -g -ffast-math ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG -O3 -ffast-math ${CMAKE_CXX_FLAGS_RELEASE}") - set(CMAKE_C_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") - set(CMAKE_CXX_LINK_FLAGS "${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") - set(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp") - - # In order to ensure that the updated compiler flags are used in try_compile() - # tests, we have to forcibly set them in the CMake cache, not merely set them - # in the local scope. - set(VARS_TO_FORCE_IN_CACHE - CMAKE_C_FLAGS - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS_MINSIZEREL - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_LINK_FLAGS - CMAKE_CXX_LINK_FLAGS) - foreach(VAR_TO_FORCE ${VARS_TO_FORCE_IN_CACHE}) - set(${VAR_TO_FORCE} "${${VAR_TO_FORCE}}" CACHE STRING "" ${FORCE_CACHE}) - endforeach() - endif() - - ## Print status messages to inform of the current state - message(STATUS "Configuring ${SDK_NAME} build for platform: ${PLATFORM_INT}, architecture(s): ${ARCHS}") - message(STATUS "Using SDK: ${CMAKE_OSX_SYSROOT_INT}") - if(DEFINED APPLE_TARGET_TRIPLE) - message(STATUS "Autoconf target triple: ${APPLE_TARGET_TRIPLE}") - endif() - message(STATUS "Using minimum deployment version: ${DEPLOYMENT_TARGET}" - " (SDK version: ${SDK_VERSION})") - if(MODERN_CMAKE) - message(STATUS "Merging integrated CMake 3.14+ iOS,tvOS,watchOS,macOS toolchain(s) with this toolchain!") - endif() - if(USED_CMAKE_GENERATOR MATCHES "Xcode") - message(STATUS "Using Xcode version: ${XCODE_VERSION}") - endif() - if(DEFINED SDK_NAME_VERSION_FLAGS) - message(STATUS "Using version flags: ${SDK_NAME_VERSION_FLAGS}") - endif() - message(STATUS "Using a data_ptr size of: ${CMAKE_CXX_SIZEOF_DATA_PTR}") - message(STATUS "Using install_name_tool: ${CMAKE_INSTALL_NAME_TOOL}") - if(ENABLE_BITCODE_INT) - message(STATUS "Enabling bitcode support.") - else() - message(STATUS "Disabling bitcode support.") - endif() - - if(ENABLE_ARC_INT) - message(STATUS "Enabling ARC support.") - else() - message(STATUS "Disabling ARC support.") - endif() - - if(NOT ENABLE_VISIBILITY_INT) - message(STATUS "Hiding symbols (-fvisibility=hidden).") - endif() -endif() - -set(CMAKE_PLATFORM_HAS_INSTALLNAME 1) -set(CMAKE_SHARED_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks") -set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names") -set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -Wl,-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 ".tbd" ".dylib" ".so" ".a") -set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name") - -# Set the find root to the iOS developer roots and to user defined paths. -set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT_INT} ${CMAKE_PREFIX_PATH} CACHE STRING "Root path that will be prepended - to all search paths") -# Default to searching for frameworks first. -set(CMAKE_FIND_FRAMEWORK FIRST) -# Set up the default search directories for frameworks. -set(CMAKE_FRAMEWORK_PATH - ${CMAKE_DEVELOPER_ROOT}/Library/PrivateFrameworks - ${CMAKE_OSX_SYSROOT_INT}/System/Library/Frameworks - ${CMAKE_FRAMEWORK_PATH} CACHE STRING "Frameworks search paths" ${FORCE_CACHE}) - -set(IOS_TOOLCHAIN_HAS_RUN TRUE CACHE BOOL "Has the CMake toolchain run already?" ${FORCE_CACHE}) - -# By default, search both the specified iOS SDK and the remainder of the host filesystem. -if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH CACHE STRING "" ${FORCE_CACHE}) -endif() -if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH CACHE STRING "" ${FORCE_CACHE}) -endif() -if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) - set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH CACHE STRING "" ${FORCE_CACHE}) -endif() -if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) - set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH CACHE STRING "" ${FORCE_CACHE}) -endif() - -# -# Some helper-macros below to simplify and beautify the CMakeFile -# - -# This little macro lets you set any Xcode specific property. -macro(set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE XCODE_RELVERSION) - set(XCODE_RELVERSION_I "${XCODE_RELVERSION}") - if(XCODE_RELVERSION_I STREQUAL "All") - set_property(TARGET ${TARGET} PROPERTY - XCODE_ATTRIBUTE_${XCODE_PROPERTY} "${XCODE_VALUE}") - else() - set_property(TARGET ${TARGET} PROPERTY - XCODE_ATTRIBUTE_${XCODE_PROPERTY}[variant=${XCODE_RELVERSION_I}] "${XCODE_VALUE}") - endif() -endmacro(set_xcode_property) - -# This macro lets you find executable programs on the host system. -macro(find_host_package) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) - set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) - set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER) - set(IOS FALSE) - find_package(${ARGN}) - set(IOS TRUE) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) - set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) - set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) -endmacro(find_host_package) diff --git a/contrib/ios.sh b/contrib/ios.sh index 7e532f53eb..d3e24e8009 100755 --- a/contrib/ios.sh +++ b/contrib/ios.sh @@ -13,23 +13,72 @@ root="$(readlink -f $(dirname $0)/../)" build_dir="$root/build/iphone" -./contrib/ios/ios-configure.sh "$build_dir/device" OS64 $@ -./contrib/ios/ios-configure.sh "$build_dir/sim" SIMULATOR64 $@ +deviceArchs=(arm64) +devicePlat=(OS64) +simArchs=(arm64 x86_64) +simPlat=(SIMULATORARM64 SIMULATOR64) -for targ in device sim ; do - ./contrib/ios/ios-build.sh "$build_dir/$targ" +for i in "${!deviceArchs[@]}"; do + ./contrib/ios/ios-configure.sh "$build_dir/device/${deviceArchs[i]}" ${devicePlat[i]} $@ +done + +for i in "${!simArchs[@]}"; do + ./contrib/ios/ios-configure.sh "$build_dir/sim/${simArchs[i]}" ${simPlat[i]} $@ +done + +for targ in ${deviceArchs[@]} ; do + ./contrib/ios/ios-build.sh "$build_dir/device/$targ" +done + +for targ in ${simArchs[@]} ; do + ./contrib/ios/ios-build.sh "$build_dir/sim/$targ" done pkg_name="iphone_lokinet_embedded_$(date +%s)" pkg_dir="$build_dir/$pkg_name" -mkdir -p "$pkg_dir"/{include,lib/{device,sim}} -for targ in device sim ; do - mkdir -p "$pkg_dir/lib/$targ" - cp -av "$build_dir/$targ/llarp/liblokinet-embedded.a" "$pkg_dir/lib/$targ/liblokinet-embedded.a" -done -cp -a "$root"/include/lokinet{,/*}.h "$pkg_dir/include/" +# Combine and device/simulator libraries into a single file so XCode doesn't complain +function combineArchsIfNeeded() { + local group=$1 + local destination=$2 + shift; shift + local archs=("$@") + + if [ ${#archs[@]} -gt 1 ]; then + local dirs=("${archs[@]/#/$build_dir/${group}/}") + local libs=("${dirs[@]/%//llarp/liblokinet-embedded.a}") + + mkdir -p "$build_dir/$group/$destination/llarp" + lipo -create "${libs[@]}" -output "$build_dir/$group/${destination}/llarp/liblokinet-embedded.a" + fi +} + +deviceArchsString="${deviceArchs[*]}" +joinedDeviceArchs="${deviceArchsString// /_}" +simArchsString="${simArchs[*]}" +joinedSimArchs="${simArchsString// /_}" + +combineArchsIfNeeded "device" $joinedDeviceArchs ${deviceArchs[*]} +combineArchsIfNeeded "sim" $joinedSimArchs ${simArchs[*]} + +# Create a '.xcframework' so XCode can deal with the different architectures +xcodebuild -create-xcframework \ + -library "$build_dir/device/$joinedDeviceArchs/llarp/liblokinet-embedded.a" \ + -library "$build_dir/sim/$joinedSimArchs/llarp/liblokinet-embedded.a" \ + -output "$pkg_dir/libLokinet.xcframework" + +# Copy the headers over +mkdir -p "$pkg_dir/libLokinet.xcframework/lokinet" +cp -a "$root"/include/lokinet{,/*}.h "$pkg_dir/libLokinet.xcframework/lokinet" +mv "$pkg_dir/libLokinet.xcframework/lokinet/lokinet.h" "$pkg_dir/libLokinet.xcframework/lokinet.h" + +# The 'module.modulemap' is needed for XCode to be able to find the headers +echo -e 'module Lokinet {' > "$pkg_dir/libLokinet.xcframework/module.modulemap" +echo -e ' umbrella header "lokinet.h"' >> "$pkg_dir/libLokinet.xcframework/module.modulemap" +echo -e ' export *' >> "$pkg_dir/libLokinet.xcframework/module.modulemap" +echo -e '}' >> "$pkg_dir/libLokinet.xcframework/module.modulemap" +# Archive the result cd "$build_dir" tar cfv "$pkg_name.tar" $pkg_name cd - diff --git a/contrib/ios/ios-configure.sh b/contrib/ios/ios-configure.sh index f994d3a572..342431aa53 100755 --- a/contrib/ios/ios-configure.sh +++ b/contrib/ios/ios-configure.sh @@ -18,7 +18,7 @@ mkdir -p $targ cmake \ -G Ninja \ - -DCMAKE_TOOLCHAIN_FILE="$root/contrib/cross/ios.toolchain.cmake" -DPLATFORM=$plat -DDEPLOYMENT_TARGET=13 -DENABLE_VISIBILITY=ON -DENABLE_BITCODE=OFF \ + -DCMAKE_TOOLCHAIN_FILE="$root/external/ios-cmake/ios.toolchain.cmake" -DPLATFORM=$plat -DDEPLOYMENT_TARGET=13 -DENABLE_VISIBILITY=ON -DENABLE_BITCODE=OFF \ -DBUILD_STATIC_DEPS=ON \ -DBUILD_PACKAGE=OFF \ -DBUILD_SHARED_LIBS=OFF \ diff --git a/external/ios-cmake b/external/ios-cmake new file mode 160000 index 0000000000..ab8607a7f5 --- /dev/null +++ b/external/ios-cmake @@ -0,0 +1 @@ +Subproject commit ab8607a7f57970d99d590d420ecd8e2d7f9a9c77