include_guard(GLOBAL)

include(CPM)
cpm()

if(NOT DEFINED SPDLOG_REPOSITORY)
  set(SPDLOG_REPOSITORY "gabime/spdlog")
endif()

if(NOT DEFINED SPDLOG_VERSION)
  set(SPDLOG_VERSION "v1.8.2")
endif()

# misc tweakme options
if(WIN32)
  declare_option(REPOSITORY spdlog OPTION SPDLOG_WCHAR_SUPPORT VALUE ON)
  declare_option(REPOSITORY spdlog OPTION SPDLOG_WCHAR_FILENAMES VALUE ON)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
  declare_option(REPOSITORY spdlog OPTION SPDLOG_CLOCK_COARSE VALUE OFF)
endif()

declare_option(REPOSITORY spdlog OPTION CMAKE_CXX_STANDARD VALUE 14)
declare_option(REPOSITORY spdlog OPTION CMAKE_CXX_STANDARD_REQUIRED VALUE TRUE)
declare_option(REPOSITORY spdlog OPTION CMAKE_CXX_EXTENSIONS VALUE FALSE)
declare_option(REPOSITORY spdlog OPTION CMAKE_INSTALL_PREFIX VALUE ${CMAKE_INSTALL_PREFIX})
declare_option(REPOSITORY spdlog OPTION SPDLOG_BUILD_ALL VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_BUILD_SHARED VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_ENABLE_PCH VALUE ON)
declare_option(REPOSITORY spdlog OPTION SPDLOG_BUILD_EXAMPLE VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_BUILD_EXAMPLE_HO VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_BUILD_TESTS VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_BUILD_TESTS_HO VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_BUILD_BENCH VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_SANITIZE_ADDRESS VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_BUILD_WARNINGS VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_INSTALL VALUE ON)
declare_option(REPOSITORY spdlog OPTION SPDLOG_FMT_EXTERNAL VALUE ON)
declare_option(REPOSITORY spdlog OPTION SPDLOG_FMT_EXTERNAL_HO VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_NO_EXCEPTIONS VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_PREVENT_CHILD_FD VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_NO_THREAD_ID VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_NO_TLS VALUE OFF)
declare_option(REPOSITORY spdlog OPTION SPDLOG_NO_ATOMIC_LEVELS VALUE OFF)

get_option(REPOSITORY spdlog OPTION SPDLOG_FMT_EXTERNAL VARIABLE SPDLOG_FMT_EXTERNAL)
get_option(REPOSITORY spdlog OPTION SPDLOG_FMT_EXTERNAL_HO VARIABLE SPDLOG_FMT_EXTERNAL_HO)
if(SPDLOG_FMT_EXTERNAL OR SPDLOG_FMT_EXTERNAL_HO)
  include(Fmt)
  set(SPDLOG_DEPENDS "DEPENDS fmt")
endif()

print_options(REPOSITORY  spdlog)

CPMFindPackage(NAME spdlog
               ${SPDLOG_DEPENDS}
               GITHUB_REPOSITORY ${SPDLOG_REPOSITORY}
               GIT_TAG ${SPDLOG_VERSION}
               FETCHCONTENT_UPDATES_DISCONNECTED ${IS_OFFLINE}
               OPTIONS ${SPDLOG_OPTIONS}
              )
