diff --git a/ports/libmodbus/CMakeLists.txt b/ports/libmodbus/CMakeLists.txt deleted file mode 100644 index 618ba5f6cb..0000000000 --- a/ports/libmodbus/CMakeLists.txt +++ /dev/null @@ -1,114 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project(libmodbus VERSION 3.1.6) - -set(LIBMODBUS_VERSION ${PROJECT_VERSION}) -set(LIBMODBUS_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) -set(LIBMODBUS_VERSION_MINOR ${PROJECT_VERSION_MINOR}) -set(LIBMODBUS_VERSION_MICRO ${PROJECT_VERSION_PATCH}) -configure_file(src/modbus-version.h.in ${CMAKE_CURRENT_BINARY_DIR}/modbus-version.h) - -if(WIN32) - set(HAVE_ERRNO_H 1) - set(HAVE_FCNTL_H 1) - set(HAVE_LIMITS_H 1) - set(HAVE_SYS_TYPES_H 1) - set(HAVE_TIME_H 1) - set(HAVE_MALLOC 1) - set(HAVE_MEMSET 1) - set(HAVE_STRERROR 1) -else() - include(CheckIncludeFile) - check_include_file(arpa/inet.h HAVE_ARPA_INET_H) - check_include_file(byteswap.h HAVE_BYTESWAP_H) - check_include_file(errno.h HAVE_ERRNO_H) - check_include_file(fcntl.h HAVE_FCNTL_H) - check_include_file(limits.h HAVE_LIMITS_H) - check_include_file(linux/serial.h HAVE_LINUX_SERIAL_H) - check_include_file(netdb.h HAVE_NETDB_H) - check_include_file(netinet/in.h HAVE_NETINET_IN_H) - check_include_file(netinet/tcp.h HAVE_NETINET_TCP_H) - check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H) - check_include_file(sys/params.h HAVE_SYS_PARAMS_H) - check_include_file(sys/socket.h HAVE_SYS_SOCKET_H) - check_include_file(sys/time.h HAVE_SYS_TIME_H) - check_include_file(sys/types.h HAVE_SYS_TYPES_H) - check_include_file(termios.h HAVE_TERMIOS_H) - check_include_file(time.h HAVE_TIME_H) - check_include_file(unistd.h HAVE_UNISTD_H) - - include(CheckFunctionExists) - check_function_exists(accept4 HAVE_ACCEPT4) - check_function_exists(fork HAVE_FORK) - check_function_exists(getaddrinfo HAVE_GETADDRINFO) - check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) - check_function_exists(inet_ntoa HAVE_INET_NTOA) - check_function_exists(malloc HAVE_MALLOC) - check_function_exists(memset HAVE_MEMSET) - check_function_exists(select HAVE_SELECT) - check_function_exists(socket HAVE_SOCKET) - check_function_exists(strerror HAVE_STRERROR) - check_function_exists(strlcpy HAVE_STRLCPY) - - include(CheckSymbolExists) - check_symbol_exists(TIOCSRS485 sys/ioctl.h HAVE_TIOCRS485) - check_symbol_exists(TIOCM_RTS sys/ioctl.h HAVE_TIOCM_RTS) -endif() - -configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) - - -if(BUILD_SHARED_LIBS) - add_compile_options(-DDLLBUILD=ON) -else() - add_compile_options(-DLIBBUILD=ON) -endif() - -set(MODBUS_PUBLIC_HEADERS - src/modbus-rtu.h - src/modbus-tcp.h - src/modbus.h - ${CMAKE_CURRENT_BINARY_DIR}/modbus-version.h -) - -add_library(modbus - src/modbus-data.c - src/modbus-rtu.c - src/modbus-tcp.c -src/modbus.c) - -target_include_directories(modbus PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) -target_include_directories(modbus INTERFACE - $ -) -set_target_properties(modbus PROPERTIES PUBLIC_HEADER "${MODBUS_PUBLIC_HEADERS}") - -if(CMAKE_COMPILER_IS_GNUCC) - target_compile_options(modbus PRIVATE -D_GNU_SOURCE) -endif() - -if(WIN32) - target_link_libraries(modbus wsock32 ws2_32) -endif() - -set(LIBMODBUS_SOVERSION_VERSION 5.1.0) -set(LIBMODBUS_SOVERSION_SOVERSION 5) - - -set_target_properties(modbus PROPERTIES - VERSION ${LIBMODBUS_SOVERSION_VERSION} -SOVERSION ${LIBMODBUS_SOVERSION_SOVERSION}) - - -install( - TARGETS modbus - EXPORT libmodbusConfig - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib -) -install(EXPORT libmodbusConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake) - - -if(NOT DISABLE_INSTALL_HEADERS) - install(FILES ${MODBUS_PUBLIC_HEADERS} DESTINATION include/) -endif() diff --git a/ports/libmodbus/cflags.diff b/ports/libmodbus/cflags.diff new file mode 100644 index 0000000000..854aca246b --- /dev/null +++ b/ports/libmodbus/cflags.diff @@ -0,0 +1,20 @@ +diff --git a/configure.ac b/configure.ac +index 920612f..06d5dfa 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -147,6 +147,7 @@ AC_CHECK_DECLS([TIOCSRS485], [], [], [[#include ]]) + # Check for RTS flags + AC_CHECK_DECLS([TIOCM_RTS], [], [], [[#include ]]) + ++test -n "$WARNING_CFLAGS" || \ + WARNING_CFLAGS="-Wall \ + -Wmissing-declarations -Wmissing-prototypes \ + -Wnested-externs -Wpointer-arith \ +@@ -178,6 +179,7 @@ AC_ARG_ENABLE([debug], + [enable_debug=$enableval], + [enable_debug=no]) + ++test -n "$CFLAGS" || \ + AS_IF([test "x$enable_debug" = "xyes"], [ + CFLAGS="-g -O0" + CXXFLAGS="-g -O0" diff --git a/ports/libmodbus/config.h.cmake b/ports/libmodbus/config.h.cmake deleted file mode 100644 index b8f7585be7..0000000000 --- a/ports/libmodbus/config.h.cmake +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -#cmakedefine HAVE_ARPA_INET_H -#cmakedefine HAVE_BYTESWAP_H -#cmakedefine HAVE_ERRNO_H -#cmakedefine HAVE_FCNTL_H -#cmakedefine HAVE_LIMITS_H -#cmakedefine HAVE_LINUX_SERIAL_H -#cmakedefine HAVE_NETDB_H -#cmakedefine HAVE_NETINET_IN_H -#cmakedefine HAVE_NETINET_TCP_H -#cmakedefine HAVE_SYS_IOCTL_H -#cmakedefine HAVE_SYS_PARAMS_H -#cmakedefine HAVE_SYS_SOCKET_H -#cmakedefine HAVE_SYS_TIME_H -#cmakedefine HAVE_SYS_TYPES_H -#cmakedefine HAVE_TERMIOS_H -#cmakedefine HAVE_TIME_H -#cmakedefine HAVE_UNISTD_H - -#cmakedefine HAVE_ACCEPT4 -#cmakedefine HAVE_FORK -#cmakedefine HAVE_GETADDRINFO -#cmakedefine HAVE_GETTIMEOFDAY -#cmakedefine HAVE_INET_NTOA -#cmakedefine HAVE_MALLOC -#cmakedefine HAVE_MEMSET -#cmakedefine HAVE_SELECT -#cmakedefine HAVE_SOCKET -#cmakedefine HAVE_STRERROR -#cmakedefine HAVE_STRLCPY - -#cmakedefine HAVE_TIOCRS485 -#cmakedefine HAVE_TIOCM_RTS - -#ifdef HAVE_TIOCM_RTS -#define HAVE_DECL_TIOCM_RTS 1 -#else -#define HAVE_DECL_TIOCM_RTS 0 -#endif - -#ifdef HAVE_TIOCRS485 -#define HAVE_DECL_TIOCSRS485 1 -#else -#define HAVE_DECL_TIOCSRS485 0 -#endif - -#endif \ No newline at end of file diff --git a/ports/libmodbus/fix-static-linkage.patch b/ports/libmodbus/fix-static-linkage.patch deleted file mode 100644 index 7d7ae79f50..0000000000 --- a/ports/libmodbus/fix-static-linkage.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/src/modbus.h b/src/modbus.h -index fbe20bc..895d05d 100644 ---- a/src/modbus.h -+++ b/src/modbus.h -@@ -24,6 +24,8 @@ - # if defined(DLLBUILD) - /* define DLLBUILD when building the DLL */ - # define MODBUS_API __declspec(dllexport) -+# elif defined(LIBBUILD) -+# define MODBUS_API - # else - # define MODBUS_API __declspec(dllimport) - # endif diff --git a/ports/libmodbus/libmodbusConfig.cmake b/ports/libmodbus/libmodbusConfig.cmake new file mode 100644 index 0000000000..83aebe4e81 --- /dev/null +++ b/ports/libmodbus/libmodbusConfig.cmake @@ -0,0 +1,27 @@ +message(WARNING "find_package(modbus) is unofficial. libmodbus provides a pkg-config module: libmodbus") + +if(NOT TARGET modbus) + get_filename_component(VCPKG_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE) + find_library(Z_VCPKG_MODBUS_RELEASE NAMES modbus PATHS "${VCPKG_IMPORT_PREFIX}/lib" REQUIRED) + find_library(Z_VCPKG_MODBUS_DEBUG NAMES modbus PATHS "${VCPKG_IMPORT_PREFIX}/debug/lib") + mark_as_advanced(Z_VCPKG_MODBUS_RELEASE Z_VCPKG_MODBUS_DEBUG) + add_library(modbus UNKNOWN IMPORTED) + set_target_properties(modbus PROPERTIES + IMPORTED_CONFIGURATIONS "Release" + INTERFACE_INCLUDE_DIRECTORIES "${VCPKG_IMPORT_PREFIX}/include/modbus" + IMPORTED_LOCATION_RELEASE "${Z_VCPKG_MODBUS_RELEASE}" + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + ) + if(Z_VCPKG_MODBUS_DEBUG) + set_property(TARGET modbus APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug) + set_target_properties(modbus PROPERTIES + IMPORTED_LOCATION_DEBUG "${Z_VCPKG_MODBUS_DEBUG}" + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C" + ) + endif() + if(WIN32) + set_target_properties(modbus PROPERTIES + INTERFACE_LINK_LIBRARIES "ws2_32" + ) + endif() +endif() diff --git a/ports/libmodbus/library-linkage.diff b/ports/libmodbus/library-linkage.diff new file mode 100644 index 0000000000..402363dfcc --- /dev/null +++ b/ports/libmodbus/library-linkage.diff @@ -0,0 +1,32 @@ +diff --git a/configure.ac b/configure.ac +index 9f30d29..29737da 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -120,6 +120,14 @@ AC_C_INLINE + # libtool + AC_PROG_CXX + ++if "$os_win32" = "true"; then ++ if test "$enable_shared" = "yes"; then ++ AC_DEFINE(DLLBUILD, [], [Building a DLL]) ++ else ++ AC_DEFINE(STATIC_LIBMODBUS, [], [Building a static library]) ++ fi ++fi ++ + # Various types + AC_TYPE_INT64_T + AC_TYPE_SIZE_T +diff --git a/src/modbus.h b/src/modbus.h +index fa7ec4a..ae204ce 100644 +--- a/src/modbus.h ++++ b/src/modbus.h +@@ -25,6 +25,8 @@ + # if defined(DLLBUILD) + /* define DLLBUILD when building the DLL */ + # define MODBUS_API __declspec(dllexport) ++# elif defined(STATIC_LIBMODBUS) ++# define MODBUS_API + # else + # define MODBUS_API __declspec(dllimport) + # endif diff --git a/ports/libmodbus/pkgconfig.diff b/ports/libmodbus/pkgconfig.diff new file mode 100644 index 0000000000..015d84ce66 --- /dev/null +++ b/ports/libmodbus/pkgconfig.diff @@ -0,0 +1,23 @@ +diff --git a/configure.ac b/configure.ac +index 06d5dfa..f3122ac 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -133,6 +133,8 @@ if test "$os_cygwin" = "false"; then + AC_CHECK_HEADERS([winsock2.h], HAVE_WINSOCK2_H=yes) + if test "x$HAVE_WINSOCK2_H" = "xyes"; then + LIBS="$LIBS -lws2_32" ++ PC_LIBS_PRIVATE="$PC_LIBS_PRIVATE -lws2_32" ++ AC_SUBST(PC_LIBS_PRIVATE) + AC_SUBST(LIBS) + fi + fi +diff --git a/libmodbus.pc.in b/libmodbus.pc.in +index f1a9cbf..f7b4d08 100644 +--- a/libmodbus.pc.in ++++ b/libmodbus.pc.in +@@ -7,4 +7,5 @@ Name: modbus + Description: Modbus library + Version: @VERSION@ + Libs: -L${libdir} -lmodbus ++Libs.private: @PC_LIBS_PRIVATE@ + Cflags: -I${includedir}/modbus diff --git a/ports/libmodbus/portfile.cmake b/ports/libmodbus/portfile.cmake index 3e16315905..117f36621a 100644 --- a/ports/libmodbus/portfile.cmake +++ b/ports/libmodbus/portfile.cmake @@ -2,30 +2,37 @@ vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO stephane/libmodbus REF "v${VERSION}" - SHA512 6a01da1f8b486e356ff44874f1479d9d121463958a5ed06e60d910328ccc9b2d431b4a1fd72861c5c645c97b5887a076b763ad6a9ae6b18402dd043ec525b1e2 + SHA512 cb506d5b72b629591002450221ea512a067209ee60c588dc88c45494ea983af2c05c47b2d0ba7db02e46d7a30110547ec96f9f98d643756f9528a99291683f70 HEAD_REF master - PATCHES fix-static-linkage.patch + PATCHES + cflags.diff + library-linkage.diff + pkgconfig.diff + ssize_t.diff ) -file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" "${CMAKE_CURRENT_LIST_DIR}/config.h.cmake" - DESTINATION "${SOURCE_PATH}" -) - -vcpkg_cmake_configure( - SOURCE_PATH "${SOURCE_PATH}" - OPTIONS_DEBUG - -DDISABLE_INSTALL_HEADERS=ON -) - -vcpkg_cmake_install() -vcpkg_copy_pdbs() -vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake) - -if(VCPKG_TARGET_IS_WINDOWS AND VCPKG_LIBRARY_LINKAGE STREQUAL "static") - vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/modbus.h" "elif defined(LIBBUILD)" "elif 1") +if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW) + set(ENV{WARNING_CFLAGS} "-D_CRT_SECURE_NO_DEPRECATE=1 -D_CRT_NONSTDC_NO_DEPRECATE=1") endif() -# Handle copyright -vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING.LESSER") +vcpkg_make_configure( + SOURCE_PATH "${SOURCE_PATH}" + AUTORECONF + OPTIONS + --enable-tests=no +) +vcpkg_make_install() +vcpkg_copy_pdbs() +vcpkg_fixup_pkgconfig() +file(COPY "${CURRENT_PORT_DIR}/libmodbusConfig.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/libmodbus") -file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") +if(VCPKG_TARGET_IS_WINDOWS AND VCPKG_LIBRARY_LINKAGE STREQUAL "static") + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/modbus/modbus.h" "defined(STATIC_LIBMODBUS)" "1") +endif() + + file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" +) + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING.LESSER") diff --git a/ports/libmodbus/ssize_t.diff b/ports/libmodbus/ssize_t.diff new file mode 100644 index 0000000000..e2ba0c3dac --- /dev/null +++ b/ports/libmodbus/ssize_t.diff @@ -0,0 +1,14 @@ +diff --git a/src/modbus-private.h b/src/modbus-private.h +index ea83187..db5a3dc 100644 +--- a/src/modbus-private.h ++++ b/src/modbus-private.h +@@ -14,7 +14,9 @@ + #else + # include "stdint.h" + # include ++# ifndef ssize_t + typedef int ssize_t; ++# endif + #endif + // clang-format on + #include diff --git a/ports/libmodbus/vcpkg.json b/ports/libmodbus/vcpkg.json index 1f383188a3..2dbc876865 100644 --- a/ports/libmodbus/vcpkg.json +++ b/ports/libmodbus/vcpkg.json @@ -1,17 +1,13 @@ { "name": "libmodbus", - "version": "3.1.10", + "version": "3.1.11", "description": "libmodbus is a free software library to send/receive data with a device which respects the Modbus protocol", "homepage": "https://github.com/stephane/libmodbus", "license": "LGPL-2.1-or-later", "supports": "!uwp & !xbox", "dependencies": [ { - "name": "vcpkg-cmake", - "host": true - }, - { - "name": "vcpkg-cmake-config", + "name": "vcpkg-make", "host": true } ] diff --git a/scripts/test_ports/vcpkg-ci-libmodbus/portfile.cmake b/scripts/test_ports/vcpkg-ci-libmodbus/portfile.cmake new file mode 100644 index 0000000000..dd25706120 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-libmodbus/portfile.cmake @@ -0,0 +1,10 @@ +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) + +vcpkg_find_acquire_program(PKGCONFIG) + +vcpkg_cmake_configure( + SOURCE_PATH "${CURRENT_PORT_DIR}/project" + OPTIONS + "-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}" +) +vcpkg_cmake_build() diff --git a/scripts/test_ports/vcpkg-ci-libmodbus/project/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-libmodbus/project/CMakeLists.txt new file mode 100644 index 0000000000..b4a85a0fd2 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-libmodbus/project/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.30) +project(libmodbus-test C) + +find_package(libmodbus CONFIG REQUIRED) +add_library(imported::modbus ALIAS modbus) + +add_executable(main main.c) +target_link_libraries(main PRIVATE imported::modbus) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(libmodbus_pc libmodbus REQUIRED IMPORTED_TARGET) + +add_executable(main-pkconfig main.c) +target_link_libraries(main-pkconfig PRIVATE + PkgConfig::libmodbus_pc +) diff --git a/scripts/test_ports/vcpkg-ci-libmodbus/project/main.c b/scripts/test_ports/vcpkg-ci-libmodbus/project/main.c new file mode 100644 index 0000000000..aaffb06b36 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-libmodbus/project/main.c @@ -0,0 +1,12 @@ +#include +#include + +int main() +{ + modbus_t *ctx = modbus_new_rtu("/dev/ttyUSB0", 115200, 'N', 8, 1); + if (ctx == NULL) { + fprintf(stderr, "Unable to create the libmodbus context\n"); + return -1; + } + return 0; +} diff --git a/scripts/test_ports/vcpkg-ci-libmodbus/vcpkg.json b/scripts/test_ports/vcpkg-ci-libmodbus/vcpkg.json new file mode 100644 index 0000000000..293ffea3cb --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-libmodbus/vcpkg.json @@ -0,0 +1,17 @@ +{ + "name": "vcpkg-ci-libmodbus", + "version-string": "ci", + "description": "Port to validate libmodbus in CI", + "homepage": "https://github.com/microsoft/vcpkg", + "license": "MIT", + "dependencies": [ + { + "name": "libmodbus", + "default-features": false + }, + { + "name": "vcpkg-cmake", + "host": true + } + ] +} diff --git a/versions/baseline.json b/versions/baseline.json index 5a15e5ba5b..76bde6add2 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -4973,7 +4973,7 @@ "port-version": 13 }, "libmodbus": { - "baseline": "3.1.10", + "baseline": "3.1.11", "port-version": 0 }, "libmodman": { diff --git a/versions/l-/libmodbus.json b/versions/l-/libmodbus.json index 8f80b0bcc6..908cd33ef8 100644 --- a/versions/l-/libmodbus.json +++ b/versions/l-/libmodbus.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "9830c2727d060b7b7a8bddf735d39118576419d8", + "version": "3.1.11", + "port-version": 0 + }, { "git-tree": "5af2a746eeb644d4c228d03f4bb7854cf4f5691b", "version": "3.1.10",