Skip to content

Commit

Permalink
Fixed cross-compiling for aarch64. Updated documentations.
Browse files Browse the repository at this point in the history
  • Loading branch information
aregtech committed Nov 16, 2024
1 parent b0f10c2 commit 412c590
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
26 changes: 13 additions & 13 deletions conf/cmake/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,23 @@ endmacro(macro_system_bitness)
# If a match is found in the supported processor list, it extracts:
# - The canonical architecture name.
# - The bitness (e.g., 32 or 64 bits).
# Parameters ..: ${var_processor} [in] -- Input processor architecture name to search for.
# ${name_processor}[out] -- Variable to store the canonical processor architecture name.
# ${name_bitness} [out] -- Variable to store the bitness (32/64) of the processor.
# ${name_found} [out] -- Variable to indicate if the processor is supported (TRUE/FALSE).
# Usage .......: macro_get_processor(<processor-name> <var_processor> <var_bitness> <var_is_found>)
# Example .....: macro_get_processor("aarch64" AREG_PROCESSOR AREG_BITNESS _entry_found)
# ---------------------------------------------------------------------------
macro(macro_get_processor var_processor name_processor name_bitness name_found)
set(${name_found} FALSE)
# Parameters ..: ${processor_name} [in] -- Input processor architecture name to search for.
# ${var_processor} [out] -- Variable to store the canonical processor architecture name.
# ${var_bitness} [out] -- Variable to store the bitness (32/64) of the processor.
# ${var_found} [out] -- Variable to indicate if the processor is supported (TRUE/FALSE).
# Usage .......: macro_get_processor(<processor-name> <var_processor> <var_bitness> <var_entry_found>)
# Example .....: macro_get_processor("arm64" AREG_PROCESSOR AREG_BITNESS _entry_found)
# ---------------------------------------------------------------------------
macro(macro_get_processor processor_name var_processor var_bitness var_found)
set(${var_found} FALSE)
foreach(_entry "x86;${_proc_x86};32" "x64;${_proc_x64};64" "x86_64;${_proc_x64};64" "amd64;${_proc_x64};64" "arm;${_proc_arm32};32" "arm32;${_proc_arm32};32" "arm64;${_proc_arm64};64" "aarch64;${_proc_arm64};64")
list(GET _entry 0 _proc)
list(GET _entry 1 _arch)
list(GET _entry 2 _bits)
if (${_proc} STREQUAL ${var_processor})
set(${name_processor} ${_arch})
set(${name_bitness} ${_bits})
set(${name_found} TRUE)
if (${_proc} STREQUAL ${processor_name})
set(${var_processor} ${_arch})
set(${var_bitness} ${_bits})
set(${var_found} TRUE)
break()
endif()
endforeach()
Expand Down
2 changes: 2 additions & 0 deletions docs/wiki/01b-cmake-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ Cross-compiling allows building applications for architectures different from th
| MSVC | Windows | Win32 | x86, x86_64 |
| Cygwin GNU| Windows | POSIX | x86, x86_64 |

> [!IMPORTANT]
> The AREG SDK itself does not require any external libraries. However, the extended library, `aregextend`, may have dependencies. When cross-compiling, it is recommended to set `AREG_EXTENDED` to `OFF` if you are unsure whether all required libraries are available for the target platform. Alternatively, ensure that dependencies such as `ncurses` or `sqlite3` (if the SQLite3 package is used) are accessible for the target. Otherwise, the build of AREG SKD sources will fail.
### Cross-Compiling for 32-bit Systems

