cmake_minimum_required(VERSION 3.31)
project(deviceAccessLayer)

set(CMAKE_CXX_STANDARD 20)

set(PACKAGE_DIRS
        ${CMAKE_CURRENT_LIST_DIR}/lib/openssl
        ${CMAKE_CURRENT_LIST_DIR}/lib/HCNetSDK
)
foreach (PACKAGE_DIR ${PACKAGE_DIRS})
    list(APPEND CMAKE_PREFIX_PATH ${PACKAGE_DIR})
endforeach ()

find_package(openssl CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(mqtt_cpp_iface CONFIG REQUIRED)
find_package(HCNet CONFIG REQUIRED)
find_package(ICU REQUIRED COMPONENTS uc)
find_path(CPP_HTTPLIB_INCLUDE_DIRS "httplib.h") # 使用时要先于 windows.h 包含
find_path(CPPCODEC_INCLUDE_DIRS "cppcodec/base32_crockford.hpp")
#find_library(WS2_32_LIB NAMES ws2_32)
set(SOURCE_DIRS
        src/common
        src/vidicon
        src/report_svr
        src/barrier
        src/sound_column
        src/http
        src/mqtt
        src/oss
        src/serial_port
        src/platform_scale
        src
)
set(INCLUDE_DIRS
        src
        ${CPP_HTTPLIB_INCLUDE_DIRS}
        ${CPPCODEC_INCLUDE_DIRS}
)
list(REMOVE_DUPLICATES INCLUDE_DIRS)

set(LINK_DIRS
        src
)
set(LIBRARIES
#        ${WS2_32_LIB}
        openssl::libssl
        openssl::libcrypto
        mqtt_cpp_iface::mqtt_cpp_iface
        nlohmann_json::nlohmann_json
        spdlog::spdlog
        HCNet::HCNetSDK
        HCNet::HCCore
        ICU::uc
)


set(SOURCES "")
foreach (SOURCE_DIR ${SOURCE_DIRS})
    file(GLOB_RECURSE SOURCE_FILE "${SOURCE_DIR}/*.cpp" "${SOURCE_DIR}/*.c")
    list(APPEND SOURCES ${SOURCE_FILE})
endforeach ()
add_compile_options("/utf-8" "/bigobj")

file(COPY ${CMAKE_CURRENT_LIST_DIR}/config/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/config/)

add_executable(${PROJECT_NAME} main.cpp ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIRS})

target_link_directories(${PROJECT_NAME} PRIVATE ${LINK_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBRARIES})

target_compile_definitions(${PROJECT_NAME} PUBLIC
        UNICODE # 启用 windows 的宽字符 API
        NOMINMAX # 防止 windows 库与标准库中的 min、max 冲突
        SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO # 启用日志宏
        CPPHTTPLIB_OPENSSL_SUPPORT # httplib 支持 openssl
        MQTT_STD_VARIANT
)
