From 0464535a53a9da4625433a1671d36b8a077190ac Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Thu, 11 May 2023 17:26:41 +0200 Subject: [PATCH] refactor toolchain files --- CMakeLists.txt | 2 +- Jenkinsfile | 4 ++-- tools/cmake/RealmConfig.cmake.in | 2 +- tools/cmake/aarch64-linux-gnu.toolchain.cmake | 3 +++ tools/cmake/armhf.toolchain.cmake | 18 ------------------ .../armv7-linux-gnueabihf.toolchain.cmake | 3 +++ ...chain.cmake => linux.toolchain.base.cmake} | 4 +++- tools/cmake/x86_64-linux-gnu.toolchain.cmake | 3 +++ tools/cmake/x86_64.toolchain.cmake | 19 ------------------- 9 files changed, 16 insertions(+), 42 deletions(-) create mode 100644 tools/cmake/aarch64-linux-gnu.toolchain.cmake delete mode 100644 tools/cmake/armhf.toolchain.cmake create mode 100644 tools/cmake/armv7-linux-gnueabihf.toolchain.cmake rename tools/cmake/{aarch64.toolchain.cmake => linux.toolchain.base.cmake} (91%) create mode 100644 tools/cmake/x86_64-linux-gnu.toolchain.cmake delete mode 100644 tools/cmake/x86_64.toolchain.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 23f92cd8384..bb14ffd8592 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,7 +297,7 @@ endif() # Just use -lz and let Xcode figure it out # Emscripten does provide Zlib, but it doesn't work with find_package and is handled specially if(NOT APPLE AND NOT EMSCRIPTEN AND NOT TARGET ZLIB::ZLIB) - if(WIN32 OR (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_CROSSCOMPILING)) + if(WIN32 OR (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND REALM_LINUX_TOOLCHAIN)) realm_acquire_dependency(zlib ${DEP_ZLIB_VERSION} ZLIB_CMAKE_INCLUDE_FILE) include(${ZLIB_CMAKE_INCLUDE_FILE}) elseif(ANDROID) diff --git a/Jenkinsfile b/Jenkinsfile index 3e87ff9da02..4875c0e7b45 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -261,7 +261,7 @@ def doCheckInDocker(Map options = [:]) { } if (options.useToolchain) { - cmakeDefinitions += " -DCMAKE_TOOLCHAIN_FILE=\"${env.WORKSPACE}/tools/cmake/x86_64.toolchain.cmake\"" + cmakeDefinitions += " -DCMAKE_TOOLCHAIN_FILE=\"${env.WORKSPACE}/tools/cmake/x86_64-linux-gnu.toolchain.cmake\"" } def buildSteps = { String dockerArgs = "" -> @@ -388,7 +388,7 @@ def doBuildLinux(String buildType) { rm -rf build-dir mkdir build-dir cd build-dir - cmake -DCMAKE_BUILD_TYPE=${buildType} -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/x86_64.toolchain.cmake -DREALM_NO_TESTS=1 -DREALM_VERSION="${gitDescribeVersion}" -G Ninja .. + cmake -DCMAKE_BUILD_TYPE=${buildType} -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/x86_64-linux-gnu.toolchain.cmake -DREALM_NO_TESTS=1 -DREALM_VERSION="${gitDescribeVersion}" -G Ninja .. ninja cpack -G TGZ """ diff --git a/tools/cmake/RealmConfig.cmake.in b/tools/cmake/RealmConfig.cmake.in index 94fc7a88c23..14dc24a17dc 100644 --- a/tools/cmake/RealmConfig.cmake.in +++ b/tools/cmake/RealmConfig.cmake.in @@ -24,7 +24,7 @@ find_dependency(Threads) # so for an iOS build it'll use the path from the Device plaform, which is an error on Simulator. # Just use -lz and let Xcode figure it out if(TARGET Realm::Sync AND NOT APPLE AND NOT TARGET ZLIB::ZLIB) - if(WIN32 OR (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_CROSSCOMPILING)) + if(WIN32 OR (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND REALM_LINUX_TOOLCHAIN)) realm_acquire_dependency(zlib @DEP_ZLIB_VERSION@ ZLIB_CMAKE_INCLUDE_FILE) include(${ZLIB_CMAKE_INCLUDE_FILE}) elseif(ANDROID) diff --git a/tools/cmake/aarch64-linux-gnu.toolchain.cmake b/tools/cmake/aarch64-linux-gnu.toolchain.cmake new file mode 100644 index 00000000000..c86a4c3f31e --- /dev/null +++ b/tools/cmake/aarch64-linux-gnu.toolchain.cmake @@ -0,0 +1,3 @@ +set(_TRIPLET "aarch64-unknown-linux-gnu") +set(_TOOLCHAIN_MD5 a3a14d87f98904c2558b43bbd310f337) +include("${CMAKE_CURRENT_LIST_DIR}/linux.toolchain.base.cmake") diff --git a/tools/cmake/armhf.toolchain.cmake b/tools/cmake/armhf.toolchain.cmake deleted file mode 100644 index 6a9bbf37d92..00000000000 --- a/tools/cmake/armhf.toolchain.cmake +++ /dev/null @@ -1,18 +0,0 @@ -if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") - message(FATAL_ERROR "This toolchain can only be used on x86_64 Linux.") -endif() - -set(_TRIPLET "armv7-unknown-linux-gnueabihf") -file(DOWNLOAD https://static.realm.io/toolchains/v3/${_TRIPLET}.tar.zst ${CMAKE_BINARY_DIR}/${_TRIPLET}.tar.zst - EXPECTED_HASH MD5=fbf817b1428bb35c93be8e6c15f73d7d STATUS _DOWNLOAD_STATUS) -list(GET _DOWNLOAD_STATUS 0 _DOWNLOAD_STATUS_CODE) -if(NOT ${_DOWNLOAD_STATUS_CODE} EQUAL 0) - message(FATAL_ERROR "Error downloading ${_TRIPLET}.tar.zst: ${_DOWNLOAD_STATUS}") -endif() - -file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/${_TRIPLET}.tar.zst DESTINATION ${CMAKE_BINARY_DIR}) -include("${CMAKE_BINARY_DIR}/${_TRIPLET}/toolchain.cmake") - -set(CMAKE_EXE_LINKER_FLAGS_INIT "-Xlinker --exclude-libs=libgcc.a,libstdc++.a -static-libgcc -static-libstdc++") -set(CMAKE_SHARED_LINKER_FLAGS_INIT "-Xlinker --exclude-libs=libgcc.a,libstdc++.a -static-libgcc -static-libstdc++") -set(CMAKE_MODULE_LINKER_FLAGS_INIT "-Xlinker --exclude-libs=libgcc.a,libstdc++.a -static-libgcc -static-libstdc++") diff --git a/tools/cmake/armv7-linux-gnueabihf.toolchain.cmake b/tools/cmake/armv7-linux-gnueabihf.toolchain.cmake new file mode 100644 index 00000000000..423c44fdcd5 --- /dev/null +++ b/tools/cmake/armv7-linux-gnueabihf.toolchain.cmake @@ -0,0 +1,3 @@ +set(_TRIPLET "armv7-unknown-linux-gnueabihf") +set(_TOOLCHAIN_MD5 fbf817b1428bb35c93be8e6c15f73d7d) +include("${CMAKE_CURRENT_LIST_DIR}/linux.toolchain.base.cmake") diff --git a/tools/cmake/aarch64.toolchain.cmake b/tools/cmake/linux.toolchain.base.cmake similarity index 91% rename from tools/cmake/aarch64.toolchain.cmake rename to tools/cmake/linux.toolchain.base.cmake index f19fe88ac31..2a2c5eff0f1 100644 --- a/tools/cmake/aarch64.toolchain.cmake +++ b/tools/cmake/linux.toolchain.base.cmake @@ -4,7 +4,7 @@ endif() set(_TRIPLET "aarch64-unknown-linux-gnu") file(DOWNLOAD https://static.realm.io/toolchains/v3/${_TRIPLET}.tar.zst ${CMAKE_BINARY_DIR}/${_TRIPLET}.tar.zst - EXPECTED_HASH MD5=a3a14d87f98904c2558b43bbd310f337 STATUS _DOWNLOAD_STATUS) + EXPECTED_HASH MD5=${_TOOLCHAIN_MD5} STATUS _DOWNLOAD_STATUS) list(GET _DOWNLOAD_STATUS 0 _DOWNLOAD_STATUS_CODE) if(NOT ${_DOWNLOAD_STATUS_CODE} EQUAL 0) message(FATAL_ERROR "Error downloading ${_TRIPLET}.tar.zst: ${_DOWNLOAD_STATUS}") @@ -16,3 +16,5 @@ include("${CMAKE_BINARY_DIR}/${_TRIPLET}/toolchain.cmake") set(CMAKE_EXE_LINKER_FLAGS_INIT "-Xlinker --exclude-libs=libgcc.a,libstdc++.a -static-libgcc -static-libstdc++") set(CMAKE_SHARED_LINKER_FLAGS_INIT "-Xlinker --exclude-libs=libgcc.a,libstdc++.a -static-libgcc -static-libstdc++") set(CMAKE_MODULE_LINKER_FLAGS_INIT "-Xlinker --exclude-libs=libgcc.a,libstdc++.a -static-libgcc -static-libstdc++") + +set(REALM_LINUX_TOOLCHAIN ON) diff --git a/tools/cmake/x86_64-linux-gnu.toolchain.cmake b/tools/cmake/x86_64-linux-gnu.toolchain.cmake new file mode 100644 index 00000000000..8fbdc46792f --- /dev/null +++ b/tools/cmake/x86_64-linux-gnu.toolchain.cmake @@ -0,0 +1,3 @@ +set(_TRIPLET "x86_64-unknown-linux-gnu") +set(_TOOLCHAIN_MD5 aa99fc16d85adf1bb2f8b63b83542044) +include("${CMAKE_CURRENT_LIST_DIR}/linux.toolchain.base.cmake") diff --git a/tools/cmake/x86_64.toolchain.cmake b/tools/cmake/x86_64.toolchain.cmake deleted file mode 100644 index 0b30663fbef..00000000000 --- a/tools/cmake/x86_64.toolchain.cmake +++ /dev/null @@ -1,19 +0,0 @@ -if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") - message(FATAL_ERROR "This toolchain can only be used on x86_64 Linux.") -endif() - -set(_TRIPLET "x86_64-unknown-linux-gnu") -file(DOWNLOAD https://static.realm.io/toolchains/v3/${_TRIPLET}.tar.zst ${CMAKE_BINARY_DIR}/${_TRIPLET}.tar.zst - EXPECTED_HASH MD5=aa99fc16d85adf1bb2f8b63b83542044 STATUS _DOWNLOAD_STATUS) -list(GET _DOWNLOAD_STATUS 0 _DOWNLOAD_STATUS_CODE) -if(NOT ${_DOWNLOAD_STATUS_CODE} EQUAL 0) - message(FATAL_ERROR "Error downloading ${_TRIPLET}.tar.zst: ${_DOWNLOAD_STATUS}") -endif() - -file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/${_TRIPLET}.tar.zst DESTINATION ${CMAKE_BINARY_DIR}) -include("${CMAKE_BINARY_DIR}/${_TRIPLET}/toolchain.cmake") -unset(CMAKE_CROSSCOMPILING_EMULATOR) - -set(CMAKE_EXE_LINKER_FLAGS_INIT "-Xlinker --exclude-libs=libgcc.a,libstdc++.a -static-libgcc -static-libstdc++") -set(CMAKE_SHARED_LINKER_FLAGS_INIT "-Xlinker --exclude-libs=libgcc.a,libstdc++.a -static-libgcc -static-libstdc++") -set(CMAKE_MODULE_LINKER_FLAGS_INIT "-Xlinker --exclude-libs=libgcc.a,libstdc++.a -static-libgcc -static-libstdc++")