[x265] [PATCH 03/12] AArch64: Refactor cross-compilation toolchains
Hari Limaye
hari.limaye at arm.com
Thu May 2 21:19:38 UTC 2024
The existing Cross Compilation toolchain for aarch64-linux uses
environment variables to optionally specify a different cross-compiler,
which are then used to set CMake variables.
Refactor toolchains using CMake options (boolean cache variables), so
that these can be set directly when running CMake to configure the
project.
Remove the hard-coded version from the aarch64-darwin toolchain, and add
the option to allow overriding this default, for example in order to use
a specific gcc version. Note that by removing the version, gcc/g++ will
invoke clang/clang++ on Darwin systems by default.
Update README to reflect this change, as well as to provide some
additional details regarding the use of toolchain files.
---
build/README.txt | 17 +++++++++--------
build/aarch64-darwin/crosscompile.cmake | 10 +++++++---
build/aarch64-linux/crosscompile.cmake | 10 +++-------
3 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/build/README.txt b/build/README.txt
index 6346eb041..1528e9837 100644
--- a/build/README.txt
+++ b/build/README.txt
@@ -94,16 +94,17 @@ found, the version will be "unknown".
= Build Instructions for cross-compilation for Arm AArch64 Targets=
-When the target platform is based on Arm AArch64 architecture, the x265 can be
-built in x86 platforms. However, the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER
-enviroment variables should be set to point to the cross compilers of the
-appropriate gcc. For example:
+Cross compilation of x265 for AArch64 targets is possible on x86 platforms by
+passing a toolchain file when running CMake to configure the project:
-1. export CMAKE_C_COMPILER=aarch64-unknown-linux-gnu-gcc
-2. export CMAKE_CXX_COMPILER=aarch64-unknown-linux-gnu-g++
+* cmake -DCMAKE_TOOLCHAIN_FILE=<path-to-toolchain-file>
-The default ones are aarch64-linux-gnu-gcc and aarch64-linux-gnu-g++.
-Then, the normal building process can be followed.
+Toolchain files for AArch64 cross-compilation exist in the /build directory.
+These specify a default cross-compiler to use; however this can be overridden
+by setting the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER CMake variables when
+running CMake to configure the project. For example:
+
+* cmake -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++
Moreover, if the target platform supports SVE or SVE2 instruction set, the
CROSS_COMPILE_SVE or CROSS_COMPILE_SVE2 environment variables should be set
diff --git a/build/aarch64-darwin/crosscompile.cmake b/build/aarch64-darwin/crosscompile.cmake
index d933daaa2..289c32bca 100644
--- a/build/aarch64-darwin/crosscompile.cmake
+++ b/build/aarch64-darwin/crosscompile.cmake
@@ -7,9 +7,13 @@ set(CROSS_COMPILE_ARM64 1)
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
-# specify the cross compiler
-set(CMAKE_C_COMPILER gcc-12)
-set(CMAKE_CXX_COMPILER g++-12)
+# specify the cross compiler (giving precedence to user-supplied CC/CXX)
+if(NOT DEFINED CMAKE_C_COMPILER)
+ set(CMAKE_C_COMPILER gcc)
+endif()
+if(NOT DEFINED CMAKE_CXX_COMPILER)
+ set(CMAKE_CXX_COMPILER g++)
+endif()
# specify the target environment
SET(CMAKE_FIND_ROOT_PATH /opt/homebrew/bin/)
diff --git a/build/aarch64-linux/crosscompile.cmake b/build/aarch64-linux/crosscompile.cmake
index 8cfe3243d..932b472c4 100644
--- a/build/aarch64-linux/crosscompile.cmake
+++ b/build/aarch64-linux/crosscompile.cmake
@@ -7,15 +7,11 @@ set(CROSS_COMPILE_ARM64 1)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
-# specify the cross compiler
-if(DEFINED ENV{CMAKE_C_COMPILER})
- set(CMAKE_C_COMPILER $ENV{CMAKE_C_COMPILER})
-else()
+# specify the cross compiler (giving precedence to user-supplied CC/CXX)
+if(NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
endif()
-if(DEFINED ENV{CMAKE_CXX_COMPILER})
- set(CMAKE_CXX_COMPILER $ENV{CMAKE_CXX_COMPILER})
-else()
+if(NOT DEFINED CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
endif()
--
2.42.1
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
More information about the x265-devel
mailing list