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

FIND_PACKAGE(Threads REQUIRED)

IF(NOT TARGET Catch2)
  add_subdirectory(libs/Catch2 EXCLUDE_FROM_ALL)
  include(libs/Catch2/contrib/Catch.cmake)
  ENDIF()
  
  add_compile_definitions(LOGURU_WITH_STREAMS SQLITE_THREADSAFE=2)
  IF(NOT TARGET loguru)
  set(LOGURU_STACKTRACES 0 CACHE BOOL "disable testing")
   add_subdirectory(libs/loguru EXCLUDE_FROM_ALL)
  ENDIF()
  
  IF (NOT TARGET CLI11)
  set(CLI11_TESTING OFF CACHE BOOL "disable testing")
  add_subdirectory(libs/CLI11 EXCLUDE_FROM_ALL)
  ENDIF()

  IF(NOT TARGET nlohmann_json)
set(JSON_BuildTests_INIT OFF CACHE INTERNAL "")
  add_subdirectory(libs/nlohmann_json EXCLUDE_FROM_ALL)
ENDIF()
  
  IF (NOT TARGET yaml-cpp)
  set(YAML_CPP_BUILD_TESTS OFF CACHE INTERNAL "")
  set(YAML_CPP_BUILD_TOOLS OFF CACHE INTERNAL "")
  set(YAML_CPP_BUILD_CONTRIB OFF CACHE INTERNAL "")
  set(YAML_CPP_INSTALL OFF CACHE INTERNAL "")
  add_subdirectory(libs/yaml-cpp EXCLUDE_FROM_ALL)
ENDIF()

  IF (NOT TARGET curlpp)
  set(BUILD_SHARED_LIBS FALSE )
  add_subdirectory(libs/curlpp EXCLUDE_FROM_ALL)
  ENDIF()
  
  IF(NOT TARGET crossguid)
    set(CROSSGUID_TESTS OFF CACHE INTERNAL "")
    add_subdirectory(libs/crossguid EXCLUDE_FROM_ALL)
  ENDIF()
 
  
  # build with CC=clang-15 CXX=clang++-15 cmake -D CMAKE_BUILD_TYPE=DEBUG ..
  
  
  add_library(kubecontrol STATIC
  
  include/kubecontrol/kubecontrol.hpp
  src/kubecontrol/kubecontrol.cpp

  include/kubecontrol/KubePod.hpp
  src/kubecontrol/KubePod.cpp

  include/kubecontrol/PodController.hpp
  src/kubecontrol/PodController.cpp

  include/kubecontrol/Utils.hpp
  src/kubecontrol/Utils.cpp

  # include/kubecontrol/PodInfo.hpp
  # src/kubecontrol/PodInfo.cpp


  include/kubecontrol/KubernetesAPI.hpp
  src/kubecontrol/KubernetesAPI.cpp
  )


target_link_libraries(kubecontrol
crossguid
yaml-cpp
curlpp
loguru
nlohmann_json
pthread
)
target_include_directories(kubecontrol PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
  src)


 
  add_custom_command(TARGET kubecontrol POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy_directory
      ${CMAKE_CURRENT_SOURCE_DIR}/config $<TARGET_FILE_DIR:${PROJECT_NAME}>/config)
    
  add_custom_command(TARGET kubecontrol POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy_directory
      ${CMAKE_CURRENT_SOURCE_DIR}/docs $<TARGET_FILE_DIR:${PROJECT_NAME}>/docs)
#
# Everything TEST related
#
option(TEST_KUBECONTROL_LIBRARY "Turn running of application template specific tests off" ON)

IF (${TEST_KUBECONTROL_LIBRARY})
  
  

  add_executable(test_kubecontrol tests/test_kubecontrol.cpp)
  target_link_libraries(test_kubecontrol Catch2::Catch2 kubecontrol )
  catch_discover_tests(test_kubecontrol)

  add_executable(test_KubePod tests/test_KubePod.cpp)
  target_link_libraries(test_KubePod Catch2::Catch2 kubecontrol )
  catch_discover_tests(test_KubePod)

  add_executable(test_podcontroller tests/test_podcontroller.cpp)
  target_link_libraries(test_podcontroller Catch2::Catch2 kubecontrol )
  catch_discover_tests(test_podcontroller)

  add_executable(test_massivPodHandling tests/test_massivPodHandling.cpp)
  target_link_libraries(test_massivPodHandling Catch2::Catch2 kubecontrol )
  catch_discover_tests(test_massivPodHandling)
  
  
ENDIF()
