cmake_minimum_required(VERSION 3.21)

project(
    XaviaSDK_Examples
    LANGUAGES CXX
)

if(PROJECT_IS_TOP_LEVEL)
    # ------------------------------------------------------------
    # C++ configuration
    # ------------------------------------------------------------
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    set(CMAKE_CXX_EXTENSIONS OFF)
endif()

# ------------------------------------------------------------
# Xavia SDK
# ------------------------------------------------------------

# Only look for the SDK if it is not already part of the build
if(NOT TARGET xavia::sdk)
  get_filename_component(
      XAVIA_SDK_CMAKE_DIR
      "${CMAKE_CURRENT_LIST_DIR}/../cmake"
      REALPATH
  )

  list(APPEND CMAKE_PREFIX_PATH "${XAVIA_SDK_CMAKE_DIR}")

  find_package(Xavia_SDK REQUIRED)
endif()

if(PROJECT_IS_TOP_LEVEL)
    # ------------------------------------------------------------
    # Output directories for all targets
    # ------------------------------------------------------------
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif()

# ------------------------------------------------------------
# Examples
# ------------------------------------------------------------
set(XAVIA_EXAMPLE_DIRS
    basic
    eventHandling
    pointCloudHandling
    ser-deser
    errorHandling
    poweroff
    logging
    fileLogging
    query
)

if(XSDK_ENABLE_CAMERA)
    list(APPEND XAVIA_EXAMPLE_DIRS
        cameraBasic
        cameraRecord8
        cameraRecord12
        cameraRecordBayerRG12AsJPG
        cameraRecordBayerRG12pAsJPG
        cameraRecordAsBayerRG12
        combinedLidarCamera
        combinedLidarCameraRecorder
    )
endif()

if(XSDK_BUILD_ROS2)
    list(APPEND XAVIA_EXAMPLE_DIRS
        ros2
    )
endif()

foreach(dir IN LISTS XAVIA_EXAMPLE_DIRS)
    if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt")
        add_subdirectory(${dir})
    endif()
endforeach()
