From 5bf6850d055280729d154210fb1b0c7e98a219fb Mon Sep 17 00:00:00 2001
From: Tom Moore <tmoore@locusrobotics.com>
Date: Fri, 23 Aug 2024 13:35:27 +0100
Subject: [PATCH 1/3] Fixing issue with Eigen in Ubuntu Jammy on ARM

---
 fuse_constraints/CMakeLists.txt | 9 +++++++++
 fuse_core/CMakeLists.txt        | 9 +++++++++
 fuse_models/CMakeLists.txt      | 9 +++++++++
 fuse_viz/CMakeLists.txt         | 9 +++++++++
 4 files changed, 36 insertions(+)

diff --git a/fuse_constraints/CMakeLists.txt b/fuse_constraints/CMakeLists.txt
index 1a4d8c874..ef86b86b7 100644
--- a/fuse_constraints/CMakeLists.txt
+++ b/fuse_constraints/CMakeLists.txt
@@ -77,6 +77,15 @@ else()
   add_compile_options(-Wall -Werror)
 endif()
 
+# On ARM, the use of Eigen 3.4 with g++11 (both the versions in Jammy) causes a warning, which in turn causes
+# the build to fail. Details are here: https://gitlab.com/libeigen/eigen/-/issues/2326. We can suppress the warning
+# for ARM builds here.
+if(Eigen3_VERSION VERSION_EQUAL 3.4 AND
+CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
+CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
+    add_compile_options(-Wno-class-memaccess)
+endif()
+
 # fuse_constraints library
 add_library(${PROJECT_NAME}
   src/absolute_constraint.cpp
diff --git a/fuse_core/CMakeLists.txt b/fuse_core/CMakeLists.txt
index 7cb841059..10b96f9ff 100644
--- a/fuse_core/CMakeLists.txt
+++ b/fuse_core/CMakeLists.txt
@@ -35,6 +35,15 @@ catkin_package(
 ###########
 add_compile_options(-Wall -Werror)
 
+# On ARM, the use of Eigen 3.4 with g++11 (both the versions in Jammy) causes a warning, which in turn causes
+# the build to fail. Details are here: https://gitlab.com/libeigen/eigen/-/issues/2326. We can suppress the warning
+# for ARM builds here.
+if(Eigen3_VERSION VERSION_EQUAL 3.4 AND
+CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
+CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
+    add_compile_options(-Wno-class-memaccess)
+endif()
+
 ## fuse_core library
 add_library(${PROJECT_NAME}
   src/async_motion_model.cpp
diff --git a/fuse_models/CMakeLists.txt b/fuse_models/CMakeLists.txt
index 9b861f5b9..9fcd8e60a 100644
--- a/fuse_models/CMakeLists.txt
+++ b/fuse_models/CMakeLists.txt
@@ -81,6 +81,15 @@ roslint_cpp()
 ###########
 add_compile_options(-Wall -Werror)
 
+# On ARM, the use of Eigen 3.4 with g++11 (both the versions in Jammy) causes a warning, which in turn causes
+# the build to fail. Details are here: https://gitlab.com/libeigen/eigen/-/issues/2326. We can suppress the warning
+# for ARM builds here.
+if(Eigen3_VERSION VERSION_EQUAL 3.4 AND
+CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
+CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
+    add_compile_options(-Wno-class-memaccess)
+endif()
+
 ## Declare a C++ library
 add_library(${PROJECT_NAME}
   src/acceleration_2d.cpp
diff --git a/fuse_viz/CMakeLists.txt b/fuse_viz/CMakeLists.txt
index bde535755..3e02e0820 100644
--- a/fuse_viz/CMakeLists.txt
+++ b/fuse_viz/CMakeLists.txt
@@ -35,6 +35,15 @@ add_definitions(-DQT_NO_KEYWORDS)
 ###########
 add_compile_options(-Wall -Werror)
 
+# On ARM, the use of Eigen 3.4 with g++11 (both the versions in Jammy) causes a warning, which in turn causes
+# the build to fail. Details are here: https://gitlab.com/libeigen/eigen/-/issues/2326. We can suppress the warning
+# for ARM builds here.
+if(Eigen3_VERSION VERSION_EQUAL 3.4 AND
+CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
+CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
+    add_compile_options(-Wno-class-memaccess)
+endif()
+
 catkin_package(
   INCLUDE_DIRS include
   LIBRARIES ${PROJECT_NAME}

From f0847b990a0c348d780a8cb9bdf51f2c85392d53 Mon Sep 17 00:00:00 2001
From: Tom Moore <tmoore@locusrobotics.com>
Date: Tue, 27 Aug 2024 14:06:47 +0100
Subject: [PATCH 2/3] Also add to fuse_publishers

While Eigen isn't included directly here, it is included when we include some headers from fuse_core.
---
 fuse_publishers/CMakeLists.txt | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fuse_publishers/CMakeLists.txt b/fuse_publishers/CMakeLists.txt
index a2f78f010..7a3836365 100644
--- a/fuse_publishers/CMakeLists.txt
+++ b/fuse_publishers/CMakeLists.txt
@@ -31,6 +31,15 @@ catkin_package(
 ###########
 add_compile_options(-Wall -Werror)
 
+# On ARM, the use of Eigen 3.4 with g++11 (both the versions in Jammy) causes a warning, which in turn causes
+# the build to fail. Details are here: https://gitlab.com/libeigen/eigen/-/issues/2326. We can suppress the warning
+# for ARM builds here.
+if(Eigen3_VERSION VERSION_EQUAL 3.4 AND
+CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
+CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
+    add_compile_options(-Wno-class-memaccess)
+endif()
+
 # fuse_publishers library
 add_library(${PROJECT_NAME}
   src/path_2d_publisher.cpp

From 3f63f4b88135e18f8fb948c9654b4c2db85031b5 Mon Sep 17 00:00:00 2001
From: Tom Moore <tmoore@locusrobotics.com>
Date: Fri, 13 Sep 2024 08:09:40 +0100
Subject: [PATCH 3/3] Fixing packages with no direct Eigen dependency

---
 fuse_constraints/CMakeLists.txt |  4 ++--
 fuse_core/CMakeLists.txt        |  4 ++--
 fuse_models/CMakeLists.txt      |  4 ++--
 fuse_publishers/CMakeLists.txt  | 15 ++++++++++-----
 fuse_viz/CMakeLists.txt         | 15 ++++++++++-----
 5 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/fuse_constraints/CMakeLists.txt b/fuse_constraints/CMakeLists.txt
index ef86b86b7..ce0891c50 100644
--- a/fuse_constraints/CMakeLists.txt
+++ b/fuse_constraints/CMakeLists.txt
@@ -81,8 +81,8 @@ endif()
 # the build to fail. Details are here: https://gitlab.com/libeigen/eigen/-/issues/2326. We can suppress the warning
 # for ARM builds here.
 if(Eigen3_VERSION VERSION_EQUAL 3.4 AND
-CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
-CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
+   CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
+   CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
     add_compile_options(-Wno-class-memaccess)
 endif()
 
diff --git a/fuse_core/CMakeLists.txt b/fuse_core/CMakeLists.txt
index 10b96f9ff..00d5dd0d0 100644
--- a/fuse_core/CMakeLists.txt
+++ b/fuse_core/CMakeLists.txt
@@ -39,8 +39,8 @@ add_compile_options(-Wall -Werror)
 # the build to fail. Details are here: https://gitlab.com/libeigen/eigen/-/issues/2326. We can suppress the warning
 # for ARM builds here.
 if(Eigen3_VERSION VERSION_EQUAL 3.4 AND
-CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
-CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
+   CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
+   CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
     add_compile_options(-Wno-class-memaccess)
 endif()
 
diff --git a/fuse_models/CMakeLists.txt b/fuse_models/CMakeLists.txt
index 9fcd8e60a..dadbc40ba 100644
--- a/fuse_models/CMakeLists.txt
+++ b/fuse_models/CMakeLists.txt
@@ -85,8 +85,8 @@ add_compile_options(-Wall -Werror)
 # the build to fail. Details are here: https://gitlab.com/libeigen/eigen/-/issues/2326. We can suppress the warning
 # for ARM builds here.
 if(Eigen3_VERSION VERSION_EQUAL 3.4 AND
-CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
-CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
+   CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
+   CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
     add_compile_options(-Wno-class-memaccess)
 endif()
 
diff --git a/fuse_publishers/CMakeLists.txt b/fuse_publishers/CMakeLists.txt
index 7a3836365..d6ee2affe 100644
--- a/fuse_publishers/CMakeLists.txt
+++ b/fuse_publishers/CMakeLists.txt
@@ -33,11 +33,16 @@ add_compile_options(-Wall -Werror)
 
 # On ARM, the use of Eigen 3.4 with g++11 (both the versions in Jammy) causes a warning, which in turn causes
 # the build to fail. Details are here: https://gitlab.com/libeigen/eigen/-/issues/2326. We can suppress the warning
-# for ARM builds here.
-if(Eigen3_VERSION VERSION_EQUAL 3.4 AND
-CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
-CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
-    add_compile_options(-Wno-class-memaccess)
+# for ARM builds here. However, this package does not depend directly upon Eigen, but includes headers from other
+# packages that do. So to prevent the error, we need to find Eigen and then check the version.
+if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
+   CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
+
+   find_package(Eigen3)
+
+   if(Eigen3_FOUND AND Eigen3_VERSION VERSION_EQUAL 3.4)
+      add_compile_options(-Wno-class-memaccess)
+   endif()
 endif()
 
 # fuse_publishers library
diff --git a/fuse_viz/CMakeLists.txt b/fuse_viz/CMakeLists.txt
index 3e02e0820..32a681ffd 100644
--- a/fuse_viz/CMakeLists.txt
+++ b/fuse_viz/CMakeLists.txt
@@ -37,11 +37,16 @@ add_compile_options(-Wall -Werror)
 
 # On ARM, the use of Eigen 3.4 with g++11 (both the versions in Jammy) causes a warning, which in turn causes
 # the build to fail. Details are here: https://gitlab.com/libeigen/eigen/-/issues/2326. We can suppress the warning
-# for ARM builds here.
-if(Eigen3_VERSION VERSION_EQUAL 3.4 AND
-CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
-CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
-    add_compile_options(-Wno-class-memaccess)
+# for ARM builds here. However, this package does not depend directly upon Eigen, but includes headers from other
+# packages that do. So to prevent the error, we need to find Eigen and then check the version.
+if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11.0 AND
+   CMAKE_LIBRARY_ARCHITECTURE STREQUAL "aarch64-linux-gnu")
+
+   find_package(Eigen3)
+
+   if(Eigen3_FOUND AND Eigen3_VERSION VERSION_EQUAL 3.4)
+      add_compile_options(-Wno-class-memaccess)
+   endif()
 endif()
 
 catkin_package(