diff --git a/.travis.yml b/.travis.yml index 3f73107..004b145 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,53 +1,109 @@ language: objective-c -matrix: +os: + - osx + +jobs: + fast_finish: true + allow_failures: + - name: "Use new *COMBINED build support in CMake 3.19.4+ [allowed failure]" + - name: "Mac Catalyst on Apple Silicon, Target iOS 13.0 [arm64] [allowed failure]" + - name: "Xcode version 12.2, Target macOS on Apple Silicon [arm64] SDK 11.0 [allowed failure]" include: - - os: osx - osx_image: xcode11.3 - env: - - PLATFORM=SIMULATOR DEPLOYMENT_TARGET=13.1 - - os: osx - osx_image: xcode10.2 - env: - - PLATFORM=SIMULATOR64 DEPLOYMENT_TARGET=12.1 - - os: osx - osx_image: xcode11.1 - env: - - PLATFORM=OS DEPLOYMENT_TARGET=13.0 - - os: osx - osx_image: xcode10.2 - env: - - PLATFORM=OS64 DEPLOYMENT_TARGET=12.0 - - os: osx - osx_image: xcode9.4 - env: - - PLATFORM=OS64 DEPLOYMENT_TARGET=11.0 - - os: osx - osx_image: xcode10.2 - env: - - PLATFORM=OS BUILD_SHARED=1 DEPLOYMENT_TARGET=12.0 - - os: osx - osx_image: xcode10.2 - env: - - PLATFORM=TVOS DEPLOYMENT_TARGET=11.0 - - os: osx - osx_image: xcode10.2 - env: - - PLATFORM=WATCHOS DEPLOYMENT_TARGET=5.0 - - os: osx - osx_image: xcode10.2 - env: - - PLATFORM=OS64COMBINED USE_XCODE=1 DEPLOYMENT_TARGET=11.0 - - os: osx - osx_image: xcode12.2 - env: - - PLATFORM=OS64COMBINED USE_XCODE=1 DEPLOYMENT_TARGET=14.0 - - os: osx - osx_image: xcode11.3 - env: - - PLATFORM=OS64COMBINED BUILD_CURL=1 USE_XCODE=1 DEPLOYMENT_TARGET=11.0 - -install: true + - name: "Xcode version 8.3, Target iOS [arm64] SDK 9.0" + stage: "iOS builds" + osx_image: xcode8.3 + env: + - PLATFORM=OS64 DEPLOYMENT_TARGET=9.0 + - name: "Xcode version 9.4, Target iOS [arm64] SDK 9.0" + stage: "iOS builds" + osx_image: xcode9.4 + env: + - PLATFORM=OS64 DEPLOYMENT_TARGET=9.0 + - name: "Xcode version 9.4, Target iOS [arm64] SDK 11.0" + stage: "iOS builds" + osx_image: xcode10.2 + env: + - PLATFORM=OS64 DEPLOYMENT_TARGET=11.0 + - name: "Xcode version 9.4, Target iOS [armv7, armv7k, arm64] SDK 9.0" + stage: "iOS builds" + osx_image: xcode10.2 + env: + - PLATFORM=OS DEPLOYMENT_TARGET=9.0 + - name: "Xcode version 11.3, Target iOS Simulator64 [x86_64] SDK 12.0" + stage: "iOS builds" + osx_image: xcode11.3 + env: + - PLATFORM=SIMULATOR64 DEPLOYMENT_TARGET=12.0 + + - name: "Xcode version 11.3, Target watchOS [armv7k,arm64_32] SDK 5.0" + stage: "watchOS builds" + osx_image: xcode11.3 + env: + - PLATFORM=WATCHOS DEPLOYMENT_TARGET=5.0 + - name: "Xcode version 12.2, Target watchOS Simulator [x86_64] SDK 7.0" + stage: "watchOS builds" + osx_image: xcode12.2 + env: + - PLATFORM=SIMULATOR_WATCHOS DEPLOYMENT_TARGET=7.0 + + - name: "Xcode version 11.3, Target tvOS [arm64] SDK 11.0" + stage: "tvOS builds" + osx_image: xcode11.3 + env: + - PLATFORM=TVOS DEPLOYMENT_TARGET=11.0 + + - name: "Xcode version 11.3, Target iOS Combined Build [x86_64, arm64] SDK 12.0" + stage: "Combined builds" + osx_image: xcode11.3 + env: + - PLATFORM=OS64COMBINED USE_XCODE=1 DEPLOYMENT_TARGET=12.0 + - name: "Xcode version 11.3, Target watchOS [armv7k, arm64_32, x86_64] SDK 5.0" + stage: "Combined builds" + osx_image: xcode11.3 + env: + - PLATFORM=WATCHOSCOMBINED USE_XCODE=1 DEPLOYMENT_TARGET=5.0 + - name: "Xcode version 11.3, Target tvOS [arm64, x86_64] SDK 11.0" + stage: "Combined builds" + osx_image: xcode11.3 + env: + - PLATFORM=TVOSCOMBINED USE_XCODE=1 DEPLOYMENT_TARGET=11.0 + + - name: "Xcode version 12.2, Target macOS [x86_64] SDK 10.13" + stage: "macOS builds" + osx_image: xcode12.2 + env: + - PLATFORM=MAC DEPLOYMENT_TARGET=10.13 + - name: "Xcode version 12.2, Target macOS on Apple Silicon [arm64] SDK 11.0 [allowed failure]" + stage: "macOS builds" + osx_image: xcode12.2 + env: + - PLATFORM=MAC_ARM64 DEPLOYMENT_TARGET=11.0 + + - name: "Mac Catalyst, iOS target 13.0 [x86_64]" + stage: "Mac Catalyst builds" + osx_image: xcode12.2 + env: + - PLATFORM=MAC_CATALYST DEPLOYMENT_TARGET=13.0 + - name: "Mac Catalyst on Apple Silicon, Target iOS 13.0 [arm64] [allowed failure]" + stage: "Mac Catalyst builds" + osx_image: xcode12.2 + env: + - PLATFORM=MAC_CATALYST_ARM64 DEPLOYMENT_TARGET=13.0 + + - name: "Use new *COMBINED build support in CMake 3.19.4+ [allowed failure]" + stage: "New build system combined builds" + osx_image: xcode12.2 + env: + - PLATFORM=OS64COMBINED USE_XCODE=1 DEPLOYMENT_TARGET=11.0 USE_NEW_BUILD=1 + + - name: "libCURL example combined build on iOS" + stage: "libCURL example builds" + osx_image: xcode11.3 + env: + - PLATFORM=OS64COMBINED USE_XCODE=1 DEPLOYMENT_TARGET=11.0 BUILD_CURL=1 + +install: skip script: - ./.travis/build.sh diff --git a/.travis/build.sh b/.travis/build.sh index 7792df5..2d23a63 100755 --- a/.travis/build.sh +++ b/.travis/build.sh @@ -10,6 +10,7 @@ USE_XCODE=${USE_XCODE:-0} BUILD_CURL=${BUILD_CURL:-0} USE_STRICT_COMPILER_CHECKS=${USE_STRICT_COMPILER_CHECKS:-0} DEPLOYMENT_TARGET=${DEPLOYMENT_TARGET:-11.0} +USE_NEW_BUILD=${USE_NEW_BUILD:-0} SHARED_EXT="" if [[ ${BUILD_SHARED} -eq 1 ]]; then @@ -23,20 +24,26 @@ fi if [[ ${BUILD_CURL} -eq 1 ]]; then mkdir -p example/example-curl/build - pushd example/example-curl/build + pushd example/example-curl/build || exit 1 cmake .. \ - ${GENERATOR_EXT} -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake \ + ${GENERATOR_EXT} -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DCMAKE_INSTALL_PREFIX=../out \ -DPLATFORM=${PLATFORM} -DDEPLOYMENT_TARGET=${DEPLOYMENT_TARGET} -DENABLE_STRICT_TRY_COMPILE=${USE_STRICT_COMPILER_CHECKS} || exit 1 cmake --build . --config Release --parallel 4 || exit 1 - popd + popd || exit 1 else mkdir -p example/example-lib/build - pushd example/example-lib/build + pushd example/example-lib/build || exit 1 cmake .. \ ${GENERATOR_EXT} -DCMAKE_TOOLCHAIN_FILE=../../ios.toolchain.cmake -DCMAKE_INSTALL_PREFIX=../out \ -DPLATFORM=${PLATFORM} -DDEPLOYMENT_TARGET=${DEPLOYMENT_TARGET} -DENABLE_STRICT_TRY_COMPILE=${USE_STRICT_COMPILER_CHECKS} ${SHARED_EXT}\ || exit 1 - cmake --build . --config Release || exit 1 - cmake --install . --config Release || exit 1 - popd + + # Test new way of building in newer CMake versions when building the *COMBINED platform options + if [[ ${USE_NEW_BUILD} -eq 1 ]]; then + cmake --build . --config Release || exit 1 + cmake --install . --config Release || exit 1 + else + cmake --build . --config Release --target install || exit 1 + fi + popd || exit 1 fi diff --git a/example/example-lib/CMakeLists.txt b/example/example-lib/CMakeLists.txt index 8d0b952..47df0c7 100644 --- a/example/example-lib/CMakeLists.txt +++ b/example/example-lib/CMakeLists.txt @@ -13,33 +13,18 @@ else() message(STATUS "kqueue found!") endif() -if(PLATFORM MATCHES "(MAC|MAC_ARM64)") - find_library(HAVE_APPKIT AppKit) - if (NOT HAVE_APPKIT) - message(FATAL_ERROR "AppKit.framework NOT found!") - else() - message(STATUS "AppKit.framework found!") - endif() -elseif(PLATFORM MATCHES "(MAC_CATALYST|MAC_CATALYST_ARM64)") - find_library(HAVE_APPKIT AppKit) - if (NOT HAVE_APPKIT) - message(FATAL_ERROR "AppKit.framework NOT found!") - else() - message(STATUS "AppKit.framework found!") - endif() - find_library(HAVE_UIKIT UIKit) - if (NOT HAVE_UIKIT) - message(FATAL_ERROR "UIKit.framework NOT found!") - else() - message(STATUS "UIKit.framework found!") - endif() +find_library(HAVE_APPKIT AppKit) +if (NOT HAVE_APPKIT) + message(STATUS "AppKit.framework NOT found!") else() - find_library(HAVE_UIKIT UIKit) - if (NOT HAVE_UIKIT) - message(FATAL_ERROR "UIKit.framework NOT found!") - else() - message(STATUS "UIKit.framework found!") - endif() + message(STATUS "AppKit.framework found!") +endif() + +find_library(HAVE_UIKIT UIKit) +if (NOT HAVE_UIKIT) + message(STATUS "UIKit.framework NOT found!") +else() + message(STATUS "UIKit.framework found!") endif() # Hook up XCTest for the supported plaforms (all but WatchOS) @@ -72,6 +57,7 @@ set(HEADERS # Library if(BUILD_SHARED) add_library (example SHARED ${SOURCES} ${HEADERS}) + target_compile_definitions(example PUBLIC IS_BUILDING_SHARED) message(STATUS "Building shared version...") else() add_library (example STATIC ${SOURCES} ${HEADERS}) @@ -84,14 +70,44 @@ endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # Executable if(PLATFORM MATCHES "MAC.*") - add_executable (helloworld main.cpp) + set(APP_NAME TestApp) + add_executable (${APP_NAME} MACOSX_BUNDLE main.cpp) + set_target_properties(${APP_NAME} PROPERTIES + BUNDLE True + MACOSX_BUNDLE_GUI_IDENTIFIER leetal.com.helloworld + MACOSX_BUNDLE_BUNDLE_NAME helloworld + MACOSX_BUNDLE_BUNDLE_VERSION "0.1" + MACOSX_BUNDLE_SHORT_VERSION_STRING "0.1" + ) # Link the library with the executable - target_link_libraries(helloworld example) + target_link_libraries(${APP_NAME} example) endif() # Debug symbols set in XCode project set_xcode_property(example GCC_GENERATE_DEBUGGING_SYMBOLS YES "All") # Installation -install (TARGETS example DESTINATION lib) +if(PLATFORM MATCHES "MAC.*") + install(TARGETS ${APP_NAME} + BUNDLE DESTINATION . COMPONENT Runtime + RUNTIME DESTINATION bin COMPONENT Runtime + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static) + + # Note Mac specific extension .app + set(APPS "\${CMAKE_INSTALL_PREFIX}/${APP_NAME}.app") + + # Directories to look for dependencies + set(DIRS ${CMAKE_BINARY_DIR}) + + install(CODE "include(BundleUtilities) + fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\")") + + set(CPACK_GENERATOR "DRAGNDROP") + include(CPack) +else() + install(TARGETS example + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static) +endif() install (FILES ${HEADERS} DESTINATION include) diff --git a/example/example-lib/HelloWorld.hpp b/example/example-lib/HelloWorld.hpp index e65ebcf..c875965 100644 --- a/example/example-lib/HelloWorld.hpp +++ b/example/example-lib/HelloWorld.hpp @@ -1,7 +1,18 @@ #pragma once #include -class HelloWorld +#if defined(__clang__) +#define SHARED_EXPORT __attribute__((visibility("default"))) +#define SHARED_LOCAL __attribute__((visibility("hidden"))) +#endif + +#if defined(IS_BUILDING_SHARED) +#define API SHARED_EXPORT +#else +#define API +#endif + +class API HelloWorld { public: std::string helloWorld(); diff --git a/ios.toolchain.cmake b/ios.toolchain.cmake index 070101b..3356425 100644 --- a/ios.toolchain.cmake +++ b/ios.toolchain.cmake @@ -127,6 +127,14 @@ # command. # +cmake_minimum_required(VERSION 3.8.0) + +# CMake invokes the toolchain file twice during the first build, but only once during subsequent rebuilds. +if(IOS_TOOLCHAIN_HAS_RUN) + return() +endif(IOS_TOOLCHAIN_HAS_RUN) +set(IOS_TOOLCHAIN_HAS_RUN true) + ############################################################################### # OPTIONS # ############################################################################### @@ -184,16 +192,7 @@ if(_CMAKE_IN_TRY_COMPILE) unset(FORCE_CACHE) endif() -# Problem: CMake runs toolchain files multiple times, but can't read cache variables on some runs. -# Workaround: On first run (in which cache variables are always accessible), set an intermediary environment variable. -# -# NOTE: This pattern is used i many places in this toolchain to speed up checks of all sorts -if(DEFINED PLATFORM) - # Environment variables are always preserved. - set(ENV{_PLATFORM} "${PLATFORM}") -elseif(DEFINED ENV{_PLATFORM}) - set(PLATFORM "$ENV{_PLATFORM}") -elseif(NOT DEFINED PLATFORM) +if(NOT DEFINED PLATFORM) message(FATAL_ERROR "PLATFORM argument not set. Bailing configure since I don't know what target you want to build for!") endif () @@ -205,30 +204,23 @@ if("${contains_PLATFORM}" EQUAL "-1") " Supported PLATFORM values: \n * ${_supported_platforms_formatted}") endif() -set(PLATFORM_INT "${PLATFORM}" CACHE STRING "Type of platform for which the build targets.") - # Check if Apple Silicon is supported -if(PLATFORM_INT MATCHES "^(MAC_ARM64)$|^(MAC_CATALYST_ARM64)$" AND ${CMAKE_VERSION} VERSION_LESS "3.19.5") +if(PLATFORM MATCHES "^(MAC_ARM64)$|^(MAC_CATALYST_ARM64)$" AND ${CMAKE_VERSION} VERSION_LESS "3.19.5") message(FATAL_ERROR "Apple Silicon builds requires a minimum of CMake 3.19.5") endif() # Specify minimum version of deployment target. -if(DEFINED DEPLOYMENT_TARGET) - # Environment variables are always preserved. - set(ENV{_DEPLOYMENT_TARGET} "${DEPLOYMENT_TARGET}") -elseif(DEFINED ENV{_DEPLOYMENT_TARGET}) - set(DEPLOYMENT_TARGET "$ENV{_DEPLOYMENT_TARGET}") -elseif(NOT DEFINED DEPLOYMENT_TARGET) - if (PLATFORM_INT STREQUAL "WATCHOS" OR PLATFORM_INT STREQUAL "SIMULATOR_WATCHOS") +if(NOT DEFINED DEPLOYMENT_TARGET) + if (PLATFORM STREQUAL "WATCHOS" OR PLATFORM STREQUAL "SIMULATOR_WATCHOS") # Unless specified, SDK version 4.0 is used by default as minimum target version (watchOS). set(DEPLOYMENT_TARGET "4.0" CACHE STRING "Minimum SDK version to build for.") - elseif(PLATFORM_INT MATCHES "MAC") + elseif(PLATFORM MATCHES "MAC") # Unless specified, SDK version 10.13 (High sierra) is used by default as minimum target version (macos). set(DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimum SDK version to build for.") - elseif(PLATFORM_INT STREQUAL "MAC_ARM64") + elseif(PLATFORM STREQUAL "MAC_ARM64") # Unless specified, SDK version 11.0 (Big Sur) is used by default as minimum target version (macos on arm). set(DEPLOYMENT_TARGET "11.0" CACHE STRING "Minimum SDK version to build for.") - elseif(PLATFORM_INT MATCHES "(MAC_CATALYST|MAC_CATALYST_ARM64)") + elseif(PLATFORM MATCHES "(MAC_CATALYST|MAC_CATALYST_ARM64)") # Unless specified, SDK version 13.0 is used by default as minimum target version (mac catalyst minimum requirement). set(DEPLOYMENT_TARGET "13.0" CACHE STRING "Minimum SDK version to build for.") else() @@ -236,19 +228,21 @@ elseif(NOT DEFINED DEPLOYMENT_TARGET) set(DEPLOYMENT_TARGET "11.0" CACHE STRING "Minimum SDK version to build for.") endif() message(STATUS "[DEFAULTS] Using the default min-version since DEPLOYMENT_TARGET not provided!") -elseif(DEFINED DEPLOYMENT_TARGET AND PLATFORM_INT STREQUAL "MAC_CATALYST" AND ${DEPLOYMENT_TARGET} VERSION_LESS "13.0") +elseif(DEFINED DEPLOYMENT_TARGET AND PLATFORM STREQUAL "MAC_CATALYST" AND ${DEPLOYMENT_TARGET} VERSION_LESS "13.0") message(FATAL_ERROR "Mac Catalyst builds requires a minimum deployment target of 13.0!") endif() # 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" CACHE STRING "" ${FORCE_CACHE}) +if(PLATFORM STREQUAL "OS" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4) + set(PLATFORM "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" CACHE STRING "" ${FORCE_CACHE}) +elseif(PLATFORM STREQUAL "SIMULATOR" AND DEPLOYMENT_TARGET VERSION_GREATER_EQUAL 10.3.4) + set(PLATFORM "SIMULATOR64") message(STATUS "Targeting minimum SDK version ${DEPLOYMENT_TARGET}. Dropping 32-bit support.") endif() +set(PLATFORM_INT "${PLATFORM}" CACHE STRING "Type of platform for which the build targets.") + # Determine the platform name and architectures for use in xcodebuild commands # from the specified PLATFORM_INT name. if(PLATFORM_INT STREQUAL "OS") @@ -378,11 +372,11 @@ else() message(FATAL_ERROR "Invalid PLATFORM: ${PLATFORM_INT}") endif() -if(MODERN_CMAKE AND PLATFORM_INT MATCHES ".*COMBINED" AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode") +if(MODERN_CMAKE AND PLATFORM_INT MATCHES ".*COMBINED" AND NOT CMAKE_GENERATOR MATCHES "Xcode") message(FATAL_ERROR "The COMBINED options only work with Xcode generator, -G Xcode") endif() -if(USED_CMAKE_GENERATOR MATCHES "Xcode" AND PLATFORM_INT MATCHES "MAC_CATALYST_.*") +if(CMAKE_GENERATOR MATCHES "Xcode" AND PLATFORM_INT MATCHES "MAC_CATALYST_.*") set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") set(CMAKE_XCODE_ATTRIBUTE_SUPPORTED_PLATFORMS "macosx") set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-maccatalyst") @@ -394,17 +388,13 @@ if(USED_CMAKE_GENERATOR MATCHES "Xcode" AND PLATFORM_INT MATCHES "MAC_CATALYST_. endif() # If user did not specify the SDK root to use, then query xcodebuild for it. -if(DEFINED CMAKE_OSX_SYSROOT_INT) - # Environment variables are always preserved. - set(ENV{_CMAKE_OSX_SYSROOT_INT} "${CMAKE_OSX_SYSROOT_INT}") -elseif(DEFINED ENV{_CMAKE_OSX_SYSROOT_INT}) - set(CMAKE_OSX_SYSROOT_INT "$ENV{_CMAKE_OSX_SYSROOT_INT}") -else() +if(NOT DEFINED CMAKE_OSX_SYSROOT_INT) execute_process(COMMAND xcodebuild -version -sdk ${SDK_NAME} Path OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_INT ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) endif() + 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:" @@ -418,7 +408,7 @@ elseif(DEFINED CMAKE_OSX_SYSROOT_INT) endif() # Set Xcode property for SDKROOT as well if Xcode generator is used -#if(USED_CMAKE_GENERATOR MATCHES "Xcode") +#if(CMAKE_GENERATOR MATCHES "Xcode") # set(CMAKE_OSX_SYSROOT "${SDK_NAME}" CACHE INTERNAL "") #endif() @@ -458,12 +448,7 @@ 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. -if(DEFINED SDK_VERSION) - # Environment variables are always preserved. - set(ENV{_SDK_VERSION} "${SDK_VERSION}") -elseif(DEFINED ENV{_SDK_VERSION}) - set(SDK_VERSION "$ENV{_SDK_VERSION}") -else() +if(NOT DEFINED SDK_VERSION) execute_process(COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT_INT} -version SDKVersion OUTPUT_VARIABLE SDK_VERSION ERROR_QUIET @@ -474,7 +459,7 @@ endif() # 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") +if (NOT DEFINED CMAKE_DEVELOPER_ROOT AND NOT CMAKE_GENERATOR MATCHES "Xcode") get_filename_component(PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT_INT} PATH) get_filename_component(CMAKE_DEVELOPER_ROOT ${PLATFORM_SDK_DIR} PATH) if (NOT DEFINED CMAKE_DEVELOPER_ROOT) @@ -484,60 +469,43 @@ if (NOT DEFINED CMAKE_DEVELOPER_ROOT AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode endif() # Find the C & C++ compilers for the specified SDK. -if(DEFINED CMAKE_C_COMPILER) - # Environment variables are always preserved. - set(ENV{_CMAKE_C_COMPILER} "${CMAKE_C_COMPILER}") -elseif(DEFINED ENV{_CMAKE_C_COMPILER}) - set(CMAKE_C_COMPILER "$ENV{_CMAKE_C_COMPILER}") -else() +if(NOT DEFINED CMAKE_C_COMPILER) execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT_INT} -find clang OUTPUT_VARIABLE CMAKE_C_COMPILER ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) endif() -if(DEFINED CMAKE_CXX_COMPILER) - # Environment variables are always preserved. - set(ENV{_CMAKE_CXX_COMPILER} "${CMAKE_CXX_COMPILER}") -elseif(DEFINED ENV{_CMAKE_CXX_COMPILER}) - set(CMAKE_CXX_COMPILER "$ENV{_CMAKE_CXX_COMPILER}") -else() +if(NOT DEFINED CMAKE_CXX_COMPILER) execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT_INT} -find clang++ OUTPUT_VARIABLE CMAKE_CXX_COMPILER ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) endif() # Find (Apple's) libtool. -if(DEFINED BUILD_LIBTOOL) - # Environment variables are always preserved. - set(ENV{_BUILD_LIBTOOL} "${BUILD_LIBTOOL}") -elseif(DEFINED ENV{_BUILD_LIBTOOL}) - set(BUILD_LIBTOOL "$ENV{_BUILD_LIBTOOL}") -else() +if(NOT DEFINED BUILD_LIBTOOL) execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT_INT} -find libtool OUTPUT_VARIABLE BUILD_LIBTOOL ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) endif() -# 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 " CACHE STRING "" ${FORCE_CACHE}) -set(CMAKE_CXX_CREATE_STATIC_LIBRARY - "${BUILD_LIBTOOL} -static -o " CACHE STRING "" ${FORCE_CACHE}) # Find the toolchain's provided install_name_tool if none is found on the host -if(DEFINED CMAKE_INSTALL_NAME_TOOL) - # Environment variables are always preserved. - set(ENV{_CMAKE_INSTALL_NAME_TOOL} "${CMAKE_INSTALL_NAME_TOOL}") -elseif(DEFINED ENV{_CMAKE_INSTALL_NAME_TOOL}) - set(CMAKE_INSTALL_NAME_TOOL "$ENV{_CMAKE_INSTALL_NAME_TOOL}") -else() +if(NOT DEFINED CMAKE_INSTALL_NAME_TOOL) execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT_INT} -find install_name_tool - OUTPUT_VARIABLE CMAKE_INSTALL_NAME_TOOL - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) + 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() +# 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. +get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) +foreach(lang ${languages}) + set(CMAKE_${lang}_CREATE_STATIC_LIBRARY + "${BUILD_LIBTOOL} -static -o ") +endforeach() + # CMake 3.14+ support building for iOS, watchOS and tvOS out of the box. if(MODERN_CMAKE) if(SDK_NAME MATCHES "iphone") @@ -681,86 +649,100 @@ else() set(CMAKE_XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN "NO") 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() - # Hidden visibility is required for C++ on iOS. - set(CMAKE_C_FLAGS "${C_TARGET_FLAGS} ${SDK_NAME_VERSION_FLAGS} ${BITCODE} -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_C_FLAGS}") - set(CMAKE_CXX_FLAGS "${C_TARGET_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 "${C_TARGET_FLAGS} ${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") - set(CMAKE_CXX_LINK_FLAGS "${C_TARGET_FLAGS} ${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") - set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp -arch ${CMAKE_OSX_ARCHITECTURES}") - - # 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 - CMAKE_ASM_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}") - message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}") - message(STATUS "Using CXX compiler: ${CMAKE_CXX_COMPILER}") - message(STATUS "Using libtool: ${BUILD_LIBTOOL}") - message(STATUS "Using install name tool: ${CMAKE_INSTALL_NAME_TOOL}") - 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() - message(STATUS "CMake version: ${CMAKE_VERSION}") - 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}") - if(ENABLE_BITCODE_INT) - message(STATUS "Bitcode: Enabled") - else() - message(STATUS "Bitcode: Disabled") - endif() - - if(ENABLE_ARC_INT) - message(STATUS "ARC: Enabled") - else() - message(STATUS "ARC: Disabled") - endif() - - if(NOT ENABLE_VISIBILITY_INT) - message(STATUS "Hiding symbols (-fvisibility=hidden).") - endif() +#Check if Xcode generator is used, since that will handle these flags automagically +if(CMAKE_GENERATOR MATCHES "Xcode") + message(STATUS "Not setting any manual command-line buildflags, since Xcode is selected as generator.") +else() + # Hidden visibility is required for C++ on iOS. + set(CMAKE_C_FLAGS "${C_TARGET_FLAGS} ${SDK_NAME_VERSION_FLAGS} ${BITCODE} -fobjc-abi-version=2 ${FOBJC_ARC} ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "${C_TARGET_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 "${C_TARGET_FLAGS} ${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") + set(CMAKE_CXX_LINK_FLAGS "${C_TARGET_FLAGS} ${SDK_NAME_VERSION_FLAGS} -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") + set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp -arch ${CMAKE_OSX_ARCHITECTURES}") + + # 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 + CMAKE_ASM_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}") +message(STATUS "Using C compiler: ${CMAKE_C_COMPILER}") +message(STATUS "Using CXX compiler: ${CMAKE_CXX_COMPILER}") +message(STATUS "Using libtool: ${BUILD_LIBTOOL}") +message(STATUS "Using install name tool: ${CMAKE_INSTALL_NAME_TOOL}") +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(CMAKE_GENERATOR MATCHES "Xcode") + message(STATUS "Using Xcode version: ${XCODE_VERSION}") +endif() +message(STATUS "CMake version: ${CMAKE_VERSION}") +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}") +if(ENABLE_BITCODE_INT) + message(STATUS "Bitcode: Enabled") +else() + message(STATUS "Bitcode: Disabled") +endif() - # Set global properties - set_property(GLOBAL PROPERTY PLATFORM "${PLATFORM}") - set_property(GLOBAL PROPERTY APPLE_TARGET_TRIPLE "${APPLE_TARGET_TRIPLE_INT}") - set_property(GLOBAL PROPERTY SDK_VERSION "${SDK_VERSION}") - set_property(GLOBAL PROPERTY XCODE_VERSION "${XCODE_VERSION}") +if(ENABLE_ARC_INT) + message(STATUS "ARC: Enabled") +else() + message(STATUS "ARC: Disabled") endif() +if(NOT ENABLE_VISIBILITY_INT) + message(STATUS "Hiding symbols (-fvisibility=hidden).") +endif() + +# Set global properties +set_property(GLOBAL PROPERTY PLATFORM "${PLATFORM}") +set_property(GLOBAL PROPERTY APPLE_TARGET_TRIPLE "${APPLE_TARGET_TRIPLE_INT}") +set_property(GLOBAL PROPERTY SDK_VERSION "${SDK_VERSION}") +set_property(GLOBAL PROPERTY XCODE_VERSION "${XCODE_VERSION}") + +# Export configurable variables for the try_compile() command. +set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES + PLATFORM + XCODE_VERSION + SDK_VERSION + DEPLOYMENT_TARGET + CMAKE_DEVELOPER_ROOT + CMAKE_OSX_SYSROOT_INT + ENABLE_BITCODE + ENABLE_ARC + CMAKE_C_COMPILER + CMAKE_CXX_COMPILER + BUILD_LIBTOOL + CMAKE_INSTALL_NAME_TOOL + ) + 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") @@ -789,8 +771,6 @@ else() ${CMAKE_FRAMEWORK_PATH} CACHE STRING "Frameworks search paths" ${FORCE_CACHE}) endif() -set(IOS_TOOLCHAIN_HAS_RUN TRUE CACHE BOOL "Has the CMake toolchain run already?") - # 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})