Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions recipes/libmodbus/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
sources:
"3.1.11":
url: "https://github.com/stephane/libmodbus/archive/refs/tags/v3.1.11.tar.gz"
sha256: "8a750452ef86a53de6cec6fbca67bd5be08d0a1e87278a422fbce3003fd42d99"
"3.1.10":
url: "https://github.com/stephane/libmodbus/releases/download/v3.1.10/libmodbus-3.1.10.tar.gz"
sha256: "899be4e25ab7fe5799d43f9567510d6f063d2e8f56136dd726b6fd976f9b2253"
"3.1.8":
url: "https://github.com/stephane/libmodbus/releases/download/v3.1.8/libmodbus-3.1.8.tar.gz"
sha256: "b122f2bc29f749702a22c0a760a7ca2182d541f5fa26bf25e3431f907b606f3c"
"3.1.6":
url: "https://libmodbus.org/releases/libmodbus-3.1.6.tar.gz"
sha256: "d7d9fa94a16edb094e5fdf5d87ae17a0dc3f3e3d687fead81835d9572cf87c16"
"3.1.12":
url: "https://github.com/stephane/libmodbus/releases/download/v3.1.12/libmodbus-3.1.12.tar.gz"
sha256: "2f4d4191cd196c1fba131daec03b621db75129d8255c832fc66b259d9fc46e7b"
patches:
"3.1.11":
- patch_file: "patches/3.1.11-0001-msvc-fixes.patch"
"3.1.10":
- patch_file: "patches/3.1.10-0001-msvc-fixes.patch"
"3.1.8":
- patch_file: "patches/3.1.8-0001-msvc-fixes.patch"
"3.1.6":
- patch_file: "patches/3.1.6-0001-msvc-fixes.patch"
"3.1.12":
- patch_file: "patches/0001-respect-cflags.patch"
- patch_file: "patches/0002-no-msvc-warnings.patch"
- patch_file: "patches/0003-fix-typedef-int.patch"
8 changes: 3 additions & 5 deletions recipes/libmodbus/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import check_min_vs, is_msvc
from conan.tools.scm import Version
import os

required_conan_version = ">=1.57.0"
Expand Down Expand Up @@ -54,19 +53,18 @@ def build_requirements(self):

if is_msvc(self):
self.tool_requires("automake/1.16.5")

if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
apply_conandata_patches(self)

def generate(self):
tc = AutotoolsToolchain(self)
if Version(self.version) < "3.1.8":
tc.configure_args.append("--without-documentation")
tc.configure_args.append("--disable-tests")
if is_msvc(self) and check_min_vs(self, "180", raise_invalid=False):
tc.extra_cflags.append("-FS")
Expand All @@ -75,10 +73,10 @@ def generate(self):
tc.generate()

def _patch_sources(self):
apply_conandata_patches(self)
if not self.options.shared:
for decl in ("__declspec(dllexport)", "__declspec(dllimport)"):
replace_in_file(self, os.path.join(self.source_folder, "src", "modbus.h"), decl, "")

def build(self):
self._patch_sources()
autotools = Autotools(self)
Expand Down
78 changes: 78 additions & 0 deletions recipes/libmodbus/all/patches/0001-respect-cflags.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Respect user-provided CFLAGS

https://github.com/stephane/libmodbus/pull/836
https://github.com/stephane/libmodbus/commit/b2b37ef6a38d38c08e4bf710e089ca2ad058bb55

diff --git a/configure.ac b/configure.ac
index cb4cec68..7b745caf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,6 +30,10 @@ AC_INIT([libmodbus],
AC_CONFIG_SRCDIR([src/modbus.c])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign 1.11 silent-rules tar-pax subdir-objects])
+
+# Check if user provided CFLAGS before AC_PROG_CC sets defaults
+user_set_cflags="${CFLAGS+set}"
+
AC_PROG_CC
AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE
@@ -178,13 +182,18 @@ AC_ARG_ENABLE([debug],
[enable_debug=$enableval],
[enable_debug=no])

