2024-10-31 17:52:29 +08:00
|
|
|
|
#指定cmake最低版本
|
2024-11-21 13:27:37 +08:00
|
|
|
|
cmake_minimum_required(VERSION 3.14)
|
2024-10-31 17:52:29 +08:00
|
|
|
|
|
|
|
|
|
#x86平台
|
|
|
|
|
# set(CMAKE_C_COMPILER gcc)
|
|
|
|
|
# set(CMAKE_CXX_COMPILER g++)
|
2024-11-04 16:59:51 +08:00
|
|
|
|
|
2024-10-31 17:52:29 +08:00
|
|
|
|
#交叉编译
|
|
|
|
|
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
|
|
|
|
|
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
|
|
|
|
|
|
|
|
|
|
set(CMAKE_BUILD_TYPE "Debug")
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
|
|
|
|
|
|
|
|
|
|
# 设置一个字符串变量,用与编译文件名称生成
|
2024-11-22 09:44:21 +08:00
|
|
|
|
set(ProjectName "EMS_C_V")
|
2024-10-31 17:52:29 +08:00
|
|
|
|
|
2024-11-21 13:27:37 +08:00
|
|
|
|
project(${ProjectName} LANGUAGES C)
|
|
|
|
|
|
|
|
|
|
# 设置 C 标准
|
|
|
|
|
set(CMAKE_C_STANDARD 11)
|
|
|
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
|
|
|
|
|
|
|
|
# 设置编译类型(Debug 或 Release)
|
|
|
|
|
set(CMAKE_BUILD_TYPE Debug)
|
|
|
|
|
|
|
|
|
|
add_definitions(-DHARDWARE_TYPE=1)
|
2024-10-31 17:52:29 +08:00
|
|
|
|
|
2024-11-04 16:59:51 +08:00
|
|
|
|
# 添加头文件路径
|
2024-10-31 17:52:29 +08:00
|
|
|
|
include_directories(
|
2024-11-04 16:59:51 +08:00
|
|
|
|
${PROJECT_SOURCE_DIR}/alg
|
2024-10-31 17:52:29 +08:00
|
|
|
|
${PROJECT_SOURCE_DIR}/app
|
|
|
|
|
${PROJECT_SOURCE_DIR}/kit
|
|
|
|
|
${PROJECT_SOURCE_DIR}/bsp
|
|
|
|
|
${PROJECT_SOURCE_DIR}/drv
|
|
|
|
|
${PROJECT_SOURCE_DIR}/lib
|
|
|
|
|
${PROJECT_SOURCE_DIR}/model
|
2024-11-04 16:59:51 +08:00
|
|
|
|
${PROJECT_SOURCE_DIR}/test
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 添加驱动源文件
|
|
|
|
|
set(DRV_SOURCE
|
|
|
|
|
# DI驱动源文件
|
|
|
|
|
${PROJECT_SOURCE_DIR}/drv/drv_di.c
|
|
|
|
|
# DO驱动源文件
|
|
|
|
|
${PROJECT_SOURCE_DIR}/drv/drv_do.c
|
2024-11-12 08:21:37 +08:00
|
|
|
|
# UART驱动源文件
|
|
|
|
|
${PROJECT_SOURCE_DIR}/drv/drv_uart.c
|
2024-11-13 15:23:09 +08:00
|
|
|
|
# CAN驱动源文件
|
|
|
|
|
${PROJECT_SOURCE_DIR}/drv/drv_can.c
|
2024-11-13 14:46:59 +08:00
|
|
|
|
# TCP驱动源文件
|
|
|
|
|
${PROJECT_SOURCE_DIR}/drv/drv_tcp.c
|
2024-11-20 16:11:23 +08:00
|
|
|
|
# 4G驱动源文件
|
|
|
|
|
${PROJECT_SOURCE_DIR}/drv/drv_4g.c
|
|
|
|
|
# CAN驱动源文件
|
|
|
|
|
${PROJECT_SOURCE_DIR}/drv/drv_can.c
|
2024-11-04 16:59:51 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 添加KIT源文件
|
|
|
|
|
set(KIT_SOURCE
|
|
|
|
|
# Logger kit源文件
|
|
|
|
|
${PROJECT_SOURCE_DIR}/kit/kit_logger.c
|
2024-11-21 13:27:37 +08:00
|
|
|
|
${PROJECT_SOURCE_DIR}/kit/kit_safe_memcpy.c
|
2024-11-22 09:44:21 +08:00
|
|
|
|
${PROJECT_SOURCE_DIR}/kit/kit_mqtt.c
|
|
|
|
|
${PROJECT_SOURCE_DIR}/kit/kit_mqtt_sub.c
|
2024-11-21 13:27:37 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 添加库头文件
|
|
|
|
|
include_directories(
|
|
|
|
|
${PROJECT_SOURCE_DIR}/lib/libsqlite3/include
|
|
|
|
|
${PROJECT_SOURCE_DIR}/lib/libxml2/include
|
|
|
|
|
${PROJECT_SOURCE_DIR}/lib/libssl/include
|
|
|
|
|
${PROJECT_SOURCE_DIR}/lib/libcjson/include
|
|
|
|
|
${PROJECT_SOURCE_DIR}/lib/libmodbus/include
|
|
|
|
|
${PROJECT_SOURCE_DIR}/lib/libpaho-mqtt/include
|
2024-10-31 17:52:29 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
add_executable(${ProjectName}
|
|
|
|
|
main.c
|
2024-11-05 17:17:30 +08:00
|
|
|
|
# 测试代码源文件
|
2024-11-04 16:59:51 +08:00
|
|
|
|
${PROJECT_SOURCE_DIR}/test/test.c
|
2024-11-05 17:17:30 +08:00
|
|
|
|
# 驱动代码源文件
|
2024-11-04 16:59:51 +08:00
|
|
|
|
${DRV_SOURCE}
|
2024-11-05 17:17:30 +08:00
|
|
|
|
# 插件代码源文件
|
2024-11-04 16:59:51 +08:00
|
|
|
|
${KIT_SOURCE}
|
2024-10-31 17:52:29 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 添加编译选项
|
|
|
|
|
target_compile_options(${ProjectName} PRIVATE -fno-stack-protector)
|
|
|
|
|
|
|
|
|
|
# 添加库路径
|
2024-11-21 13:52:16 +08:00
|
|
|
|
find_library(LIB_PTHREAD NAMES pthread PATHS /usr/aarch64-linux-gnu/lib)
|
|
|
|
|
find_library(LIB_SQLITE3 NAMES sqlite3 PATHS lib/libsqlite3/lib)
|
|
|
|
|
find_library(LIB_XML2 NAMES xml2 PATHS lib/libxml2/lib)
|
|
|
|
|
find_library(LIB_SSL NAMES ssl PATHS lib/libssl/lib)
|
|
|
|
|
find_library(LIB_CRYPTO NAMES crypto PATHS lib/libssl/lib)
|
|
|
|
|
find_library(LIB_CJSON NAMES cjson PATHS lib/libcjson/lib)
|
|
|
|
|
find_library(LIB_MODBUS NAMES modbus PATHS lib/libmodbus/lib)
|
|
|
|
|
find_library(LIB_MQTT3A NAMES paho-mqtt3a PATHS lib/libpaho-mqtt/lib)
|
|
|
|
|
find_library(LIB_MQTT3AS NAMES paho-mqtt3as PATHS lib/libpaho-mqtt/lib)
|
|
|
|
|
find_library(LIB_MQTT3C NAMES paho-mqtt3c PATHS lib/libpaho-mqtt/lib)
|
|
|
|
|
find_library(LIB_MQTT3CS NAMES paho-mqtt3cs PATHS lib/libpaho-mqtt/lib)
|
2024-11-21 13:27:37 +08:00
|
|
|
|
|
|
|
|
|
# 添加链接库
|
|
|
|
|
target_link_libraries(${ProjectName} PRIVATE
|
|
|
|
|
${LIB_PTHREAD}
|
|
|
|
|
${LIB_SQLITE3}
|
|
|
|
|
${LIB_XML2}
|
|
|
|
|
${LIB_SSL}
|
|
|
|
|
${LIB_CRYPTO}
|
|
|
|
|
${LIB_CJSON}
|
|
|
|
|
${LIB_MODBUS}
|
2024-11-21 13:52:16 +08:00
|
|
|
|
${LIB_MQTT3A}
|
|
|
|
|
${LIB_MQTT3AS}
|
|
|
|
|
${LIB_MQTT3C}
|
|
|
|
|
${LIB_MQTT3CS}
|
2024-10-31 17:52:29 +08:00
|
|
|
|
)
|
|
|
|
|
|
2024-11-21 13:27:37 +08:00
|
|
|
|
if(NOT LIB_PTHREAD)
|
|
|
|
|
message("LIB_PTHREAD not found!")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(NOT LIB_SQLITE3)
|
|
|
|
|
message("LIB_SQLITE3 not found!")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(NOT LIB_XML2)
|
|
|
|
|
message("LIB_XML2 not found!")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(NOT LIB_SSL)
|
|
|
|
|
message("LIB_SSL not found!")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(NOT LIB_CRYPTO)
|
|
|
|
|
message("LIB_CRYPTO not found!")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(NOT LIB_CJSON)
|
|
|
|
|
message("LIB_CJSON not found!")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(NOT LIB_MODBUS)
|
|
|
|
|
message("LIB_MODBUS not found!")
|
|
|
|
|
endif()
|
2024-10-31 17:52:29 +08:00
|
|
|
|
|
|
|
|
|
# 拷贝文件
|
2024-11-21 13:27:37 +08:00
|
|
|
|
# file(GLOB SQL_SCHEMAS ${CMAKE_SOURCE_DIR}/config/*.sql)
|
|
|
|
|
# file(COPY ${SQL_SCHEMAS} DESTINATION ${CMAKE_BINARY_DIR}/config)
|
2024-10-31 17:52:29 +08:00
|
|
|
|
|
|
|
|
|
# 指定工作目录
|
|
|
|
|
# install(TARGETS ${ProjectName} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|