#需要交叉编译时 include include (cross.cmake) #CMake最低版本号要求 cmake_minimum_required(VERSION 3.5.1 FATAL_ERROR) #项目信息 project(DevicePortGetApp) #message(STATUS "Project: SERVER") message(STATUS "DevicePortGetApp CMake version: " ${CMAKE_VERSION}) message(STATUS "DevicePortGetApp CMake system name: " ${CMAKE_SYSTEM_NAME}) message(STATUS "DevicePortGetApp CMake system processor: " ${CMAKE_SYSTEM_PROCESSOR}) # 加入一个配置头文件,用于处理 CMake 对源码的设置 #configure_file ( # "${PROJECT_SOURCE_DIR}/config.h.in" # "${PROJECT_BINARY_DIR}/config.h" # ) #add_definitions("-Wall -g") SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}") SET(CMAKE_C_FLAGS "-DWITH_NO_C_LOCALE") message("${PROJECT_SOURCE_DIR}") message("${PROJECT_BINARY_DIR}") message(STATUS "${CMAKE_C_FLAGS}") #SET(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Debug) #添加头文件目录(类是于 -I) include_directories("src") #新增 20230915 include_directories("src/mslog") include_directories("src/koolootest") include_directories("src/FuncConfigType") #错误用法 #include_directories("src/TimeAligned_Src") #include_directories("src/MainProcess_Src") include_directories("Public_Src") include_directories("Public_Src/cjson") #Mqtt include_directories("Mqtt_src") include_directories("lib/sqlite3/include") include_directories("lib/libmodbus/include") include_directories("soap_sc") include_directories("lib/goahead/include") #将Mqtt库放在工作区 kooloo add 20230925 include_directories("lib/paho.mqtt.c-1.3.12/install/include") #添加需要链接的库文件目录(-L) link_directories("lib/sqlite3/lib") link_directories("lib/libmodbus/lib") link_directories("lib/paho.mqtt.c-1.3.12/install/lib") #链接库文件(-l) #link_libraries("sqlite3") #查找目录下的所有源文件,并将名称保存到 SRC_LIST 变量 aux_source_directory(src SRC_LIST) #新增 20230915 aux_source_directory(src/mslog SRC_LIST) aux_source_directory(src/koolootest SRC_LIST) aux_source_directory(src/FuncConfigType SRC_LIST) #错误用法 内部有main 重复 暂时不动 #aux_source_directory(src/TimeAligned_Src SRC_LIST) #aux_source_directory(MainProcess_Src SRC_LIST) aux_source_directory(Public_Src SRC_LIST) aux_source_directory(Public_Src/cjson SRC_LIST) aux_source_directory(soap_sc SRC_LIST) # 指定生成目标 ADD_EXECUTABLE(DevicePortGetApp ${SRC_LIST}) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) # 添加链接库(dl:动态库加载、pthread:线程库、rt:运行时函数库(#include)、m:数学库) TARGET_LINK_LIBRARIES(DevicePortGetApp dl) TARGET_LINK_LIBRARIES(DevicePortGetApp pthread) TARGET_LINK_LIBRARIES(DevicePortGetApp ${CMAKE_CURRENT_SOURCE_DIR}/lib/sqlite3/lib/libsqlite3.so) TARGET_LINK_LIBRARIES(DevicePortGetApp ${CMAKE_CURRENT_SOURCE_DIR}/lib/libmodbus/lib/libmodbus.so) TARGET_LINK_LIBRARIES(DevicePortGetApp ${CMAKE_CURRENT_SOURCE_DIR}/lib/paho.mqtt.c-1.3.12/install/lib/libpaho-mqtt3c.so) TARGET_LINK_LIBRARIES(DevicePortGetApp rt) #TARGET_LINK_LIBRARIES(DevicePortGetApp m) #MQTT库文件搜索路径 #target_link_libraries(mqttClient PRIVATE paho-mqtt3c) #MQTT链接库 libpaho-mqtt3c.so #添加子目录(子目录编译为库或子程序时使用) ADD_SUBDIRECTORY(soap_sc) ADD_SUBDIRECTORY(web_src) ADD_SUBDIRECTORY(Mqtt_src) ADD_SUBDIRECTORY(TimeAligned_Src) ADD_SUBDIRECTORY(MainProcess_Src) ADD_SUBDIRECTORY(Uart_passthrough)