192 lines
6.8 KiB
CMake
192 lines
6.8 KiB
CMake
# The Flutter tooling requires that developers have a version of Visual Studio
|
||
# installed that includes CMake 3.14 or later. You should not increase this
|
||
# version, as doing so will cause the plugin to fail to compile for some
|
||
# customers of the plugin.
|
||
cmake_minimum_required(VERSION 3.14)
|
||
|
||
# Project-level configuration.
|
||
set(PROJECT_NAME "flutter_openim_sdk")
|
||
project(${PROJECT_NAME} LANGUAGES CXX)
|
||
|
||
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
|
||
# versions of CMake.
|
||
cmake_policy(VERSION 3.14...3.25)
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
# 定义一个函数用于下载和解压SDK
|
||
# 参数:
|
||
# DOWNLOAD_URL - 下载URL
|
||
# TARGET_DIR - 目标目录
|
||
function(download_and_extract_sdk)
|
||
# 解析参数
|
||
set(oneValueArgs DOWNLOAD_URL TARGET_DIR)
|
||
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "${oneValueArgs}" "")
|
||
|
||
if(NOT ARG_DOWNLOAD_URL OR NOT ARG_TARGET_DIR)
|
||
message(FATAL_ERROR "DOWNLOAD_URL and TARGET_DIR must be specified")
|
||
endif()
|
||
|
||
# 从URL中提取文件名
|
||
set(SPLIT "download=")
|
||
string(LENGTH ${SPLIT} SPLIT_LENGTH)
|
||
string(LENGTH ${ARG_DOWNLOAD_URL} URL_LENGTH)
|
||
string(FIND ${ARG_DOWNLOAD_URL} ${SPLIT} POS)
|
||
|
||
if(POS GREATER_EQUAL 0)
|
||
math(EXPR SPLIT_POS "${POS}+${SPLIT_LENGTH}")
|
||
string(SUBSTRING ${ARG_DOWNLOAD_URL} ${SPLIT_POS} ${URL_LENGTH} FILE_NAME)
|
||
else()
|
||
# 如果没有找到分割字符串,使用默认文件名
|
||
set(FILE_NAME "sdk_package.tar.gz")
|
||
endif()
|
||
|
||
# 设置完整文件路径
|
||
set(FULL_PATH "${ARG_TARGET_DIR}/${FILE_NAME}")
|
||
|
||
# 检查文件是否存在且大小不为0
|
||
if(EXISTS "${FULL_PATH}")
|
||
file(SIZE "${FULL_PATH}" FILE_SIZE)
|
||
if(NOT ${FILE_SIZE})
|
||
file(REMOVE_RECURSE "${FULL_PATH}")
|
||
endif()
|
||
endif()
|
||
|
||
# 下载和解压
|
||
if(NOT EXISTS "${FULL_PATH}")
|
||
file(MAKE_DIRECTORY ${ARG_TARGET_DIR})
|
||
message("[download_sdk]: 开始从 ${ARG_DOWNLOAD_URL} 下载SDK")
|
||
|
||
# 下载文件
|
||
file(DOWNLOAD ${ARG_DOWNLOAD_URL} ${FULL_PATH}
|
||
STATUS DOWNLOAD_STATUS
|
||
LOG DOWNLOAD_LOG)
|
||
|
||
list(GET DOWNLOAD_STATUS 0 STATUS_CODE)
|
||
if(NOT STATUS_CODE EQUAL 0)
|
||
message(FATAL_ERROR "[download_sdk]: 下载失败: ${DOWNLOAD_STATUS}, 日志: ${DOWNLOAD_LOG}")
|
||
endif()
|
||
|
||
message("[download_sdk]: 下载完成")
|
||
else()
|
||
message("[download_sdk]: SDK包已存在,跳过下载")
|
||
endif()
|
||
|
||
message("[download_sdk]: 开始解压 ${FILE_NAME}")
|
||
file(ARCHIVE_EXTRACT
|
||
INPUT ${FULL_PATH}
|
||
DESTINATION ${ARG_TARGET_DIR})
|
||
message("[download_sdk]: 解压完成")
|
||
endfunction()
|
||
|
||
# third_party
|
||
set(ALOG_SDK_URL "http://192.168.77.132:8081/repository/mvn2-group/com/alog/1.0/alog-1.0.zip?download=alog-1.0.zip")
|
||
|
||
download_and_extract_sdk(
|
||
DOWNLOAD_URL ${ALOG_SDK_URL}
|
||
TARGET_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party
|
||
)
|
||
|
||
# openim
|
||
set(OPENIM_SDK_URL "http://192.168.77.132:8081/repository/mvn2-group/com/openim_pc/1.0.0/openim_pc-1.0.0.zip?download=openim_pc-1.0.0.zip")
|
||
|
||
download_and_extract_sdk(
|
||
DOWNLOAD_URL ${OPENIM_SDK_URL}
|
||
TARGET_DIR ${CMAKE_CURRENT_SOURCE_DIR}/openlib
|
||
)
|
||
# This value is used when generating builds using this plugin, so it must
|
||
# not be changed
|
||
set(PLUGIN_NAME "flutter_openim_sdk_plugin")
|
||
set(PCH_HEADER_FILE ${CMAKE_CURRENT_LIST_DIR}/src/common/stable.h)
|
||
|
||
# third_party_libs
|
||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party/alog/include")
|
||
link_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party/alog/lib/x64/${CMAKE_BUILD_TYPE}")
|
||
|
||
FILE(GLOB SELF_TEMP_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.cpp src/*.h)
|
||
source_group(src FILES ${SELF_TEMP_SRC_FILES})
|
||
list(APPEND NIM_CORE_SOURCES ${SELF_TEMP_SRC_FILES})
|
||
|
||
FILE(GLOB SELF_TEMP_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/common/*.cpp src/common/*.h)
|
||
source_group(src/common FILES ${SELF_TEMP_SRC_FILES})
|
||
list(APPEND NIM_CORE_SOURCES ${SELF_TEMP_SRC_FILES})
|
||
|
||
FILE(GLOB SELF_TEMP_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/common/services/*.cpp src/common/services/*.h)
|
||
source_group(src/common/services FILES ${SELF_TEMP_SRC_FILES})
|
||
list(APPEND NIM_CORE_SOURCES ${SELF_TEMP_SRC_FILES})
|
||
|
||
FILE(GLOB SELF_TEMP_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/common/utils/*.cpp src/common/utils/*.h src/common/utils/*.hpp)
|
||
source_group(src/common/utils FILES ${SELF_TEMP_SRC_FILES})
|
||
list(APPEND NIM_CORE_SOURCES ${SELF_TEMP_SRC_FILES})
|
||
|
||
FILE(GLOB SELF_TEMP_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/utils/*.cpp src/utils/*.h)
|
||
source_group(src/utils FILES ${SELF_TEMP_SRC_FILES})
|
||
list(APPEND NIM_CORE_SOURCES ${SELF_TEMP_SRC_FILES})
|
||
|
||
FILE(GLOB SELF_TEMP_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/utils/dump/*.cpp src/utils/dump/*.h)
|
||
source_group(src/utils/dump FILES ${SELF_TEMP_SRC_FILES})
|
||
list(APPEND NIM_CORE_SOURCES ${SELF_TEMP_SRC_FILES})
|
||
|
||
# Any new source files that you add to the plugin should be added here.
|
||
list(APPEND PLUGIN_SOURCES
|
||
${CMAKE_CURRENT_LIST_DIR}/flutter_openim_sdk_plugin.cpp
|
||
)
|
||
|
||
add_library(${PLUGIN_NAME} SHARED
|
||
${PLUGIN_SOURCES}
|
||
${NIM_CORE_SOURCES}
|
||
)
|
||
target_precompile_headers(${PLUGIN_NAME} PRIVATE ${PCH_HEADER_FILE})
|
||
target_link_libraries(${PLUGIN_NAME} PRIVATE yx_alog)
|
||
|
||
# Apply a standard set of build settings that are configured in the
|
||
# application-level CMakeLists.txt. This can be removed for plugins that want
|
||
# full control over build settings.
|
||
apply_standard_settings(${PLUGIN_NAME})
|
||
|
||
# Symbols are hidden by default to reduce the chance of accidental conflicts
|
||
# between plugins. This should not be removed; any symbols that should be
|
||
# exported should be explicitly exported with the FLUTTER_PLUGIN_EXPORT macro.
|
||
set_target_properties(${PLUGIN_NAME} PROPERTIES
|
||
CXX_VISIBILITY_PRESET hidden)
|
||
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
|
||
target_compile_options(${PLUGIN_NAME} PRIVATE /W4 /WX- /wd4100 /wd4267 /wd4189 /wd4244 /wd4996 /bigobj /utf-8)
|
||
|
||
target_include_directories(${PLUGIN_NAME} PUBLIC
|
||
"${CMAKE_CURRENT_LIST_DIR}/include"
|
||
"${CMAKE_CURRENT_LIST_DIR}/"
|
||
"${CMAKE_CURRENT_LIST_DIR}/openlib/x64/include"
|
||
)
|
||
|
||
target_link_libraries(${PLUGIN_NAME} PRIVATE
|
||
flutter
|
||
flutter_wrapper_plugin
|
||
${CMAKE_CURRENT_LIST_DIR}/openlib/x64/libopenimsdk.lib
|
||
)
|
||
|
||
|
||
|
||
file(GLOB flutter_openim_sdk_bundled_libraries
|
||
"${CMAKE_CURRENT_LIST_DIR}/openlib/x64/*.dll"
|
||
)
|
||
|
||
file(GLOB LIBRARY_FILES "${CMAKE_CURRENT_LIST_DIR}/openlib/x64/*")
|
||
foreach(LIB_FILE ${LIBRARY_FILES})
|
||
if(LIB_FILE MATCHES "cacert\.pem")
|
||
# 添加库文件路径到变量
|
||
list(APPEND flutter_openim_sdk_bundled_libraries ${LIB_FILE})
|
||
endif()
|
||
endforeach()
|
||
|
||
set(flutter_openim_sdk_bundled_libraries ${flutter_openim_sdk_bundled_libraries} PARENT_SCOPE)
|
||
|
||
|
||
|
||
#install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/openlib/libopenimsdk.dll
|
||
# DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
|
||
#)
|