cmake_minimum_required(VERSION 3.13)
project(superviseur)

# Import modules
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)

# Compile libraries
# Base64
add_library(base64
            lib/base64/base64.cpp
            lib/base64/base64.h
            )
target_include_directories(base64 PUBLIC lib/base64)

# lib
add_library(lib
            lib/camera.cpp
            lib/camera.h
            lib/commonitor.cpp
            lib/commonitor.h
            lib/comrobot.cpp
            lib/comrobot.h
            lib/img.cpp
            lib/img.h
            lib/messages.cpp
            lib/messages.h
            )
target_include_directories(lib PUBLIC lib)
target_link_libraries(lib base64)
target_compile_definitions(lib PUBLIC __FOR_PC__ __SIMULATION__ __WITH_ARUCO__ __WITH_OPENCV4__)

# Compile main executable
add_executable(main main.cpp tasks.cpp tasks.h)
target_link_libraries(main lib)

# OpenCV
#set (OpenCV_DIR /path/to/opencv)        # Optiona: hint for OpenCV root folder
find_package(OpenCV REQUIRED)
target_link_libraries(lib ${OpenCV_LIBS})

# Raspicam_CV
#find_package(raspicam REQUIRED)
#target_link_libraries(lib ${raspicam_CV_LIBS})

# Xenomai
set(Xenomai_ROOT_DIR /usr/xenomai)     # Optional: hint for Xenomai root folder
set(Xenomai_libs POSIX ALCHEMY RTDM PSOS VXWORKS SMOKEY NATIVE)   # List of Xenomai libraries to link

find_package(Xenomai 3.0 REQUIRED ${Xenomai_libs})
if (Xenomai_FOUND)
    message(STATUS "Xenomai found with theses skins: ${Xenomai_SKINS}")
else ()
    message(FATAL_ERROR "Xenomai not found")
endif ()

foreach (lib IN LISTS Xenomai_libs)
    target_include_directories(main PRIVATE ${Xenomai_${lib}_INCLUDE_DIRS})
    target_link_options(main PRIVATE "LINKER:-R/usr/xenomai/lib")
    target_link_libraries(main ${Xenomai_${lib}_LIBRARY_DIRS} ${Xenomai_${lib}_LIBRARIES})
    set_target_properties(main PROPERTIES LINK_FLAGS ${Xenomai_${lib}_LDFLAGS})
    target_compile_definitions(main PRIVATE ${Xenomai_${lib}_DEFINITIONS})
endforeach ()
