[zeromq-dev] Add build-information to ZMQ headers

Goswin von Brederlow goswin-v-b at web.de
Tue Jan 14 09:55:51 CET 2014

On Tue, Jan 14, 2014 at 01:21:18AM +0100, Patric Schmitz wrote:
> Dear zeromq developers,
> in our project using zeromq, we depend on the PGM features which we use
> for multicast synchronisation in our cluster environment. I would like
> to be able to compile-time test, when building against zeromq, wether
> that specific build has PGM support enabled or not, in order to abort
> or warn the user if he tries to use a 'wrongly' configured build.
> However, having looked at the zmq headers, I see, as of now, no way of
> doing so.

Is that realy a compile time feature? What if I compile an app against
libzmq without pgm and then replace libzmq with a recompiled version
that has pgm? Does that require everything to be recompiled for pgm to
work? If so then the pgm feature would have to be part of the soname
too and things get ugly. 

But luckily you open a pgm socket with:

    rc = zmq_connect(socket, "pgm://;");

That either works or fails depending on wether pgm support is present
and the process has the right permissions. No change in the ABI.

> I have looked into autoconf to see how this could be done. A simple
> option would be to introduce a new header like zmq_config.h which
> contains a subset of the undef/defines which are present in
> src/platform.hpp as generated by autoheader. Since appropriate macros
> such as ZMQ_HAVE_OPENPGM are already defined, we would just have to add
> e.g. include/zeromq_config.h as a second AC_CONFIG_HEADER and put
> only the build options relevant to the user in there.
> There are already 'build-specific' options contained in zmq.h,
> specifically the ZMQ_VERSION_* macros. I would prefer not to introduce
> a separate header, but have the build configuration defines in zmq.h as
> well. However, simply having the undefs automatically replaced by
> autoconfig is not possible within zmq.h, since an AC_CONFIG_HEADER
> should not contain any defines and undefs will be commented if they
> were not AC_DEFINE'd, which will mess up #undef ZMQ_EXPORT at the end
> of zmq.h for example.
> It is however possible to make zmq.h an AC_CONFIG_FILE and have the
> value of an autoconf variable exported via AC_SUBST substituted in the
> generated file. A patch implementing that option is attached. Please
> feel free to adapt it as you see fit and hopefully include this kind of
> feature macros in future zmq versions.
> Best regards
> -- 
> Patric Schmitz <bzk0711 at aol.com>

The define would maybe prevent some accidental mishaps telling you
earlier that pgm support is missing. But they wouldn't prevent a non
pgm libzmq from being used later on. On the other hand the define
would prevent compiling against a libzmq without pgm but later use it
with one with pgm. So I'm not sure that define would be all that

> diff --git a/configure.ac b/configure.ac
> index a258bf0..28af2d2 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -456,6 +456,11 @@ if test "x$with_system_pgm_ext" != "xno"; then
>      [AC_MSG_ERROR([--with-system-pgm requires a working pkg-config installation])])
>  fi
> +pgm_available=0
> +if test "x$with_system_pgm_ext" != "xno" -o "x$with_pgm_ext" != "xno" ; then
> +   pgm_available=1
> +fi
> +AC_SUBST(pgm_available)
>  AC_SUBST(pgm_basename)
>  # Set -Wall, -Werror and -pedantic
> @@ -530,5 +535,6 @@ AC_CONFIG_FILES([Makefile \
>      tools/Makefile \
>      builds/msvc/Makefile \
>      foreign/openpgm/Makefile \
> -    builds/redhat/zeromq.spec])
> +    builds/redhat/zeromq.spec \
> +    include/zmq.h])

@@ -530,5 +535,7 @@ AC_CONFIG_FILES([Makefile \
     tools/Makefile \
     builds/msvc/Makefile \
     foreign/openpgm/Makefile \
-    builds/redhat/zeromq.spec])
+    builds/redhat/zeromq.spec \
+    include/zmq.h \
+    ])

That way future changes will only add lines, not replace old ones just
to add the "\" to the end. But that might be just my preference.


More information about the zeromq-dev mailing list