include_guard(GLOBAL)

include(CPM)
cpm()

if(NOT DEFINED SOCI_REPOSITORY)
  set(SOCI_REPOSITORY "https://github.com/SOCI/soci.git")
endif()

if(NOT DEFINED SOCI_TAG)
  set(SOCI_TAG "v4.0.2")
endif()

declare_option(REPOSITORY soci OPTION SOCI_SHARED VALUE OFF)
declare_option(REPOSITORY soci OPTION SOCI_STATIC VALUE ON)
declare_option(REPOSITORY soci OPTION SOCI_TESTS VALUE OFF)
declare_option(REPOSITORY soci OPTION SOCI_ASAN VALUE OFF)
declare_option(REPOSITORY soci OPTION SOCI_LTO VALUE ON)
declare_option(REPOSITORY soci OPTION SOCI_VISIBILITY VALUE OFF)
declare_option(REPOSITORY soci OPTION WITH_BOOST VALUE OFF)
print_options(REPOSITORY  soci)

CPMAddPackage(NAME soci
        GIT_REPOSITORY "${SOCI_REPOSITORY}"
        GIT_TAG "${SOCI_TAG}"
        FETCHCONTENT_UPDATES_DISCONNECTED "${IS_OFFLINE}"
        OPTIONS "${soci_OPTIONS}")
if(soci_ADDED)
  add_library(soci INTERFACE)
  get_option(VARIABLE SOCI_STATIC OPTION SOCI_STATIC REPOSITORY soci)
  target_link_libraries(soci INTERFACE soci_core)
  if(SOCI_EMPTY)
    target_link_libraries(soci INTERFACE soci_empty)
  endif()
  if(SOCI_FIREBIRD)
    target_link_libraries(soci INTERFACE soci_firebird INTERFACE ${FIREBIRD_LIBRARIES})
    target_include_directories(soci INTERFACE ${FIREBIRD_INCLUDE_DIR})
  endif()
  if(SOCI_MYSQL)
    target_link_libraries(soci INTERFACE soci_mysql INTERFACE ${MYSQL_LIBRARIES})
    target_include_directories(soci INTERFACE ${MYSQL_INCLUDE_DIR})
  endif()
  if(SOCI_ODBC)
    target_link_libraries(soci INTERFACE soci_odbc INTERFACE ${ODBC_LIBRARIES})
    target_include_directories(soci INTERFACE ${ODBC_INCLUDE_DIRS})
  endif()
  if(SOCI_POSTGRESQL)
    target_link_libraries(soci INTERFACE soci_postgresql INTERFACE ${POSTGRESQL_LIBRARIES})
    target_include_directories(soci INTERFACE ${POSTGRESQL_INCLUDE_DIRS})
  endif()
  if(SOCI_SQLITE3)
    target_link_libraries(soci INTERFACE soci_sqlite3 INTERFACE ${SQLITE3_LIBRARIES})
    target_include_directories(soci INTERFACE ${SQLITE3_INCLUDE_DIR})
  endif()
  if(SOCI_DB2)
    target_link_libraries(soci INTERFACE soci_db2 INTERFACE ${DB2_LIBRARIES})
    target_include_directories(soci INTERFACE ${DB2_INCLUDE_DIR})
  endif()
  if(SOCI_ORACLE)
    target_link_libraries(soci INTERFACE soci_oracle INTERFACE ${ORACLE_LIBRARIES})
    target_include_directories(soci INTERFACE ${ORACLE_INCLUDE_DIR})
  endif()
  target_include_directories(soci INTERFACE $<BUILD_INTERFACE:${soci_SOURCE_DIR}/include> INTERFACE $<BUILD_INTERFACE:${soci_BINARY_DIR}/include>)
  add_library(soci::soci ALIAS soci)
endif()
