Skip to content

Commit

Permalink
Cross compilation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ds58 committed Nov 18, 2024
1 parent ad2a54d commit e4f03c5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
8 changes: 8 additions & 0 deletions linux-aarch64-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.10)

set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu)
set(CMAKE_PROGRAM_PATH /usr/aarch64-linux-gnu/bin)

set(ENV{AARCH64_CROSS} "1")
19 changes: 11 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,17 @@ The gradle build files for the SOEM wrapper and native libraries are created by

To build and publish run the following commands. Note that the gradle commands are ran from within the build directory.


- cd ihmc-ethercat-master
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE=Release ..
- make
- ../gradlew publishToMavenLocal -Ptarget=JAVA
- ../gradlew publishToMavenLocal -Ptarget=PLATFORM
```
cd ihmc-ethercat-master
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
# Cross compile for arm64 using the toolchain
# cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../linux-aarch64-toolchain.cmake ..
make
../gradlew publishToMavenLocal -Ptarget=JAVA
../gradlew publishToMavenLocal -Ptarget=PLATFORM
```

Note that if you want to publish multiple platform libraries you only have to run target=JAVA on a single platform

Expand Down
2 changes: 1 addition & 1 deletion swig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.4)
cmake_minimum_required(VERSION 3.10)

set(CMAKE_POSITION_INDEPENDENT_CODE true)

Expand Down
2 changes: 1 addition & 1 deletion swig/settings.gradle.kts.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ else
}
else
{
if (OperatingSystem.current().isLinux() && System.getProperty("os.arch") == "aarch64")
if (OperatingSystem.current().isLinux() && (System.getProperty("os.arch") == "aarch64" || System.getenv("AARCH64_CROSS") != null))
{
rootProject.name="soem-platform-linux-arm64"
}
Expand Down
8 changes: 5 additions & 3 deletions swig/us/ihmc/soem/generated/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.10)

find_package(JNI REQUIRED)
include_directories(${JNI_INCLUDE_DIRS})
Expand All @@ -11,9 +11,11 @@ include_directories("/usr/include/soem")
set_property(SOURCE soem.i PROPERTY SWIG_FLAGS "-package" "us.ihmc.soem.generated")

if(UNIX AND NOT APPLE)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" AND NOT DEFINED ENV{AARCH64_CROSS})
message(STATUS "Using target platform x86_64")
set(LIBRARY_NAME "soemJava-x86_64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR DEFINED ENV{AARCH64_CROSS})
message(STATUS "Using target platform arm64")
set(LIBRARY_NAME "soemJava-arm64")
else()
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}")
Expand Down

0 comments on commit e4f03c5

Please sign in to comment.