cmake_minimum_required(VERSION 3.18...3.26 FATAL_ERROR)

project(tango_admin VERSION 1.19 LANGUAGES CXX)

if (NOT DEFINED CMAKE_CXX_STANDARD)
    set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/TangoCMakeModules)
find_package(Tango REQUIRED)
message(STATUS "Found cppTango version ${Tango_VERSION}.")

set(SOURCES
        tango_admin.cpp
        anyoption.cpp)

set(HEADERS
        anyoption.h)

add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC Tango::Tango ${CMAKE_DL_LIBS})

if (WIN32)
    target_compile_definitions(${PROJECT_NAME} PUBLIC "NOMINMAX")
endif()


install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)

option(TANGO_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF)

if(TANGO_WARNINGS_AS_ERRORS)
  if(WIN32)
    target_compile_options(${PROJECT_NAME} PUBLIC /WX)
    # LNK4099: PDB was not found
    target_link_options(${PROJECT_NAME} PUBLIC /WX /ignore:4099)
  else()
    target_compile_options(${PROJECT_NAME} PUBLIC -Werror -Wall -Wextra -Wformat -Werror=format-security -pedantic)
  endif()
endif()

option(BUILD_TESTING "Build testing" ON)

if (BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
