From bef8c5ec103cc5f975e3e04ebb6434aed80bbd14 Mon Sep 17 00:00:00 2001
From: quentin <quentin.leblanc@hesge.ch>
Date: Tue, 11 Mar 2025 17:25:36 +0100
Subject: [PATCH 1/3] Modified CMAKE so that it is more generic and includes
 everything correctly for the .so wrapper. A Valid Makefile is also provided
 in cpp directory in case (very likely) that cmake would not do what it is
 supposed to

---
 CMakeLists.txt     | 91 ++++++++++++++++++++++++++++++++++++++++------
 cpp/Makefile.valid | 24 ++++++++++++
 2 files changed, 104 insertions(+), 11 deletions(-)
 create mode 100644 cpp/Makefile.valid

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e16ab87..535e6f2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,18 +1,87 @@
-cmake_minimum_required(VERSION 2.8.12)
+cmake_minimum_required(VERSION 3.1)
 
 project(sandbox_wrapper)
 
+set(LIBNAME "sandbox_wrapper")
+set(LIB_MINOR_VERS "0.0")
+set(LIB_MAJOR_VERS "1")
+set(LIB_VERS "${LIB_MAJOR_VERS}.${LIB_MINOR_VERS}")
+set(LIB_FULL_NAME "${LIBNAME}.so.${LIB_VERS}")
+
+set(LIBSANDBOX_DIR "" CACHE PATH "Path to LIBSANDBOX Directory")
+set(BUILD_DIR "" CACHE PATH "Path in the LIBSANDBOX Directory for the built .so file")
+
+if(NOT LIBSANDBOX_DIR)
+    message(FATAL_ERROR "LIBSANDBOX Directory must be passed with -DLIBSANDBOX_DIR=...")
+endif()
+
+if(NOT BUILD_DIR)
+    message(FATAL_ERROR "BUILD_DIR Directory must be passed with -DBUILD_DIR=...")
+endif()
+
+set(BUILD_DIR "${LIBSANDBOX_DIR}${BUILD_DIR}")
+
+message(STATUS "LIBSANDBOX located at: ${LIBSANDBOX_DIR}")
+message(STATUS "Build of LIBSANDBOX located at ${BUILD_DIR}")
+
 find_package(OpenCV REQUIRED)
