cmake_minimum_required (VERSION 3.20) project (application C CXX) set (VERSION 1.0.1) # 指定C++标准 set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) option (USE_MQTT "use mqtt protocol" OFF) option (USE_WEBSOCKET "use websocket" ON) option (USE_SQLITE3 "use sqlite3" ON) option (USE_ADS "use ads" ON) if (USE_SQLITE3) option (USE_SQLITE_CONFIG "use sqlite config" OFF) if (USE_SQLITE_CONFIG) add_definitions(-DUSE_SQLITE_CONFIG) message (STATUS "Using sqlite3 config file.") endif () endif () set (CMAKE_BUILD_TYPE "Release") option (USE_32BITS "Build 32Bits application?" OFF) if (USE_32BITS) message (STATUS "Using 32Bits Platform: ${CMAKE_SYSTEM_PROCESSOR} host: ${CMAKE_HOST_SYSTEM_PROCESSOR}") if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") add_compile_options (-m32) add_link_options (-m32) endif() add_definitions(-DUSE_32BITS) else () message (STATUS "Using 64Bits Platform") add_definitions(-DNOPOLL_64BIT_PLATFORM) endif (USE_32BITS) if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") SET (CMAKE_BUILD_TYPE "Debug") endif () if (CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Debug")) add_compile_options ("-O0") add_compile_options ("-Wall") message("Debug mode:${CMAKE_C_FLAGS_DEBUG}") elseif (CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Release")) add_compile_options ("-O3") add_compile_options ("-Wall") message ("Release mode:${CMAKE_C_FLAGS_RELEASE}") else () message ("else:${CMAKE_BUILD_TYPE}") message ("else:${CMAKE_C_FLAGS_RELEASE}") endif() if(CMAKE_SIZEOF_VOID_P EQUAL 4) message(STATUS "Target platform is 32-bit.") add_definitions(-DUSE_32BITS) else() message(STATUS "Target platform is 64-bit.") endif() find_package(miniocpp REQUIRED) set (APP_LIBS ${APP_LIBS} miniocpp::miniocpp) # target_link_libraries(application PRIVATE miniocpp::miniocpp) include_directories ( inc inc/json inc/uuid inc/sqlite inc/nopoll inc/websockets inc/crypto cmg/ inc/mqtt) set (APP_SRCS cmg/main.cpp cmg/changemaster.cpp cmg/ry.cpp comm/ryFileDef.cpp comm/process.cpp comm/netproc.cpp comm/portproc.cpp comm/public.cpp comm/soe.cpp comm/ycbw.cpp comm/yklog.cpp comm/ytlog.cpp comm/yxbw.cpp comm/iec104.cpp hostiec104/host_iec104.cpp hostmodbusrtu/host_modbus_rtu.cpp hostmodbustcp/host_modbus_tcp.cpp hostmodbustcpbf/host_modbus_tcp_bf.cpp rtustatusproc/rtustatus.cpp subiec104/sub_iec104.cpp submodbustcp/sub_modbus_tcp.cpp zjd3100proc/zjd3100pro.cpp minio/ftp2minio.cpp ) set (APP_SRCS ${APP_SRCS} third_party/json/jsoncpp.cpp) set (APP_SRCS ${APP_SRCS} third_party/base64/base64.c third_party/md5/md5.c third_party/aes/aes.c third_party/aes/error.c third_party/aes/platform_util.c) set (APP_SRCS ${APP_SRCS} third_party/uuid/clear.c third_party/uuid/compare.c third_party/uuid/copy.c third_party/uuid/gen_uuid.c third_party/uuid/isnull.c third_party/uuid/pack.c third_party/uuid/parse.c third_party/uuid/unpack.c third_party/uuid/unparse.c third_party/uuid/uuid_time.c third_party/uuid/randutils.c) set (APP_SRCS ${APP_SRCS} third_party/zlog/buf.c third_party/zlog/category_table.c third_party/zlog/category.c third_party/zlog/conf.c third_party/zlog/event.c third_party/zlog/format.c third_party/zlog/level_list.c third_party/zlog/level.c third_party/zlog/mdc.c third_party/zlog/record_table.c third_party/zlog/record.c third_party/zlog/rotater.c third_party/zlog/rule.c third_party/zlog/spec.c third_party/zlog/thread.c third_party/zlog/zc_arraylist.c third_party/zlog/zc_hashtable.c third_party/zlog/zc_profile.c third_party/zlog/zc_util.c third_party/zlog/zlog.c) if (USE_WEBSOCKET) set (APP_SRCS ${APP_SRCS} third_party/websockets/easywsclient.cpp ) # find_package(websockets) # set (APP_LIBS ${APP_LIBS} websockets) # set (APP_SRCS ${APP_SRCS} # third_party/nopoll/nopoll.c # third_party/nopoll/nopoll_conn.c # third_party/nopoll/nopoll_conn_opts.c # third_party/nopoll/nopoll_listener.c # third_party/nopoll/nopoll_ctx.c # third_party/nopoll/nopoll_decl.c # third_party/nopoll/nopoll_io.c # third_party/nopoll/nopoll_log.c # third_party/nopoll/nopoll_msg.c) set (APP_LIBS ${APP_LIBS} ssl crypto) # add_definitions(-DUSE_WEBSOCKET) # add_definitions(-DNOPOLL_OS_UNIX=1) # add_definitions(-DSHOW_DEBUG_LOG) # add_definitions(-DNOPOLL_HAVE_VASPRINTF=1) # add_definitions(-DNOPOLL_HAVE_TLSv10_ENABLED=1) # add_definitions(-DNOPOLL_HAVE_TLSv11_ENABLED=1) # add_definitions(-DNOPOLL_HAVE_TLSv12_ENABLED=1) # add_definitions(-DNOPOLL_HAVE_TLS_FLEXIBLE_ENABLED=1) endif () if (USE_ADS) add_definitions(-DCONFIG_DEFAULT_LOGLEVEL=1) include_directories (third_party/AdsLib) set (APP_SRCS ${APP_SRCS} hostadsbf/hostadsbf.cpp) set (APP_SRCS ${APP_SRCS} third_party/AdsLib/AdsDef.cpp third_party/AdsLib/AdsDevice.cpp third_party/AdsLib/AdsFile.cpp third_party/AdsLib/AdsLib.cpp third_party/AdsLib/ECatAccess.cpp third_party/AdsLib/Frame.cpp third_party/AdsLib/LicenseAccess.cpp third_party/AdsLib/Log.cpp third_party/AdsLib/RouterAccess.cpp third_party/AdsLib/RTimeAccess.cpp third_party/AdsLib/Sockets.cpp third_party/AdsLib/RegistryAccess.cpp third_party/AdsLib/SymbolAccess.cpp third_party/AdsLib/Beckhoff/ParameterList.cpp third_party/AdsLib/Standalone/AdsLib.cpp third_party/AdsLib/Standalone/AmsConnection.cpp third_party/AdsLib/Standalone/AmsNetId.cpp third_party/AdsLib/Standalone/AmsPort.cpp third_party/AdsLib/Standalone/AmsRouter.cpp third_party/AdsLib/Standalone/NotificationDispatcher.cpp ) endif () if (USE_MQTT) set(APP_SRCS ${APP_SRCS} third_party/mqtt/actions.c third_party/mqtt/callbacks.c third_party/mqtt/connect.c third_party/mqtt/handle_auth.c third_party/mqtt/handle_connack.c third_party/mqtt/handle_disconnect.c third_party/mqtt/handle_ping.c third_party/mqtt/handle_pubackcomp.c third_party/mqtt/handle_publish.c third_party/mqtt/handle_pubrec.c third_party/mqtt/handle_pubrel.c third_party/mqtt/handle_suback.c third_party/mqtt/handle_unsuback.c third_party/mqtt/helpers.c third_party/mqtt/logging_mosq.c third_party/mqtt/loop.c third_party/mqtt/memory_mosq.c third_party/mqtt/messages_mosq.c third_party/mqtt/misc_mosq.c third_party/mqtt/mosquitto.c third_party/mqtt/net_mosq_ocsp.c third_party/mqtt/net_mosq.c third_party/mqtt/options.c third_party/mqtt/packet_datatypes.c third_party/mqtt/packet_mosq.c third_party/mqtt/property_mosq.c third_party/mqtt/read_handle.c third_party/mqtt/send_connect.c third_party/mqtt/send_disconnect.c third_party/mqtt/send_mosq.c third_party/mqtt/send_publish.c third_party/mqtt/send_subscribe.c third_party/mqtt/send_unsubscribe.c third_party/mqtt/send_mosq.c third_party/mqtt/socks_mosq.c third_party/mqtt/srv_mosq.c third_party/mqtt/strings_mosq.c third_party/mqtt/thread_mosq.c third_party/mqtt/time_mosq.c third_party/mqtt/tls_mosq.c third_party/mqtt/utf8_mosq.c third_party/mqtt/util_mosq.c third_party/mqtt/util_topic.c third_party/mqtt/will_mosq.c) # set (APP_SRCS ${APP_SRCS} hwmqtt/hwmqtt.cpp) add_definitions(-DUSE_MQTT) add_definitions(-DWITH_SOCKS) add_definitions(-DWITH_THREADING) add_definitions(-DWITH_UNIX_SOCKETS) # add_definitions(-DWITH_TLS) # add_definitions(-DWITH_TLS_PSK) endif (USE_MQTT) if (USE_SQLITE3) set (APP_SRCS ${APP_SRCS} third_party/sqlite/KompexSQLiteBlob.cpp third_party/sqlite/KompexSQLiteDatabase.cpp third_party/sqlite/KompexSQLiteStatement.cpp third_party/sqlite/sqlite3.c) add_definitions(-DUSE_SQLITE3) endif () include_directories ("${CMAKE_CURRENT_BINARY_DIR}") link_directories (${LINK_DIR}) set (APP_LIBS ${APP_LIBS} pthread) set (APP_LIBS ${APP_LIBS} dl) set (APP_LIBS ${APP_LIBS} rt) #add_link_options (-static) add_executable (application ${APP_SRCS}) target_link_libraries (application ${APP_LIBS})