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() 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()