From ad2a54dc0e1c9c8115ec06abd5ab29fe47a75e19 Mon Sep 17 00:00:00 2001 From: Dexton Anderson Date: Mon, 18 Nov 2024 15:41:53 -0600 Subject: [PATCH] Use separate libraries for x86_64 and arm64 --- build.gradle.kts | 4 +- .../ihmc/etherCAT/soemJavaNativeLibrary.java | 8 +++- swig/build.gradle.kts.in | 5 ++- swig/settings.gradle.kts.in | 44 ++++++++----------- swig/us/ihmc/soem/generated/CMakeLists.txt | 27 +++++++++--- 5 files changed, 50 insertions(+), 38 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c74dd4d..2a56ee8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,8 +17,8 @@ ihmc { app.entrypoint("SlaveInfo", "us.ihmc.etherCAT.master.SlaveInfo") mainDependencies { - api("us.ihmc:soem:1.4.0-ihmc1") - api("us.ihmc:soem-platform-linux:1.4.0-ihmc1") + api("us.ihmc:soem:1.5.0") + api("us.ihmc:soem-platform-linux-x86_64:1.5.0") api("us.ihmc:ihmc-native-library-loader:2.0.3") api("us.ihmc:ihmc-realtime:1.6.0") } diff --git a/src/main/java/us/ihmc/etherCAT/soemJavaNativeLibrary.java b/src/main/java/us/ihmc/etherCAT/soemJavaNativeLibrary.java index a694619..e953f1e 100644 --- a/src/main/java/us/ihmc/etherCAT/soemJavaNativeLibrary.java +++ b/src/main/java/us/ihmc/etherCAT/soemJavaNativeLibrary.java @@ -15,9 +15,13 @@ public String getPackage(OperatingSystem os, Architecture arch) @Override public NativeLibraryWithDependencies getLibraryWithDependencies(OperatingSystem os, Architecture arch) { - if (os == OperatingSystem.LINUX64) + if (os == OperatingSystem.LINUX64 && arch == Architecture.x64) { - return NativeLibraryWithDependencies.fromFilename("libsoemJava.so"); + return NativeLibraryWithDependencies.fromFilename("libsoemJava-x86_64.so"); + } + else if (os == OperatingSystem.LINUX64 && arch == Architecture.arm64) + { + return NativeLibraryWithDependencies.fromFilename("libsoemJava-arm64.so"); } throw new RuntimeException("Unsupported platform: " + os.name() + "-" + arch.name()); } diff --git a/swig/build.gradle.kts.in b/swig/build.gradle.kts.in index 025dafd..8355f28 100644 --- a/swig/build.gradle.kts.in +++ b/swig/build.gradle.kts.in @@ -5,7 +5,7 @@ plugins { ihmc { group = "us.ihmc" - version = "1.4.0-ihmc1" + version = "1.5.0" vcsUrl = "https://github.com/ihmcrobotics/ihmc-ethercat-master" openSource = true @@ -43,7 +43,8 @@ sourceSets { main { resources{ srcDir("swig/") - include("**/libsoemJava.so") + include("**/libsoemJava-x86_64.so") + include("**/libsoemJava-arm64.so") exclude("**/CMakeFiles") } } diff --git a/swig/settings.gradle.kts.in b/swig/settings.gradle.kts.in index c6746c5..c2e61c9 100644 --- a/swig/settings.gradle.kts.in +++ b/swig/settings.gradle.kts.in @@ -33,29 +33,23 @@ if((target != "JAVA" && target != "PLATFORM")) else { - if(target == "JAVA") - { - rootProject.name="soem" - } - else - { - - if(OperatingSystem.current().isWindows()) - { - rootProject.name="soem-platform-windows" - } - else if (OperatingSystem.current().isLinux()) - { - rootProject.name="soem-platform-linux" - } - else if (OperatingSystem.current().isMacOsX()) - { - rootProject.name="soem-platform-mac" - } - else - { - throw GradleException("Current platform is not supported") - } - - } + if (target == "JAVA") + { + rootProject.name="soem" + } + else + { + if (OperatingSystem.current().isLinux() && System.getProperty("os.arch") == "aarch64") + { + rootProject.name="soem-platform-linux-arm64" + } + else if (OperatingSystem.current().isLinux() && System.getProperty("os.arch") == "amd64") + { + rootProject.name="soem-platform-linux-x86_64" + } + else + { + throw GradleException("Current platform is not supported") + } + } } diff --git a/swig/us/ihmc/soem/generated/CMakeLists.txt b/swig/us/ihmc/soem/generated/CMakeLists.txt index bd81139..5f3f72f 100644 --- a/swig/us/ihmc/soem/generated/CMakeLists.txt +++ b/swig/us/ihmc/soem/generated/CMakeLists.txt @@ -2,13 +2,26 @@ cmake_minimum_required(VERSION 2.8) find_package(JNI REQUIRED) include_directories(${JNI_INCLUDE_DIRS}) -FIND_PACKAGE(SWIG REQUIRED) -INCLUDE(${SWIG_USE_FILE}) +find_package(SWIG REQUIRED) +include(${SWIG_USE_FILE}) -INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/swig/") -INCLUDE_DIRECTORIES("/usr/include/soem") +include_directories("${PROJECT_SOURCE_DIR}/swig/") +include_directories("/usr/include/soem") -SET_PROPERTY(SOURCE soem.i PROPERTY SWIG_FLAGS "-package" "us.ihmc.soem.generated") +set_property(SOURCE soem.i PROPERTY SWIG_FLAGS "-package" "us.ihmc.soem.generated") -SWIG_ADD_MODULE(soemJava java soem.i) -swig_link_libraries(soemJava ihmcsoemwrapper) +if(UNIX AND NOT APPLE) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") + set(LIBRARY_NAME "soemJava-x86_64") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + set(LIBRARY_NAME "soemJava-arm64") + else() + message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") + endif() +else() + message(FATAL_ERROR "This CMake configuration is only for Linux.") +endif() + +# Add SWIG module with the architecture-specific library name +swig_add_module(${LIBRARY_NAME} java soem.i) +swig_link_libraries(${LIBRARY_NAME} ihmcsoemwrapper)