52 lines
1.4 KiB
CMake
52 lines
1.4 KiB
CMake
# Vendored libmodbus v3.1.10 static library for softbus_edge
|
|
|
|
set(_src_dir "${CMAKE_SOURCE_DIR}/third_party/libmodbus")
|
|
if(NOT EXISTS "${_src_dir}/src/modbus.c")
|
|
message(WARNING "Vendor libmodbus not found at ${_src_dir}")
|
|
return()
|
|
endif()
|
|
|
|
set(_gen_dir "${CMAKE_BINARY_DIR}/libmodbus_vendor")
|
|
file(MAKE_DIRECTORY "${_gen_dir}")
|
|
|
|
configure_file(
|
|
"${CMAKE_SOURCE_DIR}/cmake/libmodbus/config.h.linux"
|
|
"${_gen_dir}/config.h"
|
|
COPYONLY
|
|
)
|
|
configure_file(
|
|
"${CMAKE_SOURCE_DIR}/cmake/libmodbus/modbus-version.h"
|
|
"${_gen_dir}/modbus-version.h"
|
|
COPYONLY
|
|
)
|
|
|
|
add_library(modbus_vendor STATIC
|
|
"${_src_dir}/src/modbus.c"
|
|
"${_src_dir}/src/modbus-data.c"
|
|
"${_src_dir}/src/modbus-rtu.c"
|
|
"${_src_dir}/src/modbus-tcp.c"
|
|
)
|
|
set_target_properties(modbus_vendor PROPERTIES
|
|
C_STANDARD 99
|
|
POSITION_INDEPENDENT_CODE ON
|
|
)
|
|
target_include_directories(modbus_vendor
|
|
PUBLIC
|
|
"${_src_dir}/src"
|
|
"${_gen_dir}"
|
|
)
|
|
if(UNIX)
|
|
target_link_libraries(modbus_vendor PUBLIC pthread)
|
|
endif()
|
|
|
|
add_library(libmodbus_iface INTERFACE)
|
|
target_link_libraries(libmodbus_iface INTERFACE modbus_vendor)
|
|
target_include_directories(libmodbus_iface INTERFACE
|
|
"${_src_dir}/src"
|
|
"${_gen_dir}"
|
|
)
|
|
|
|
set(SOFTBUS_HAS_LIBMODBUS ON PARENT_SCOPE)
|
|
set(SOFTBUS_LIBMODBUS_VENDOR ON PARENT_SCOPE)
|
|
message(STATUS "libmodbus: using vendored build from third_party/libmodbus")
|