Skip to content
Snippets Groups Projects
Commit bef8c5ec authored by Quentin Leblanc's avatar Quentin Leblanc
Browse files

Modified CMAKE so that it is more generic and includes everything correctly...

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
parent 494cf1d8
No related branches found
No related tags found
1 merge request!1Update of install process
cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 3.1)
project(sandbox_wrapper) 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) find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS}) include_directories(inc ${OpenCV_INCLUDE_DIRS})
include_directories(/usr/include/x86_64-linux-gnu/python3.6m)
include_directories(/usr/include/python3.6m) find_package(realsense2 REQUIRED )
include_directories(/home/frog/Prog/Projects/Sandbox/lib/ar_sandbox_lib/inc) 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) # Installation de la bibliothèque et des fichiers d'en-tête
find_package(pybind11 REQUIRED) install(TARGETS ${LIBNAME} DESTINATION lib)
pybind11_add_module(sandbox_wrapper ./cpp/sandbox_wrapper.cpp) install(DIRECTORY inc/ DESTINATION include)
include_directories(/home/frog/Prog/Projects/Sandbox/lib/ar_sandbox_lib/build/) install(CODE "execute_process(COMMAND ln -sf ${LIB_FULL_NAME} ${CMAKE_INSTALL_PREFIX}/lib/${LIBNAME}.so.${LIB_MAJOR_VERS})")
target_link_libraries(sandbox_wrapper PRIVATE ${OpenCV_LIBS}) install(CODE "execute_process(COMMAND ln -sf ${LIB_FULL_NAME} ${CMAKE_INSTALL_PREFIX}/lib/${LIBNAME}.so)")
target_link_libraries(sandbox_wrapper PRIVATE /home/frog/Prog/Projects/Sandbox/lib/ar_sandbox_lib/build/libsandbox.so.1.0.0 -lrealsense2 -lyaml-cpp) \ No newline at end of file
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment