From 275a368f4231c73dce95826f4f18da095f435853 Mon Sep 17 00:00:00 2001
From: zhangfei
Date: Mon, 16 Dec 2024 17:17:39 +0800
Subject: [PATCH 1/3] README: add cross-compile
Signed-off-by: Zhang fei
---
CMakeLists.txt | 4 ++++
README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c978973e..f9912bc4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -246,6 +246,10 @@ function(add_host_executable TARGETNAME)
target_compile_options(${TARGETNAME} PRIVATE -arch "${CMAKE_HOST_SYSTEM_PROCESSOR}")
target_link_options(${TARGETNAME} PRIVATE -arch "${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
+ elseif (DEFINED ENV{SLEEF_TARGET_EXEC_USE_QEMU})
+ if($ENV{SLEEF_TARGET_EXEC_USE_QEMU})
+ add_executable(${TARGETNAME} ${ARGN})
+ endif()
else()
add_executable(${TARGETNAME} IMPORTED GLOBAL)
set_property(TARGET ${TARGETNAME} PROPERTY IMPORTED_LOCATION ${NATIVE_BUILD_DIR}/bin/${TARGETNAME})
diff --git a/README.md b/README.md
index ad18449b..1c70533b 100644
--- a/README.md
+++ b/README.md
@@ -190,6 +190,51 @@ ctest --test-dir build -j
For more detailed build instructions please refer to the [dedicated section on CMake](./docs/1-user-guide/build-with-cmake) or to [our web page][build_info_url].
+## How to CROSS-COMPILE SLEEF
+Two methods are used for cross-compiling SLEEF. Here are examples of cross-compiling SLEEF for the arm architecture on a platform with X86 architecture and Linux OS:
+
+### Method 1
+1. First, compile the native SLEEF.
+```bash
+cmake -S . -B build-native
+
+cmake --build build-native -j --clean-first
+```
+
+2. Cross-compile the target platform's SLEEF.
+```bash
+cmake -DCMAKE_TOOLCHAIN_FILE=./toolchains/aarch64-gcc.cmake -DNATIVE_BUILD_DIR=$(pwd)/build-native/ -S . -B build
+
+cmake --build build -j --clean-first
+```
+
+### Method 2
+
+No need to compile the native SLEEF
+
+1. Install qemu on Ubuntu.
+```bash
+sudo apt install -y qemu-user-static binfmt-support
+```
+
+2. Set the environment variable.
+```bash
+export SLEEF_TARGET_EXEC_USE_QEMU=ON
+```
+
+3. Set the dynamic linker/loader path.
+```bash
+# for aarch64
+export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu/
+```
+
+4. Cross-compile the target platform's SLEEF.
+```bash
+cmake -DCMAKE_TOOLCHAIN_FILE=./toolchains/aarch64-gcc.cmake -S . -B build
+
+cmake --build build -j --clean-first
+```
+
## Install SLEEF
### From source
From aa02abd40ed0e3d27eca41a0bb622c27a72715ca Mon Sep 17 00:00:00 2001
From: zhangfei
Date: Fri, 20 Dec 2024 10:46:09 +0800
Subject: [PATCH 2/3] README: update
Signed-off-by: Zhang fei
---
README.md | 45 ++---------------------------
docs/1-user-guide/README.md | 57 +++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 43 deletions(-)
diff --git a/README.md b/README.md
index 1c70533b..7a2934c5 100644
--- a/README.md
+++ b/README.md
@@ -190,50 +190,9 @@ ctest --test-dir build -j
For more detailed build instructions please refer to the [dedicated section on CMake](./docs/1-user-guide/build-with-cmake) or to [our web page][build_info_url].
-## How to CROSS-COMPILE SLEEF
-Two methods are used for cross-compiling SLEEF. Here are examples of cross-compiling SLEEF for the arm architecture on a platform with X86 architecture and Linux OS:
+## How to cross-compile SLEEF
-### Method 1
-1. First, compile the native SLEEF.
-```bash
-cmake -S . -B build-native
-
-cmake --build build-native -j --clean-first
-```
-
-2. Cross-compile the target platform's SLEEF.
-```bash
-cmake -DCMAKE_TOOLCHAIN_FILE=./toolchains/aarch64-gcc.cmake -DNATIVE_BUILD_DIR=$(pwd)/build-native/ -S . -B build
-
-cmake --build build -j --clean-first
-```
-
-### Method 2
-
-No need to compile the native SLEEF
-
-1. Install qemu on Ubuntu.
-```bash
-sudo apt install -y qemu-user-static binfmt-support
-```
-
-2. Set the environment variable.
-```bash
-export SLEEF_TARGET_EXEC_USE_QEMU=ON
-```
-
-3. Set the dynamic linker/loader path.
-```bash
-# for aarch64
-export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu/
-```
-
-4. Cross-compile the target platform's SLEEF.
-```bash
-cmake -DCMAKE_TOOLCHAIN_FILE=./toolchains/aarch64-gcc.cmake -S . -B build
-
-cmake --build build -j --clean-first
-```
+For more detailed please refer to [cross-compile SLEEF](./docs/1-user-guide#cross_linux)
## Install SLEEF
diff --git a/docs/1-user-guide/README.md b/docs/1-user-guide/README.md
index cf15bb43..5e6b9953 100644
--- a/docs/1-user-guide/README.md
+++ b/docs/1-user-guide/README.md
@@ -18,6 +18,7 @@ Guidelines on how to compile and install the library.
* [Compiling the library with Microsoft Visual C++](#MSVC)
* [Compiling and running "Hello SLEEF"](#hello)
* [Importing SLEEF into your project](#import)
+* [Cross compilation for Linux](#cross_linux)
* [Cross compilation for iOS and Android](#cross)
Preliminaries
@@ -204,6 +205,62 @@ target_link_libraries(hellox86 sleef)
+Cross compilation for Linux
+
+Two methods are used for cross-compiling SLEEF. Both rely on existing toolchain
+files provided in the `toolchains/` directory.
+
+Here are examples of cross-compiling SLEEF for the AArch64 on a platform with
+x86_64 and Linux OS:
+
+Method1
+
+Please run the following from the root directory of SLEEF:
+
+1. First, compile the native SLEEF.
+```bash
+cmake -S . -B build-native
+
+cmake --build build-native -j --clean-first
+```
+
+2. Cross-compile the target platform's SLEEF.
+```bash
+cmake -DCMAKE_TOOLCHAIN_FILE=./toolchains/aarch64-gcc.cmake -DNATIVE_BUILD_DIR=$(pwd)/build-native/ -S . -B build
+
+cmake --build build -j --clean-first
+```
+
+Method2
+
+If running via an emulator like QEMU, there is no need to compile the native SLEEF.
+
+Please run the following from the root directory of SLEEF:
+
+1. Install qemu on Ubuntu.
+```bash
+sudo apt install -y qemu-user-static binfmt-support
+```
+
+2. Set the environment variable.
+```bash
+export SLEEF_TARGET_EXEC_USE_QEMU=ON
+```
+
+3. Set the dynamic linker/loader path.
+```bash
+# for AArch64
+export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu/
+```
+
+4. Cross-compile the target platform's SLEEF.
+```bash
+cmake -DCMAKE_TOOLCHAIN_FILE=./toolchains/aarch64-gcc.cmake -S . -B build
+
+cmake --build build -j --clean-first
+```
+
+
Cross compilation for iOS and Android
SLEEF has preliminary support for iOS and Android. Here, "preliminary" means
From cbdb212983e4c3f81aff2525beb3cc7bd5832ca6 Mon Sep 17 00:00:00 2001
From: zhangfei
Date: Fri, 20 Dec 2024 20:33:19 +0800
Subject: [PATCH 3/3] README: update
Signed-off-by: Zhang fei
---
docs/1-user-guide/README.md | 32 ++++++++++++--------------------
1 file changed, 12 insertions(+), 20 deletions(-)
diff --git a/docs/1-user-guide/README.md b/docs/1-user-guide/README.md
index 5e6b9953..5f98aea4 100644
--- a/docs/1-user-guide/README.md
+++ b/docs/1-user-guide/README.md
@@ -213,7 +213,7 @@ files provided in the `toolchains/` directory.
Here are examples of cross-compiling SLEEF for the AArch64 on a platform with
x86_64 and Linux OS:
-Method1
+Method 1
Please run the following from the root directory of SLEEF:
@@ -231,7 +231,7 @@ cmake -DCMAKE_TOOLCHAIN_FILE=./toolchains/aarch64-gcc.cmake -DNATIVE_BUILD_DIR=$
cmake --build build -j --clean-first
```
-Method2
+Method 2
If running via an emulator like QEMU, there is no need to compile the native SLEEF.
@@ -274,29 +274,21 @@ the library for the host computer, then for the target OS. Below is an example
sequence of commands for cross compiling the library for iOS.
```sh
-mkdir build-native
-cd build-native
-cmake -GNinja ..
-ninja
-cd ..
-mkdir build-cross
-cd build-cross
-cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=../ios.toolchain.cmake -DNATIVE_BUILD_DIR=`pwd`/../build-native -DSLEEF_DISABLE_MPFR=TRUE -DSLEEF_DISABLE_SSL=TRUE ..
-ninja
+# Build natively first
+cmake -S . -B build-native
+cmake --build build-native -j --clean-first
+# Then cross-compile for iOS
+cmake -S . -B build-cross -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake -DNATIVE_BUILD_DIR=$(pwd)/build-native -DSLEEF_DISABLE_MPFR=TRUE -DSLEEF_DISABLE_SSL=TRUE
```
Below is an example sequence of commands for cross compiling the library for
Android.
```sh
-mkdir build-native
-cd build-native
-cmake -GNinja ..
-ninja
-cd ..
-mkdir build-cross
-cd build-cross
-cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=/opt/android-ndk-r21d/build/cmake/android.toolchain.cmake -DNATIVE_BUILD_DIR=`pwd`/../build-native -DANDROID_ABI=arm64-v8a ..
-ninja
+# Build natively first
+cmake -S . -B build-native
+cmake --build build-native -j --clean-first
+# Then cross-compile for Android
+cmake -S . -B build-cross -DCMAKE_TOOLCHAIN_FILE=/opt/android-ndk-r21d/build/cmake/android.toolchain.cmake -DNATIVE_BUILD_DIR=$(pwd)/build-native -DANDROID_ABI=arm64-v8a
```