Add cctools CMake toolchain for cross-compiling all Apple targets

This commit is contained in:
Benau 2021-05-20 11:27:18 +08:00
parent 7109f38725
commit 35b57a7dbb
4 changed files with 65 additions and 41 deletions

View File

@ -675,7 +675,16 @@ endif()
if(NOT SERVER_ONLY)
if (IOS)
target_link_libraries(supertuxkart "-weak_framework CoreHaptics -framework QuartzCore -framework CoreGraphics -framework AVFoundation -framework AudioToolbox -framework Metal -framework GameController -framework OpenGLES -framework UIKit -framework CoreAudio -framework CoreMotion -framework Foundation -framework GLKit")
target_link_libraries(supertuxkart "-weak_framework CoreHaptics -framework QuartzCore -framework CoreGraphics -framework AVFoundation -framework AudioToolbox -framework Metal -framework GameController -framework OpenGLES -framework UIKit -framework CoreAudio -framework Foundation -framework GLKit")
# tvOS doesn't have CoreMotion framwork
include(CheckCSourceCompiles)
set(prev_req_lib ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES "-framework CoreMotion")
check_c_source_compiles("int main() { return 0; }" COREMOTION_EXISTS)
set(CMAKE_REQUIRED_LIBRARIES ${prev_req_lib})
if (COREMOTION_EXISTS)
target_link_libraries(supertuxkart "-framework CoreMotion")
endif()
endif()
target_link_libraries(supertuxkart

View File

@ -15,9 +15,8 @@ if(WIN32)
set(FREETYPE_FOUND 1)
set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY})
elseif(APPLE)
find_path(FREETYPE_INCLUDE_DIRS NAMES ft2build.h PATH_SUFFIXES freetype2 include/freetype2 include PATHS "/Library/Frameworks/FreeType.Framework/Versions/2.4/unix/include")
find_library(FREETYPE_LIBRARY NAMES freetype PATHS "/Library/Frameworks/FreeType.Framework/Versions/2.4/")
include_directories(/Library/Frameworks/FreeType.Framework/Versions/2.4/unix/include)
find_path(FREETYPE_INCLUDE_DIRS NAMES ft2build.h PATH_SUFFIXES freetype2 include/freetype2 include)
find_library(FREETYPE_LIBRARY NAMES freetype)
set(FREETYPE_FOUND 1)
set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY})
else()

View File

@ -0,0 +1,53 @@
# Usage:
# cmake .. -DCCTOOLS_PREFIX=/path/to/cctools -DCCTOOLS_ARCH=arch -DCCTOOLS_PLATFORM=platform \
# -DRT=/path/to/cctools/darwin/libclang_rt.{ios, iossim, osx, tvos, tvossim}.a -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cctools.cmake
# Download precompiled cctools at https://github.com/supertuxkart/dependencies/releases/download/preview/cctools.tar.xz
# Compiled in Ubuntu 18.04
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Darwin)
# which compilers to use for C and C++
string(TOLOWER "${CCTOOLS_PLATFORM}" platform_lower)
set(CLANG_ARCH ${CCTOOLS_ARCH})
if(CCTOOLS_ARCH MATCHES ^arm)
set(CLANG_ARCH arm)
else()
set(CLANG_ARCH ${CCTOOLS_ARCH})
endif()
if (NOT CCTOOLS_PLATFORM MATCHES MacOSX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fembed-bitcode")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fembed-bitcode")
endif()
SET(CMAKE_C_COMPILER ${CCTOOLS_PREFIX}/bin/${CCTOOLS_ARCH}-${platform_lower}-clang)
SET(CMAKE_CXX_COMPILER ${CCTOOLS_PREFIX}/bin/${CCTOOLS_ARCH}-${platform_lower}-clang++)
SET(CMAKE_RANLIB ${CCTOOLS_PREFIX}/bin/${CLANG_ARCH}-apple-darwin11-ranlib)
SET(CMAKE_AR ${CCTOOLS_PREFIX}/bin/${CLANG_ARCH}-apple-darwin11-ar)
SET(CMAKE_INSTALL_NAME_TOOL ${CCTOOLS_PREFIX}/bin/${CLANG_ARCH}-apple-darwin11-install_name_tool)
SET(CMAKE_SYSTEM_PROCESSOR ${CCTOOLS_ARCH})
SET(CMAKE_MACOSX_RPATH TRUE)
SET(CMAKE_EXE_LINKER_FLAGS ${RT})
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH ${PROJECT_SOURCE_DIR}/dependencies-${platform_lower} ${CCTOOLS_PREFIX}/sdk/${CCTOOLS_PLATFORM}.sdk)
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ALWAYS)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# fix statically linking because of order
if (NOT CCTOOLS_PLATFORM MATCHES MacOSX)
set(CURL_LIBRARY "${PROJECT_SOURCE_DIR}/dependencies-${platform_lower}/lib/libcurl.a;${PROJECT_SOURCE_DIR}/dependencies-${platform_lower}/lib/libmbedtls.a;${PROJECT_SOURCE_DIR}/dependencies-${platform_lower}/lib/libmbedx509.a")
endif()
set(USE_CRYPTO_OPENSSL FALSE CACHE BOOL "")
if (NOT CCTOOLS_PLATFORM MATCHES MacOSX)
set(USE_WIIUSE FALSE CACHE BOOL "")
set(USE_SQLITE3 FALSE CACHE BOOL "")
set(IOS TRUE CACHE BOOL "")
endif()

View File

@ -1,37 +0,0 @@
# Usage:
# cmake .. -DCCTOOLS_PREFIX=/path/to/cctools -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-ios.cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DRT=/path/to/libclang_rt.ios.a
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Darwin)
# which compilers to use for C and C++
SET(CMAKE_C_COMPILER ${CCTOOLS_PREFIX}/bin/arm-apple-darwin11-clang)
SET(CMAKE_CXX_COMPILER ${CCTOOLS_PREFIX}/bin/arm-apple-darwin11-clang++)
set(IOS_CPP_FLAGS "-I${CCTOOLS_PREFIX}/SDK/iPhoneOS13.5.sdk/usr/include/c++")
SET(CMAKE_C_FLAGS "-mios-version-min=9.0.0 ${IOS_CPP_FLAGS}")
SET(CMAKE_CXX_FLAGS "-mios-version-min=9.0.0 ${IOS_CPP_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "-mios-version-min=9.0.0 ${RT}")
SET(CMAKE_OSX_SYSROOT ${CCTOOLS_PREFIX}/SDK/iPhoneOS13.5.sdk)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH ${PROJECT_SOURCE_DIR}/dependencies-ios ${CCTOOLS_PREFIX}/SDK/iPhoneOS13.5.sdk)
# manaully set the values which failed to auto detect
set(FREETYPE_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/dependencies-ios/include/freetype2)
set(CURL_LIBRARY "${PROJECT_SOURCE_DIR}/dependencies-ios/lib/libcurl.a;${PROJECT_SOURCE_DIR}/dependencies-ios/lib/libssl.a")
set(PNG_LIBRARY ${PROJECT_SOURCE_DIR}/dependencies-ios/lib/libpng16.a)
set(SDL2_LIBRARY ${PROJECT_SOURCE_DIR}/dependencies-ios/lib/libSDL2.a)
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ALWAYS)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(USE_WIIUSE FALSE CACHE BOOL "")
set(USE_SQLITE3 FALSE CACHE BOOL "")
set(IOS TRUE CACHE BOOL "")
# comment it out to disable logging to debug console
add_definitions(-DENABLE_IOS_DEBUG_PRINT)