Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZMQ_BUILD_DRAFT_API is not added to compiler definitions for cppzmq target when ENABLE_DRAFTS is ON. #477

Open
melton1968 opened this issue Feb 11, 2021 · 5 comments · May be fixed by #565

Comments

@melton1968
Copy link

When I run cmake to configure cppzmq with the -DENALBE_DRAFTS=ON flag and then build and install the cppzmq target, the corresponding cppzmqTargets.cmake configuration file does not set the -DZMQ_BUILD_DRAFT_API compiler option as expected.

The code in CMakeLists.txt looks correct:

if (ENABLE_DRAFTS)
    COMPILE_DEFINITIONS(-DZMQ_BUILD_DRAFT_API)
    set (pkg_config_defines "-DZMQ_BUILD_DRAFT_API=1")
else (ENABLE_DRAFTS)
    set (pkg_config_defines "")
endif (ENABLE_DRAFTS)

If I move that code block to below where the cppzmq target is defined and change the add_definitions method to target_compile_definitions:

    target_compile_definitions(cppzmq INTERFACE ZMQ_BUILD_DRAFT_API)

then ZMQ_BUILD_DRAFT_API correctly gets defined as a compiler option in the installed configuration files.

I am not a cmake expert, so I am uncertain if there is something I am missing, but this seems to be some type of adverse interaction between add_definitions and interface targets.

I am using cmake 3.19.4.

I can offer a pull request with the fix if that is useful.

@jlucke86
Copy link
Contributor

@melton1968 the CMake seems to check for a .git folder in the root directory and if it exists enable building the draft api support. I ran x86 build and also arm cross compiled cppzmq 4.6.0 and libzmq 4.3.2 a few weeks ago. I’m pretty sure I didn’t need any special flags.

I support another target platform where I believe I used the compiler definitions as it was building from tar.gz sources rather than git clones. I will try to check that and let you know which flags I used, or the build system uses.

Once you get the libraries compiled you still need to define the enable draft api’s #define before including zmq.hpp in your application otherwise the draft api code will not be exposed.

@datax1969
Copy link

I am using cppzmq in-source via CMake's FetchContent facilities and run into this problem as well. Rather than having to remember to define ZMQ_BUILD_DRAFT_API at higher levels, I think it should be put here as a target_compile_definition. The fix that gets me going is:

line 49-54:
foreach (target cppzmq cppzmq-static)
  add_library(${target} INTERFACE)
+  target_compile_definitions(${target} INTERFACE $<$<BOOL:${ENABLE_DRAFTS}>:ZMQ_BUILD_DRAFT_API>)
  target_include_directories(${target} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
                                                 $<INSTALL_INTERFACE:include>)
endforeach()

I'm sure there's better options to support use for installed versions and in-tree versions but this should serve as a rough guide.

@gummif
Copy link
Member

gummif commented May 20, 2021

Isn't this something that needs to be fixed in libzmq, since that is where ZMQ_BUILD_DRAFT_API should be defined? Does libzmq export this definition in it's cmake files?

@datax1969
Copy link

"Isn't this something that needs to be fixed in libzmq"

Yes. Quite right. Hadn't noticed that if using zmq.h you would also need this.
My specific case was using cmake to build libzmq and it didn't export the define from the Find package. It might do if using pkg-config.
I have raised the issue on zeromq/libzmq

@stephanlachnit
Copy link
Contributor

Since zeromq/libzmq#4323 is merged, I guess all the ZMQ_BUILD_DRAFT_API stuff can be removed?

stephanlachnit added a commit to stephanlachnit/cppzmq that referenced this issue Jul 29, 2022
This option added ZMQ_BUILD_DRAFT_API to the compile definitions. However, this should be propagated by libzmq (see zeromq/libzmq#4323 and zeromq#477).

Signed-off-by: Stephan Lachnit <stephanlachnit@debian.org>
@stephanlachnit stephanlachnit linked a pull request Jul 29, 2022 that will close this issue
stephanlachnit added a commit to stephanlachnit/cppzmq that referenced this issue Nov 20, 2023
This option added ZMQ_BUILD_DRAFT_API to the compile definitions. However, this should be propagated by libzmq (see zeromq/libzmq#4323 and zeromq#477).

Signed-off-by: Stephan Lachnit <stephanlachnit@debian.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants