set(CMAKE_WARN_DEPRECATED
    OFF
    CACHE BOOL "" FORCE)
cmake_minimum_required(VERSION 3.15)

if(NOT DEFINED DRACAL_BUILD_FOR_MT)
  set(DRACAL_BUILD_FOR_MT TRUE)
endif()

set(DRACAL_TUTORIAL_VERSION "3.7.0")

if(MSVC)
  set(DRACAL_TUTORIALS_EXTERNAL_COMPILE_OPTIONS /W0 /Zi)
else()
  set(DRACAL_TUTORIALS_EXTERNAL_COMPILE_OPTIONS -w)
endif()

project(
  dracal-tutorials-cpp
  VERSION ${DRACAL_TUTORIAL_VERSION}
  LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(MSVC AND DRACAL_BUILD_FOR_MT)
  set(CMAKE_MSVC_RUNTIME_LIBRARY
      "MultiThreaded$<$<CONFIG:Debug>:Debug>"
      CACHE STRING "" FORCE)
endif()

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  set(CMAKE_INSTALL_PREFIX
      "${PROJECT_SOURCE_DIR}"
      CACHE PATH "..." FORCE)
endif()

file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR})

if(MSVC)
  add_compile_definitions(_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS)
endif()

add_subdirectory(external/fmt)
add_subdirectory(external/json)
add_subdirectory(external/libhv)

add_executable(dracal-cpp-${DRACAL_TUTORIAL_VERSION}-example-1
               1_check_running/main.cpp)
add_executable(dracal-cpp-${DRACAL_TUTORIAL_VERSION}-example-2
               2_device_list/main.cpp)
add_executable(dracal-cpp-${DRACAL_TUTORIAL_VERSION}-example-3
               3_get_device/main.cpp)
add_executable(dracal-cpp-${DRACAL_TUTORIAL_VERSION}-example-4
               4_RTD300/main.cpp)

target_link_libraries(dracal-cpp-${DRACAL_TUTORIAL_VERSION}-example-1 hv_static)
target_link_libraries(dracal-cpp-${DRACAL_TUTORIAL_VERSION}-example-2 fmt
                      nlohmann_json::nlohmann_json hv_static)
target_link_libraries(dracal-cpp-${DRACAL_TUTORIAL_VERSION}-example-3 fmt
                      nlohmann_json::nlohmann_json hv_static)
target_link_libraries(dracal-cpp-${DRACAL_TUTORIAL_VERSION}-example-4 fmt
                      nlohmann_json::nlohmann_json hv_static)

if(NOT DEFINED DRACAL_PACKAGING)
  install(TARGETS dracal-cpp-${DRACAL_TUTORIAL_VERSION}-example-1)
  install(TARGETS dracal-cpp-${DRACAL_TUTORIAL_VERSION}-example-2)
  install(TARGETS dracal-cpp-${DRACAL_TUTORIAL_VERSION}-example-3)
  install(TARGETS dracal-cpp-${DRACAL_TUTORIAL_VERSION}-example-4)
endif()
