Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README: add cross-compile #607

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add that both rely on existing toolchain files provided in the toolchains/ directory.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AArch64

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

say x86_64


### 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add "If running via an emulator like QEMU there is ..."


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
Expand Down