get_filename_component(name ${CMAKE_CURRENT_LIST_DIR} NAME)
set(rely global::drogon global::libarchive global::SQLiteCpp)
rcl_load_dependency_environment(${rely})
find_package(Drogon)
find_package(SQLiteCpp CONFIG REQUIRED)
set(Core Psc_Core_Static)
set(md "${CMAKE_CURRENT_LIST_DIR}/module")
if (WIN32)
    set(cfg_dir ${CMAKE_CURRENT_LIST_DIR}/config)
else ()
    set(cfg_dir ${CMAKE_CURRENT_LIST_DIR}/config)
endif ()
set(data_dir ${CMAKE_CURRENT_LIST_DIR}/data)
file(READ "${cfg_dir}/config.json" ecap_default_config_hex HEX)
string(REGEX REPLACE "([0-9A-Fa-f][0-9A-Fa-f])" "0x\\1,\n" ecap_default_config_bytes "${ecap_default_config_hex}")
set(ecap_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
file(MAKE_DIRECTORY "${ecap_generated_dir}")
configure_file("${md}/Local_Server/server/Config_Default.h.in" "${ecap_generated_dir}/Config_Default.h" @ONLY)
append_glob_source(dll_source_srcs "${md}/dll_source")
add_library(dll_source SHARED ${dll_source_srcs})
add_executable(data_process "${dll_source_srcs}")
target_include_directories(dll_source PUBLIC "${md}")
target_link_libraries(dll_source PUBLIC ${Core})
target_link_libraries(data_process PUBLIC ${Core})
_attach_post_build_file(dll_source
        ${cfg_dir}/data_progress_config.json
        ${data_dir}/BIN_Blank_Text/ADS-B_195_0205.txt
        #            "${CMAKE_CURRENT_LIST_DIR}/data/BIN_Blank_Text/ADS-B_195_0205.txt"
)
append_glob_source(mlat_source_srcs "${md}/mlat_source")
add_library(mlat_source SHARED ${mlat_source_srcs})
target_include_directories(mlat_source PUBLIC "${md}")
target_link_libraries(mlat_source PUBLIC ${Core})
append_glob_source(ecap_server_srcs "${md}/Local_Server")
add_executable(ecap_server "${md}/Local_Server_main.cpp" ${ecap_server_srcs})
target_include_directories(ecap_server PUBLIC "${md}")
target_include_directories(ecap_server PRIVATE "${ecap_generated_dir}")
target_include_directories(ecap_server PRIVATE
        "${CMAKE_CURRENT_LIST_DIR}/third_party/Adminive/backend/library/include"
        "${CMAKE_CURRENT_LIST_DIR}/third_party/Adminive/backend/service/include"
        "${CMAKE_CURRENT_LIST_DIR}/third_party/Adminive/backend/service/third_party/include"
        "${CMAKE_CURRENT_LIST_DIR}/third_party/Structive/core/include"
)
target_include_directories(ecap_server PRIVATE ${ZLIB_INCLUDE_DIR})
target_link_libraries(ecap_server PUBLIC SSR)
target_link_libraries(ecap_server PUBLIC ${Core})
target_link_libraries(ecap_server PRIVATE Drogon::Drogon)
target_link_libraries(ecap_server PRIVATE SQLiteCpp)
target_link_libraries(ecap_server PRIVATE ${ZLIB_LIBRARY})
if (MSVC)
    target_compile_options(ecap_server PRIVATE /bigobj /utf-8)
endif ()
message("LibArchive_SUB_LIBRARIES  {${LibArchive_SUB_LIBRARIES}}")
target_link_libraries(ecap_server PRIVATE
        LibArchive::LibArchive
        ${LibArchive_SUB_LIBRARIES}
)
target_compile_definitions(ecap_server PRIVATE LIBARCHIVE_STATIC)
target_compile_definitions(ecap_server PRIVATE NOMINMAX)
target_compile_definitions(ecap_server PRIVATE INCL_EXTRA_HTON_FUNCTIONS) # drogon用
if (MSVC)
    target_compile_definitions(ecap_server PRIVATE
            _CRTDBG_MAP_ALLOC
    )
endif ()
add_dependencies(ecap_server dll_source)
set(ecap_package_includes
        "^.*$"
)
set(ecap_package_excludes
        #        "^[.]git/.*$"
        #        "^[.]idea/.*$"
        "^data/.*$"
        "^cmake-build-[^/]*/.*$"
        "^(.*/)?node_modules/.*$"
        "^(.*/)?.git/.*$"
        "^(.*/)?wwwroot/.*$"
        "^(.*/)?dist/.*$"
        "^(.*/)?htdocs/.*$"
        "^(.*/)?model/.*$"
        "^(.*/)?.idea/.*$"
        "^(.*/)?dll_source_lzy/.*$"
        "^.*[.]tsbuildinfo$"
        "^.*[.]zip$"
)
_add_project_zip_target(
        ecap_package_zip
        "${CMAKE_CURRENT_LIST_DIR}/ecap_package.zip"
        "${CMAKE_SOURCE_DIR}"
        ecap_package_includes
        ecap_package_excludes
)
#_add_directory_to_clion("C:/tiles")
rcl_unload_dependency_environment(${rely})

