
cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
project (SimControlApplication VERSION 0.1.0 LANGUAGES CXX C)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
include(defaultOptions)

#find_package(Eigen3 REQUIRED NO_MODULE)


IF(NOT TARGET Catch2)
  add_subdirectory(libs/Catch2 EXCLUDE_FROM_ALL)
  include(libs/Catch2/contrib/Catch.cmake)
ENDIF()

IF (NOT TARGET CLI11)
  set(CLI11_TESTING OFF CACHE BOOL "disable testing")
  add_subdirectory(libs/CLI11 EXCLUDE_FROM_ALL)
ENDIF()


IF(NOT TARGET loguru)
  add_subdirectory(libs/loguru EXCLUDE_FROM_ALL)
  set_property(TARGET loguru PROPERTY POSITION_INDEPENDENT_CODE 1)
ENDIF()
add_compile_definitions(LOGURU_WITH_STREAMS SQLITE_THREADSAFE=2)

IF(NOT TARGET KubeControl)
  set(TEST_KUBECONTROL_LIBRARY OFF CACHE BOOL "disable testing")
  add_subdirectory(libs/KubeControl EXCLUDE_FROM_ALL)
ENDIF()

IF(NOT TARGET OrderLibrary)
  add_subdirectory(libs/OrderLibrary EXCLUDE_FROM_ALL)
ENDIF()

IF(NOT TARGET ixwebsocket)
  add_subdirectory(libs/ixwebsocket EXCLUDE_FROM_ALL)
ENDIF()


IF(NOT TARGET easywsclient)
add_library(easywsclient STATIC libs/easywsclient/easywsclient.hpp libs/easywsclient/easywsclient.cpp)
target_include_directories( easywsclient PUBLIC libs/easywsclient/ )
ENDIF()


add_library(SimControl STATIC
               
  include/SimControl/SimControl.hpp
  src/SimControl/SimControl.cpp
  include/SimControl/PodList.hpp
  src/SimControl/PodList.cpp

  include/SimControl/Tracklist.hpp
  src/SimControl/Tracklist.cpp

  include/SimControl/TrackItem.hpp
  src/SimControl/TrackItem.cpp
  )


target_link_libraries(SimControl
  PUBLIC  
  CLI11
  pthread
  SimCore
  kubecontrol
  loguru
  OrderLibrary
  ixwebsocket
)

target_include_directories(SimControl
  PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>
  PRIVATE
    src
  )


add_executable(SimControlApplication
            src/main.cpp
        )

target_link_libraries(SimControlApplication
  CLI11
  SimControl
)


add_custom_command(TARGET SimControlApplication POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy_directory
      ${CMAKE_CURRENT_SOURCE_DIR}/libs/KubeControl/docs 
      $<TARGET_FILE_DIR:${PROJECT_NAME}>/docs)

# target_include_directories(EntitiyManagerApplication
#   PRIVATE
#   src)

#
# Everything TEST related
#
option(TEST_SIMCONTROLLER_LIBRARY "Turn running of application template specific tests off" ON)

IF (${TEST_SIMCONTROLLER_LIBRARY})
  
  

add_executable(test_tracklist tests/test_tracklist.cpp)
target_link_libraries(test_tracklist Catch2::Catch2 SimControl loguru)
catch_discover_tests(test_tracklist)

add_executable(test_Simcontrol tests/test_Simcontrol.cpp)
target_link_libraries(test_Simcontrol Catch2::Catch2 SimControl easywsclient loguru)
catch_discover_tests(test_Simcontrol)

  
  
ENDIF()