-include_directories(${OpenCV_INCLUDE_DIRS})
-include_directories(/usr/include/x86_64-linux-gnu/python3.6m)
-include_directories(/usr/include/python3.6m)
-include_directories(/home/frog/Prog/Projects/Sandbox/lib/ar_sandbox_lib/inc)
+include_directories(inc ${OpenCV_INCLUDE_DIRS})
+
+find_package(realsense2 REQUIRED )
+include_directories(inc ${realsense_INCLUDE_DIR})
+
+find_package(yaml-cpp REQUIRED)
+include_directories(inc ${YAML_CPP_INCLUDE_DIRS})
+
+find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
+include_directories(inc ${Python3_INCLUDE_DIRS})
+
+include_directories(inc ${LIBSANDBOX_DIR}/inc)
+
+set(PYBIND11_FINDPYTHON ON)
+find_package(pybind11 CONFIG REQUIRED)
+# include_directories(inc ${pybind11_INCLUDE_DIR})
+
+# pybind11_add_module(sandbox_wrapper cpp/sandbox_wrapper.cpp)
+
+file(GLOB_RECURSE SOURCES
+        cpp/*.cpp
+)
+
+add_library(${LIBNAME} SHARED ${SOURCES})
+set_target_properties(${LIBNAME} PROPERTIES OUTPUT_NAME ${LIBNAME} VERSION ${LIB_VERS} SOVERSION ${LIB_MAJOR_VERS})
+
+target_link_libraries(${LIBNAME} ${OpenCV_LIBS})
+target_link_libraries(${LIBNAME} ${realsense_LIBS})
+target_link_libraries(${LIBNAME} -lrealsense2)
+target_link_libraries(${LIBNAME} ${YAML_CPP_LIBRARIES})
+target_link_libraries(${LIBNAME} -lyaml-cpp)
+
+include_directories(${LIBNAME} ${BUILD_DIR})
+target_link_libraries(${LIBNAME} "${BUILD_DIR}/libsandbox.so.1.0.0")
+
+target_compile_options(${LIBNAME} PRIVATE
+        -std=c++11  # Utilisation de C++11
+        -Wall       # Affichage des avertissements classiques
+        -Wextra     # Avertissements supplémentaires
+        -g          # Ajout des symboles de debug
+        -fPIC       # Position Indépendante du Code (obligatoire pour les bibliothèques partagées)
+        -Ilib
+)
 
+# Création des liens symboliques après la compilation
+add_custom_command(TARGET ${LIBNAME} POST_BUILD
+        COMMAND ln -sf ${LIBNAME}.so.${LIB_MAJOR_VERS}
+        COMMAND ln -sf ${LIBNAME}.so
+        WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
+        COMMENT "Création des liens symboliques pour ${LIBNAME}"
+        COMMENT "Copie de libsandbox_wrapper.so.1.0.0 dans src/ar_sandbox/wrapper"
+        COMMAND cp libsandbox_wrapper.so.1.0.0 ../src/ar_sandbox/wrapper/"${LIBNAME}.so"
+)
 
-include_directories(/usr/local/lib/python3.6/dist-packages/pybind11/share/cmake/pybind11)
-find_package(pybind11 REQUIRED)
-pybind11_add_module(sandbox_wrapper ./cpp/sandbox_wrapper.cpp)
+# Installation de la bibliothèque et des fichiers d'en-tête
+install(TARGETS ${LIBNAME} DESTINATION lib)
+install(DIRECTORY inc/ DESTINATION include)
 
-include_directories(/home/frog/Prog/Projects/Sandbox/lib/ar_sandbox_lib/build/)
-target_link_libraries(sandbox_wrapper PRIVATE ${OpenCV_LIBS})
-target_link_libraries(sandbox_wrapper PRIVATE /home/frog/Prog/Projects/Sandbox/lib/ar_sandbox_lib/build/libsandbox.so.1.0.0 -lrealsense2 -lyaml-cpp)
+install(CODE "execute_process(COMMAND ln -sf ${LIB_FULL_NAME} ${CMAKE_INSTALL_PREFIX}/lib/${LIBNAME}.so.${LIB_MAJOR_VERS})")
+install(CODE "execute_process(COMMAND ln -sf ${LIB_FULL_NAME} ${CMAKE_INSTALL_PREFIX}/lib/${LIBNAME}.so)")
\ No newline at end of file
diff --git a/cpp/Makefile.valid b/cpp/Makefile.valid
new file mode 100644
index 0000000..f2b3b57
--- /dev/null
+++ b/cpp/Makefile.valid
@@ -0,0 +1,24 @@
+OPENCVFLAG=`pkg-config --libs --cflags opencv3`
+CAMERAFLAG=-lrealsense2
+YAMLFLAG=-I/usr/local/include -L/usr/local/lib -lyaml-cpp
+
+DEP_SANDBOX=$(OPENCVFLAG) $(CAMERAFLAG) $(YAMLFLAG)
+
+SANDBOX=-I/home/quentin/Documents/HEPIA/ar_sandbox_lib/inc -L/home/quentin/Documents/HEPIA/ar_sandbox_lib/build_test/lib -lsandbox
+CFLAGS=-std=c++11 -Wall -Wextra -g -Ilib -fPIC
+
+WRAPPER_NAME=sandbox_wrapper.so
+
+all: sandbox_wrapper.so
+
+sandbox_wrapper: sandbox_wrapper.o
+	c++ -o $@ $^ $(shell python3-config --libs) $(CFLAGS) $(SANDBOX) $(DEP_SANDBOX) $(LDFLAGS)
+
+sandbox_wrapper.so: sandbox_wrapper.o
+	c++ -O3 -shared $(CFLAGS) $(shell python3 -m pybind11 --includes) $^ -o $(WRAPPER_NAME)$(python3-config --extension-suffix) $(DEP_SANDBOX) $(SANDBOX)
+
+sandbox_wrapper.o: sandbox_wrapper.cpp
+	c++ -c $^ -o $@ -I/usr/include/python3.13 $(python3 -m pybind11 --includes) $(CFLAGS) $(SANDBOX) $(DEP_SANDBOX)
+
+clean:
+	rm *.so *.o
\ No newline at end of file
-- 
GitLab


From 6f97b67abda9553345b1948d63983e960f6df3ea Mon Sep 17 00:00:00 2001
From: quentin <quentin.leblanc@hesge.ch>
Date: Wed, 12 Mar 2025 11:17:36 +0100
Subject: [PATCH 2/3] aded build of python package after compilation of wrapper
 so

---
 CMakeLists.txt | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 535e6f2..0bf0419 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -71,17 +71,18 @@ target_compile_options(${LIBNAME} PRIVATE
 
 # Création des liens symboliques après la compilation
 add_custom_command(TARGET ${LIBNAME} POST_BUILD
-        COMMAND ln -sf ${LIBNAME}.so.${LIB_MAJOR_VERS}
-        COMMAND ln -sf ${LIBNAME}.so
         WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
-        COMMENT "Création des liens symboliques pour ${LIBNAME}"
-        COMMENT "Copie de libsandbox_wrapper.so.1.0.0 dans src/ar_sandbox/wrapper"
-        COMMAND cp libsandbox_wrapper.so.1.0.0 ../src/ar_sandbox/wrapper/"${LIBNAME}.so"
+        COMMENT "Copie de ${LIB_FULL_NAME} dans src/ar_sandbox/wrapper"
+        COMMAND ${CMAKE_COMMAND}
+        ARGS -E copy "lib${LIB_FULL_NAME}" ../src/ar_sandbox/wrapper/"${LIBNAME}.so"
+)
+
+add_custom_command(TARGET ${LIBNAME} POST_BUILD
+        WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
+        COMMENT "Création du module Python dans le répertoire dist/"
+        COMMAND python -m build .. # Création du module python en prenant en compte que cmake est exécuté dans un répertoir build situé à la racine du projet.
 )
 
 # Installation de la bibliothèque et des fichiers d'en-tête
 install(TARGETS ${LIBNAME} DESTINATION lib)
-install(DIRECTORY inc/ DESTINATION include)
-
-install(CODE "execute_process(COMMAND ln -sf ${LIB_FULL_NAME} ${CMAKE_INSTALL_PREFIX}/lib/${LIBNAME}.so.${LIB_MAJOR_VERS})")
-install(CODE "execute_process(COMMAND ln -sf ${LIB_FULL_NAME} ${CMAKE_INSTALL_PREFIX}/lib/${LIBNAME}.so)")
\ No newline at end of file
+install(DIRECTORY inc/ DESTINATION include)
\ No newline at end of file
-- 
GitLab


From a756f6bed072606e72868d2a9925e354d9d5dc64 Mon Sep 17 00:00:00 2001
From: Kevin Heirich <kevin.heirich@hesge.ch>
Date: Wed, 12 Mar 2025 11:30:32 +0100
Subject: [PATCH 3/3] forgot to include the pybind headers, added it

---
 CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0bf0419..001de29 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,7 +40,7 @@ include_directories(inc ${LIBSANDBOX_DIR}/inc)
 
 set(PYBIND11_FINDPYTHON ON)
 find_package(pybind11 CONFIG REQUIRED)
-# include_directories(inc ${pybind11_INCLUDE_DIR})
+include_directories(inc ${pybind11_INCLUDE_DIR})
 
 # pybind11_add_module(sandbox_wrapper cpp/sandbox_wrapper.cpp)
 
@@ -85,4 +85,4 @@ add_custom_command(TARGET ${LIBNAME} POST_BUILD
 
 # Installation de la bibliothèque et des fichiers d'en-tête
 install(TARGETS ${LIBNAME} DESTINATION lib)
-install(DIRECTORY inc/ DESTINATION include)
\ No newline at end of file
+install(DIRECTORY inc/ DESTINATION include)
-- 
GitLab