list(APPEND authdbSrcs
    backends/file.cpp
    backends/cluster.cpp
    backend.cpp
    index.cpp
    data.cpp
    user.cpp
    domain.cpp
    group.cpp
    session.cpp
    gpo.cpp
    client.cpp
    service.cpp
    hash.cpp
    hash/sha512.cpp
    export.cpp
    import.cpp
    plugin.cpp
    cluster.cpp
)

add_library( authobj OBJECT ${authdbSrcs} )

target_include_directories(
    authobj
    PUBLIC
    ${JSONC_INCLUDE_DIR}
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
    $<INSTALL_INTERFACE:include>
)

target_link_libraries(
    authobj
    PUBLIC
    uuidp::uuidp
    json-c::json-c
    confplus::confplus
    netplus::netplus
    httppp::httppp
    htmlpp::htmlpp
    paritypp::paritypp
)

add_executable(authdb
    admin.cpp
    authdb.cpp
    api.cpp
    log.cpp
    $<TARGET_OBJECTS:authobj>
)

target_link_libraries(authdb PUBLIC
    cmdplus::cmdplus
    uuidp::uuidp
    json-c::json-c
    httppp::httppp
    htmlpp::htmlpp
    confplus::confplus
    paritypp::paritypp
    ${CMAKE_DL_LIBS}
)

set_target_properties(authdb PROPERTIES
    ENABLE_EXPORTS TRUE
    INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/authdb"
    BUILD_RPATH   "${CMAKE_BINARY_DIR}/plugin/ad;${CMAKE_BINARY_DIR}/plugin/krb5"
)

message(STATUS "NETPLUS: ${NETPLUS_INCLUDE_DIR}")

include_directories(
    BEFORE ${NETPLUS_INCLUDE_DIR}
)

install(FILES session.h authdb.h backend.h types.h group.h user.h exception.h service.h plugin.h index.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/authdb)

install(TARGETS authdb DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME_DEPENDENCY_SET authdyn)

if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows" )
    install(
        RUNTIME_DEPENDENCY_SET authdyn
        DIRECTORIES 
            "$<TARGET_FILE_DIR:htmlpp::htmlpp>" 
            "$<TARGET_FILE_DIR:httppp::httppp>"
            "$<TARGET_FILE_DIR:uuidp::uuidp>"
            "$<TARGET_FILE_DIR:json-c::json-c>"
        DESTINATION bin
        PRE_EXCLUDE_REGEXES "((api|ext)-ms-.*|.*azureattest.*|vcruntime.*|ucrtbase.*|msvcrt.*|wpaxholder.*|hvsifiletrust.*|pdmutilities.*)\\.dll"
        POST_EXCLUDE_REGEXES [[.*(\\|/)system32(\\|/).*\.dll]]
    )
endif()
