cmake_minimum_required(VERSION 3.16)

project(app_bzy_armhf_7 VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(SPDLOG_LIB_PATHS
    ##SPDLOG的绝对路径/
    ${PROJECT_SOURCE_DIR}/../Lib/Spdlog/Android/armv7a
)

set(MVS_LIB_PATHS
    ##MVS库的绝对路径
    ${PROJECT_SOURCE_DIR}/../Lib/mvs/armeabi-v7a
)

set(OPENCV_LIB_PATHS
    ##OPENCV库的绝对路径
    ${PROJECT_SOURCE_DIR}/../Lib/opencv451/staticlibs/armv7a
)

set(OPENCV_LIB_3RDPATHS
    ##第三方库的绝对路径
    ${PROJECT_SOURCE_DIR}/../Lib/opencv451/3rdparty/libs/armeabi-v7a
)

set(SPDLOG_LIB_PATHS
    ##第三方库的绝对路径/
    ${PROJECT_SOURCE_DIR}/../Lib/Spdlog/Android/armv7a
)

set(CURL_LIB_PATHS
    ##第三方库的绝对路径/
    ${PROJECT_SOURCE_DIR}/../Lib/curl
)

set(LWJSON_PATH
    #lwjson库路径
    ${PROJECT_SOURCE_DIR}/../Lib/lwjson-1.8.1
)



find_package(Felgo REQUIRED)
find_package(Qt6 COMPONENTS Core Quick SerialPort Sql Multimedia Mqtt TextToSpeech Positioning Svg NetWork Core5Compat REQUIRED)



# Project identifier and version
# More information: https://felgo.com/doc/felgo-publishing/#project-configuration
set(PRODUCT_IDENTIFIER "com.yfkj.bzyv1")
set(PRODUCT_VERSION_NAME "2.8.25")
set(PRODUCT_VERSION_CODE 102)

# Set either "test" or "publish" stage:
set(PRODUCT_STAGE "publish")

# Optionally set a license key that is used instead of the license key from
# main.qml file (App::licenseKey for your app or GameWindow::licenseKey for your game)
# Only used for local builds and Felgo Cloud Builds (https://felgo.com/cloud-builds)
# Not used if using Felgo Developer App
#set(PRODUCT_LICENSE_KEY "6BBDF824AF729C33ECAA6DC917319EDB8A7F76A9EB5217C380F81C28203CF84078DBCEEC5DB44C7DB60373C0FFE65240DA17EAC1C8376F5939F26782D2A3110CFCDB938C557DDAC8C63F942AF917CD7BCD4235973E76002E69BE740BD2FE99BB7F22AD12408FB5EE3D3A538E604803F0947C372A8486E63B5CF101A18B6CEDF7AEDC615273B15ADBCF1DCC54F123FA093609F650378D2F2BC11C74421663CAB7C178C4123AF6C8B6E44EE45A5A790448F85D4039D7EB1C23C3CA97B42E0724B2987C185114E732662A4EFD507EDC0E5DC2DA7A9FF7754678F48BFC8AAFD40B21926B5A1FD427E279FDE44EC0315229371F4D77B918CC4663CB71572051E1E84DCBF8E183C44981C9D921DB7C5A02879E2D9352ECEC03FF21D99F941B9E31E10D6D625D2603135C101658FEA17FB7B397")
#set(FELGO_PLUGINS)

# Find all QML/JS files for the QML compiler:
file(GLOB_RECURSE QmlFiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} qml/*.qml qml/*.js)

# Find all non-QML/JS files in the qml and assets folder to add as resources:
file(GLOB_RECURSE AssetsFiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} assets/* qml/*)
list(REMOVE_ITEM AssetsFiles ${QmlFiles})

include_directories(header)
include_directories(${PROJECT_SOURCE_DIR}/../Lib/lwjson-1.8.1/include)
include_directories(${PROJECT_SOURCE_DIR}/../Lib/opencv451/header)
include_directories(${PROJECT_SOURCE_DIR}/../Lib/spdlog/header)
include_directories(${PROJECT_SOURCE_DIR}/../Lib/curl/header)
include_directories(${PROJECT_SOURCE_DIR}/../Lib/libuvc/Android-Arm-v8a/header)
include_directories(${PROJECT_SOURCE_DIR}/../Lib/mvs/includes/armhf)

qt_add_executable(app_bzy_armhf_7
    header/main.h
    header/mserial.h

    header/cameramanager.h
    header/SerialEvent.h
    header/m_opencv.h
    header/m_workthread.h
    header/m_json.h
    header/mqtthandler.h
    header/frpcmanager.h
    header/ymodem.h
    header/m_loger.h
    header/EasyTableModel.h
    header/mysql.h
    header/customitem.h
    header/TreeModel.h
    header/app_fileHandle.h
    header/app_curlFunc.h
    header/app_sq_save.h
    header/wif_service.h
    header/ethernet_service.h
    header/app_credentials.h
    header/PermissionBridge.h
    header/slview_focus.h
    header/curl_global.h
    header/ImageStitcher.h

    src/main.cpp
    src/mserial.cpp
    src/cameramanager.cpp
    src/m_opencv.cpp
    src/m_workthread.cpp
    src/m_json.cpp
    src/mqtthandler.cpp
    src/frpcmanager.cpp
    src/ymodem.cpp
    src/m_loger.cpp
    src/EasyTableModel.cpp
    src/mysql.cpp
    src/customitem.cpp
    src/app_curlFunc.cpp
    src/TreeModel.cpp
    src/app_sq_save.cpp
    src/wif_service.cpp
    src/ethernet_service.cpp
    src/PermissionBridge.cpp
    src/slview_focus.cpp
    src/ImageStitcher.cpp
    ${QmlFiles}
    ${AssetsFiles}
)

felgo_configure_executable(app_bzy_armhf_7)

# Deploy resources to build folder/package directly
# comment for publishing
deploy_resources("${QmlFiles};${AssetsFiles}")

# Add QML files and resources to QML module to included them via QRC automatically:
qt_add_qml_module(app_bzy_armhf_7
    URI app_bzy_armhf_7
    VERSION 1.0
# uncomment for publishing:
#    QML_FILES ${QmlFiles}
#    RESOURCES ${AssetsFiles}
    NO_RESOURCE_TARGET_PATH
)


# 使用 CMake 的 FindZLIB 模块
find_package(ZLIB)
if(ZLIB_FOUND)
    message(STATUS "Found zlib: ${ZLIB_LIBRARIES}")
    target_link_libraries(app_bzy_armhf_7 PRIVATE ${ZLIB_LIBRARIES})
    target_include_directories(app_bzy_armhf_7 PRIVATE ${ZLIB_INCLUDE_DIRS})
else()
    message(WARNING "ZLIB not found, trying alternative methods")
endif()


file(GLOB MARKDOWN_FILES "*.md" "docs/*.md")  # 根据你的目录结构调整
# 创建一个虚拟目标，仅用于在 IDE 中显示文件
add_custom_target(docs SOURCES ${MARKDOWN_FILES})

## 链接路径
if(WIN32)
    message(STATUS ${PROJECT_SOURCE_DIR})
    message(STATUS "windows paltform.")
    link_directories(../Lib/Spdlog/win)
    link_directories(../Lib/opencv451/libs/x64/mingw/bin)
    link_directories(../Lib/curl/win)
elseif(ANDROID)
    message(STATUS "android palform.")
    message(STATUS "${PROJECT_SOURCE_DIR}/Lib/Spdlog/Android/armv7a")
    link_directories(${PROJECT_SOURCE_DIR}/Lib/opencv451/staticlibs/armv7a)
    link_directories(${OPENCV_LIB_3RDPATHS})
    link_directories(${PROJECT_SOURCE_DIR}/Lib/opencv451)
endif()

# NOTE: for PUBLISHING, perform the following steps:
# 1. comment the deploy_resources line above, to avoid shipping your qml files with the application (instead they get compiled to the app binary)
# 2. uncomment the QML_FILES and RESOURCES above; this compiles your qml files and js files to the app binary and protects your source code
# 3. change the setMainQmlFile() call in main.cpp to the one starting with "qrc:/" - this loads the qml files from the resources
# for more details see the "Deployment Guides" in the Felgo Documentation

# during development, use the deploy_resources because you then get shorter compilation times (the qml files do not need to be compiled to the binary but are just copied)
# also, for quickest deployment on Desktop disable the "Shadow Build" option in Projects/Builds - you can then select "Run Without Deployment" from the Build menu in Qt Creator if you only changed QML files; this speeds up application start, because your app is not copied & re-compiled but just re-interpreted

target_compile_definitions(app_bzy_armhf_7
    PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)

target_link_libraries(app_bzy_armhf_7 PRIVATE Felgo)
target_link_libraries(app_bzy_armhf_7 PRIVATE
    Qt6::Core
    Qt6::CorePrivate
    Qt6::Quick
    Qt6::SerialPort
    Qt6::Sql
    Qt6::Mqtt
    Qt6::TextToSpeech
    Qt6::Positioning
    Qt6::Svg
    Qt6::Network
    Qt6::Core5Compat
    mediandk)

target_link_libraries(app_bzy_armhf_7
    PRIVATE ${SPDLOG_LIB_PATHS}/libspdlog.a)

target_link_libraries(app_bzy_armhf_7
  PRIVATE ${CURL_LIB_PATHS}/armv7/libcurl.so)

target_link_libraries(app_bzy_armhf_7
  PRIVATE ${LWJSON_PATH}/armv7/liblwjson.a)

target_link_libraries(app_bzy_armhf_7
  PRIVATE
  ${MVS_LIB_PATHS}/libCppUnit_gcc49_v3_0.so
  ${MVS_LIB_PATHS}/libGCBase_gcc49_v3_0.so
  ${MVS_LIB_PATHS}/libGenApi_gcc49_v3_0.so
  ${MVS_LIB_PATHS}/libLog_gcc49_v3_0.so
  ${MVS_LIB_PATHS}/libMathParser_gcc49_v3_0.so
  ${MVS_LIB_PATHS}/libMediaProcess.so
  ${MVS_LIB_PATHS}/libMvCameraControl.so
  ${MVS_LIB_PATHS}/libMvCameraControlWrapper.so
  ${MVS_LIB_PATHS}/libMVGigEVisionSDK.so
  ${MVS_LIB_PATHS}/libMvUsb3vTL.so
  ${MVS_LIB_PATHS}/libNodeMapData_gcc49_v3_0.so
  ${MVS_LIB_PATHS}/libXmlParser_gcc49_v3_0.so)

target_link_libraries(app_bzy_armhf_7
  PRIVATE
  ${OPENCV_LIB_3RDPATHS}/libcpufeatures.a
  ${OPENCV_LIB_3RDPATHS}/libIlmImf.a
  ${OPENCV_LIB_3RDPATHS}/libittnotify.a
  ${OPENCV_LIB_3RDPATHS}/liblibjpeg-turbo.a
  ${OPENCV_LIB_3RDPATHS}/liblibopenjp2.a
  ${OPENCV_LIB_3RDPATHS}/liblibpng.a
  ${OPENCV_LIB_3RDPATHS}/liblibprotobuf.a
  ${OPENCV_LIB_3RDPATHS}/liblibtiff.a
  ${OPENCV_LIB_3RDPATHS}/liblibwebp.a
  ${OPENCV_LIB_3RDPATHS}/libquirc.a
  ${OPENCV_LIB_3RDPATHS}/libtegra_hal.a)

target_link_libraries(app_bzy_armhf_7
  PRIVATE
  ${OPENCV_LIB_PATHS}/libopencv_calib3d.a
  ${OPENCV_LIB_PATHS}/libopencv_core.a
  ${OPENCV_LIB_PATHS}/libopencv_dnn.a
  ${OPENCV_LIB_PATHS}/libopencv_features2d.a
  ${OPENCV_LIB_PATHS}/libopencv_flann.a
  ${OPENCV_LIB_PATHS}/libopencv_gapi.a
  ${OPENCV_LIB_PATHS}/libopencv_highgui.a
  ${OPENCV_LIB_PATHS}/libopencv_imgcodecs.a
  ${OPENCV_LIB_PATHS}/libopencv_imgproc.a
  ${OPENCV_LIB_PATHS}/libopencv_ml.a
  ${OPENCV_LIB_PATHS}/libopencv_objdetect.a
  ${OPENCV_LIB_PATHS}/libopencv_photo.a
  ${OPENCV_LIB_PATHS}/libopencv_stitching.a
  ${OPENCV_LIB_PATHS}/libopencv_video.a
  ${OPENCV_LIB_PATHS}/libopencv_videoio.a
  ${OPENCV_LIB_PATHS}/libopencv_xfeatures2d.a
  ${OPENCV_LIB_PATHS}/libopencv_ximgproc.a
  )



# uncomment this line to add Felgo Hot Reload and use hot reloading with your custom C++ code
# for the remaining steps see here: https://felgo.com/custom-code-reload-app/
# find_package(FelgoHotReload REQUIRED)
# target_link_libraries(appapp_bzy_armhf_7 PRIVATE FelgoHotReload)
if (ANDROID)
    include(F:/Android_Env/android-sdk-windows/android_openssl/CMakeLists.txt)
endif()
