include(FetchContent) # nlohmann_json FetchContent_Declare( nlohmann_json GIT_REPOSITORY https://github.com/nlohmann/json.git GIT_TAG v3.11.3 GIT_SHALLOW TRUE ) FetchContent_MakeAvailable(nlohmann_json) # standalone asio FetchContent_Declare( asio GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git GIT_TAG asio-1-30-2 GIT_SHALLOW TRUE ) FetchContent_GetProperties(asio) if(NOT asio_POPULATED) FetchContent_Populate(asio) add_library(asio INTERFACE) target_include_directories(asio INTERFACE ${asio_SOURCE_DIR}/asio/include) target_compile_definitions(asio INTERFACE ASIO_STANDALONE ASIO_NO_DEPRECATED) if(WIN32) target_compile_definitions(asio INTERFACE _WIN32_WINNT=0x0601) endif() endif() # open62541 (vendored: third_party/open62541, tag v1.4.6) if(SOFTBUS_WITH_OPCUA) set(_softbus_open62541_dir "${CMAKE_SOURCE_DIR}/third_party/open62541") if(NOT EXISTS "${_softbus_open62541_dir}/CMakeLists.txt") message(FATAL_ERROR "open62541 vendor tree not found at ${_softbus_open62541_dir}. " "Expected third_party/open62541 (v1.4.6).") endif() set(UA_ENABLE_AMALGAMATION OFF CACHE BOOL "" FORCE) if(MINGW) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-protector") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-stack-protector") endif() set(_softbus_saved_build_shared ${BUILD_SHARED_LIBS}) set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) set(UA_ENABLE_SUBSCRIPTIONS ON CACHE BOOL "" FORCE) set(UA_ENABLE_METHODCALLS ON CACHE BOOL "" FORCE) set(UA_ENABLE_DISCOVERY ON CACHE BOOL "" FORCE) set(UA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(UA_BUILD_UNIT_TESTS OFF CACHE BOOL "" FORCE) set(UA_ENABLE_ENCRYPTION OFF CACHE BOOL "" FORCE) add_subdirectory( "${_softbus_open62541_dir}" "${CMAKE_BINARY_DIR}/third_party/open62541" ) set(BUILD_SHARED_LIBS ${_softbus_saved_build_shared} CACHE BOOL "" FORCE) if(MINGW AND TARGET open62541) set_target_properties(open62541 PROPERTIES INTERFACE_LINK_LIBRARIES "ws2_32;iphlpapi" ) target_compile_options(open62541 PRIVATE -fno-stack-protector) target_link_options(open62541 PRIVATE -fno-stack-protector) endif() set(SOFTBUS_HAS_OPCUA ON) else() set(SOFTBUS_HAS_OPCUA OFF) endif() # libmodbus (edge RTU/TCP): system pkg-config first, else third_party vendor set(SOFTBUS_HAS_LIBMODBUS OFF) set(SOFTBUS_LIBMODBUS_VENDOR OFF) option(SOFTBUS_FORCE_VENDOR_LIBMODBUS "Always build libmodbus from third_party/libmodbus" OFF) if(NOT SOFTBUS_FORCE_VENDOR_LIBMODBUS) find_package(PkgConfig QUIET) if(PkgConfig_FOUND) pkg_check_modules(LIBMODBUS QUIET libmodbus) endif() endif() if(LIBMODBUS_FOUND AND NOT SOFTBUS_FORCE_VENDOR_LIBMODBUS) set(SOFTBUS_HAS_LIBMODBUS ON) add_library(libmodbus_iface INTERFACE) target_include_directories(libmodbus_iface INTERFACE ${LIBMODBUS_INCLUDE_DIRS}) target_link_libraries(libmodbus_iface INTERFACE ${LIBMODBUS_LIBRARIES}) message(STATUS "libmodbus: using system package (pkg-config)") else() add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/libmodbus") if(NOT SOFTBUS_HAS_LIBMODBUS) message(STATUS "libmodbus not available; softbus_edge uses simulated Modbus I/O") endif() endif() function(softbus_apply_libmodbus target) if(SOFTBUS_HAS_LIBMODBUS) target_compile_definitions(${target} PRIVATE SOFTBUS_HAS_LIBMODBUS=1) target_link_libraries(${target} PRIVATE libmodbus_iface) if(SOFTBUS_LIBMODBUS_VENDOR) target_compile_definitions(${target} PRIVATE SOFTBUS_LIBMODBUS_VENDOR=1) endif() else() target_compile_definitions(${target} PRIVATE SOFTBUS_HAS_LIBMODBUS=0) endif() endfunction() function(softbus_apply_open62541 target) if(SOFTBUS_HAS_OPCUA) target_compile_definitions(${target} PRIVATE SOFTBUS_HAS_OPCUA=1) target_link_libraries(${target} PRIVATE open62541) else() target_compile_definitions(${target} PRIVATE SOFTBUS_HAS_OPCUA=0) endif() endfunction()