+# Set project-specific optimization flags based on debug mode.
+# These are added via AM_CFLAGS in Makefile.am, preserving user's CFLAGS.
AS_IF([test "x$enable_debug" = "xyes"], [
- CFLAGS="-g -O0"
- CXXFLAGS="-g -O0"
+ LIBMODBUSCFLAGS="-g -O0"
+ # Clear AC_PROG_CC's default -O2 so debug mode works, unless user set CFLAGS
+ AS_IF([test "x$user_set_cflags" != "xset"], [
+ CFLAGS="-g"
+ ])
], [
- CFLAGS="-O2"
- CXXFLAGS="-O2"
+ LIBMODBUSCFLAGS="-O2"
])
+AC_SUBST([LIBMODBUSCFLAGS])

AC_OUTPUT
AC_MSG_RESULT([
@@ -197,7 +206,7 @@ AC_MSG_RESULT([
includedir: ${includedir}

compiler: ${CC}
- cflags: ${CFLAGS} ${WARNING_CFLAGS}
+ cflags: ${LIBMODBUSCFLAGS} ${WARNING_CFLAGS} ${CFLAGS}
ldflags: ${LDFLAGS}

tests: ${enable_tests}
diff --git a/src/Makefile.am b/src/Makefile.am
index fc6c8dbb..157e9200 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,7 +7,7 @@ AM_CPPFLAGS = \
-DLIBEXECDIR=\""$(libexecdir)"\" \
-I${top_srcdir}/src

-AM_CFLAGS = ${WARNING_CFLAGS}
+AM_CFLAGS = $(LIBMODBUSCFLAGS) $(WARNING_CFLAGS)

libmodbus_la_SOURCES = \
modbus.c \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 79a66c22..a18badba 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -44,7 +44,7 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src \
-I${top_builddir}/src

-AM_CFLAGS = ${WARNING_CFLAGS}
+AM_CFLAGS = $(LIBMODBUSCFLAGS) $(WARNING_CFLAGS)

CLEANFILES = *~ *.log

25 changes: 25 additions & 0 deletions recipes/libmodbus/all/patches/0002-no-msvc-warnings.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Use warning flags only with GCC and Clang

https://github.com/stephane/libmodbus/issues/846

diff --git a/configure.ac b/configure.ac
index 7b745ca..518574f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -151,12 +151,15 @@ AC_CHECK_DECLS([TIOCSRS485], [], [], [[#include <sys/ioctl.h>]])
# Check for RTS flags
AC_CHECK_DECLS([TIOCM_RTS], [], [], [[#include <sys/ioctl.h>]])

-WARNING_CFLAGS="-Wall \
+WARNING_CFLAGS=""
+if test "x$GCC" = "xyes"; then
+ WARNING_CFLAGS="-Wall \
-Wmissing-declarations -Wmissing-prototypes \
-Wnested-externs -Wpointer-arith \
-Wsign-compare -Wchar-subscripts \
-Wstrict-prototypes -Wshadow \
-Wformat-security"
+fi
AC_SUBST([WARNING_CFLAGS])

# Build options
21 changes: 21 additions & 0 deletions recipes/libmodbus/all/patches/0003-fix-typedef-int.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ssize_t is pre-defined in config.h as int on Windows, because Windows doesn't have ssize_t.
This patch adds a check to avoid redefining ssize_t on Windows, which causes a compilation error:
src\modbus-private.h(17): error C2632: 'int' followed by 'int' is illegal

https://github.com/stephane/libmodbus/pull/847

diff --git a/src/modbus-private.h b/src/modbus-private.h
index ea83187..f108fe6 100644
--- a/src/modbus-private.h
+++ b/src/modbus-private.h
@@ -14,8 +14,10 @@
#else
# include "stdint.h"
# include <time.h>
+#ifndef ssize_t
typedef int ssize_t;
#endif
+#endif
// clang-format on
#include <config.h>
#include <sys/types.h>
27 changes: 0 additions & 27 deletions recipes/libmodbus/all/patches/3.1.10-0001-msvc-fixes.patch

This file was deleted.

52 changes: 0 additions & 52 deletions recipes/libmodbus/all/patches/3.1.11-0001-msvc-fixes.patch

This file was deleted.

29 changes: 0 additions & 29 deletions recipes/libmodbus/all/patches/3.1.6-0001-msvc-fixes.patch

This file was deleted.

29 changes: 0 additions & 29 deletions recipes/libmodbus/all/patches/3.1.8-0001-msvc-fixes.patch

This file was deleted.

8 changes: 1 addition & 7 deletions recipes/libmodbus/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
versions:
"3.1.11":
folder: all
"3.1.10":
folder: all
"3.1.8":
folder: all
"3.1.6":
"3.1.12":
folder: all