diff --git a/CMakeLists.txt b/CMakeLists.txt index e16ab87ddb55c27c27ec00c830e9cfaac10c3baa..001de293c0777eb15d66af38ba6c2a13688865bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,88 @@ -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 + WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + 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" +) -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) +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. +) -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) +# Installation de la bibliothèque et des fichiers d'en-tête +install(TARGETS ${LIBNAME} DESTINATION lib) +install(DIRECTORY inc/ DESTINATION include) diff --git a/cpp/Makefile.valid b/cpp/Makefile.valid new file mode 100644 index 0000000000000000000000000000000000000000..f2b3b57aa44ffe12e478ceb235b718749e9fef1a --- /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