Expand Down
17 changes: 17 additions & 0 deletions docs/wiki/02b-cmake-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The [functions.cmake](./../../conf/cmake/functions.cmake) file in AREG SDK conta
- [`macro_setup_compilers_data_by_family`](#macro_setup_compilers_data_by_family)
- [`macro_guess_processor_architecture`](#macro_guess_processor_architecture)
- [`macro_system_bitness`](#macro_system_bitness)
- [`macro_get_processor`](#macro_get_processor)
3. [CMake Functions Overview](#3-cmake-functions-overview)
- [`setAppOptions`](#setappoptions)
- [`addExecutableEx`](#addexecutableex)
Expand Down Expand Up @@ -233,6 +234,22 @@ The [functions.cmake](./../../conf/cmake/functions.cmake) file includes reusable
macro_system_bitness(_sys_bitness)
```

### `macro_get_processor`
- **Syntax**: `macro_get_processor(processor_name var_processor var_bitness var_found)`
- **Purpose**: Identifies and validates the processor architecture based on a provided name. If a match is found in the supported processor list, it extracts:
- The canonical architecture name.
- The bitness (e.g., 32 or 64 bits).
- **Parameters**:
- `processor_name` [in]: Input processor architecture name to search for.
- `var_processor` [out]: Variable to store the canonical processor architecture name.
- `var_bitness` [out]: Variable to store the bitness (32/64) of the processor.
- `var_found` [out]: Variable to indicate if the processor is supported (TRUE/FALSE).
- **Usage**: `macro_get_processor(<processor-name> <var_processor> <var_bitness> <var_entry_found>)`
- **Example**:
```cmake
macro_get_processor("arm64" AREG_PROCESSOR AREG_BITNESS _entry_found)
```

---

## 3. CMake Functions Overview
Expand Down
28 changes: 28 additions & 0 deletions docs/wiki/07b-troubleshooting-cmake-linux-builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ This guide provides solutions for common issues encountered when compiling proje
2. [Issue 2: Values of `AREG_XXX` Variables are Ignored](#issue-2-values-of-areg_xxx-variables-are-ignored)
- [Solution 1: Fetch Sources Before Project Declaration](#solution-fetch-sources-before-project-declaration)
- [Solution 2: Use Standard CMake Variables](#solution-2-use-standard-cmake-variables)
3. [Issue 3: Failure to Cross-Compile with Extended Objects Enabled](#issue-3-failure-to-cross-compile-with-extended-objects-enabled)
- [Solution 1: Use Target-Compatible Libraries](#solution-1-use-target-compatible-libraries)
- [Solution 2: Pre-Build Required Libraries](#solution*2-pre-build-required-libraries)
- [Solution 3: Disable Extended Objects](#solution-3-disable-extended-objects)

---

Expand Down Expand Up @@ -55,3 +59,27 @@ Fetch the AREG SDK sources *before* calling `project()`. Additionally, you can s
Alternatively, use standard CMake variables such as `CMAKE_CXX_COMPILER` to specify the compiler and `CMAKE_BUILD_TYPE` to define the build type. These variables are compatible with AREG-specific CMake configurations and help avoid conflicts.
---
## Issue 3: Failure to Cross-Compile with Extended Objects Enabled
The build process fails during cross-compilation when AREG SDK extended objects are enabled (option `-DAREG_EXTENDED=ON`). The error message typically states: `cannot find -lncurses: No such file or directory`, even when `ncurses` library is installed. Similar may happend with `sqlite3` library, wich is not connected to extended objects.
This issue occurs when the system lacks target-compatible libraries. For example, if your host system runs on an `x86_64` platform but you are cross-compiling for 32-bit ARM, this error will appear due to missing ARM-compatible versions of the required libraries.
### Solution 1: Use Target-Compatible Libraries
Ensure that the necessary libraries are available for your target platform. You can install them directly or use a package manager, such as `vcpkg`, to compile the dependencies for your target architecture. For example, to install `sqlite3` for an ARM Linux target, use the following command:
```bash
vcpkg install sqlite3:linux-arm
```
For `ncurses`, similarly ensure you compile or install the library for the target platform.
### Solution 2: Pre-Build Required Libraries
Manually build and install the required libraries (`ncurses`, `sqlite3`, etc.) for the target platform using your cross-compilation toolchain. Ensure the paths to these libraries are correctly set in your build environment. For simplicity and portability, consider building statically linked versions of `ncurses` and `sqlite3` for your target platform. This approach avoids runtime dependency issues on the target system.
### Solution 3: Disable Extended Objects
If the extended features of the AREG SDK are not required for your application, you can disable them by setting `-DAREG_EXTENDED=OFF`. This removes dependencies on `ncurses` library. And for `sqlite3` library, use AREG SDK built-in SQLite3 sources available in the `thirdparty` subdirectory.
---

0 comments on commit 412c590

Please sign in to comment.