EMS/CMakeLists.txt

154 lines
4.0 KiB
CMake
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#指定cmake最低版本
cmake_minimum_required(VERSION 3.14)
#x86平台
# set(CMAKE_C_COMPILER gcc)
# set(CMAKE_CXX_COMPILER g++)
#交叉编译
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")
# 设置一个字符串变量,用与编译文件名称生成
set(ProjectName "EMS_C_V")
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)
# 添加头文件路径
include_directories(
${PROJECT_SOURCE_DIR}/alg
${PROJECT_SOURCE_DIR}/app
${PROJECT_SOURCE_DIR}/kit
${PROJECT_SOURCE_DIR}/bsp
${PROJECT_SOURCE_DIR}/drv
${PROJECT_SOURCE_DIR}/lib
${PROJECT_SOURCE_DIR}/model
${PROJECT_SOURCE_DIR}/test
)
# 添加驱动源文件
set(DRV_SOURCE
# DI驱动源文件
${PROJECT_SOURCE_DIR}/drv/drv_di.c
# DO驱动源文件
${PROJECT_SOURCE_DIR}/drv/drv_do.c
# UART驱动源文件
${PROJECT_SOURCE_DIR}/drv/drv_uart.c
# CAN驱动源文件
${PROJECT_SOURCE_DIR}/drv/drv_can.c
# TCP驱动源文件
${PROJECT_SOURCE_DIR}/drv/drv_tcp.c
# 4G驱动源文件
${PROJECT_SOURCE_DIR}/drv/drv_4g.c
# CAN驱动源文件
${PROJECT_SOURCE_DIR}/drv/drv_can.c
)
# 添加KIT源文件
set(KIT_SOURCE
# Logger kit源文件
${PROJECT_SOURCE_DIR}/kit/kit_logger.c
${PROJECT_SOURCE_DIR}/kit/kit_safe_memcpy.c
${PROJECT_SOURCE_DIR}/kit/kit_mqtt.c
${PROJECT_SOURCE_DIR}/kit/kit_mqtt_sub.c
${PROJECT_SOURCE_DIR}/kit/kit_xml.c
)
# 添加库头文件
include_directories(
${PROJECT_SOURCE_DIR}/lib/libsqlite3/include
${PROJECT_SOURCE_DIR}/lib/libxml2/include/
${PROJECT_SOURCE_DIR}/lib/libxml2/include/libxml2
${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
)
add_executable(${ProjectName}
main.c
# 测试代码源文件
${PROJECT_SOURCE_DIR}/test/test.c
# 驱动代码源文件
${DRV_SOURCE}
# 插件代码源文件
${KIT_SOURCE}
)
# 添加编译选项
target_compile_options(${ProjectName} PRIVATE -fno-stack-protector)
# 添加库路径
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)
# 添加链接库
target_link_libraries(${ProjectName} PRIVATE
${LIB_PTHREAD}
${LIB_SQLITE3}
${LIB_XML2}
${LIB_SSL}
${LIB_CRYPTO}
${LIB_CJSON}
${LIB_MODBUS}
${LIB_MQTT3A}
${LIB_MQTT3AS}
${LIB_MQTT3C}
${LIB_MQTT3CS}
)
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()
# 拷贝文件
# file(GLOB SQL_SCHEMAS ${CMAKE_SOURCE_DIR}/config/*.sql)
# file(COPY ${SQL_SCHEMAS} DESTINATION ${CMAKE_BINARY_DIR}/config)
# 指定工作目录
# install(TARGETS ${ProjectName} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})