Skip to content

Commit

Permalink
Use separate libraries for x86_64 and arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
ds58 committed Nov 18, 2024
1 parent 09c7709 commit ad2a54d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 38 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/us/ihmc/etherCAT/soemJavaNativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
5 changes: 3 additions & 2 deletions swig/build.gradle.kts.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -43,7 +43,8 @@ sourceSets {
main {
resources{
srcDir("swig/")
include("**/libsoemJava.so")
include("**/libsoemJava-x86_64.so")
include("**/libsoemJava-arm64.so")
exclude("**/CMakeFiles")
}
}
Expand Down
44 changes: 19 additions & 25 deletions swig/settings.gradle.kts.in
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
27 changes: 20 additions & 7 deletions swig/us/ihmc/soem/generated/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit ad2a54d

Please sign in to comment.