libzmq
libzmq copied to clipboard
Some build-checks ignored with cmake
Issue description
I first noticed this when running zeromq inside a chroot on nixos; it was trying to open /dev/urandom and failing. Building manually, I noticed that cmake checks for getrandom() in zmq_check_getrandom() but then never sets -DZMQ_HAVE_GETRANDOM
at buildtime
Environment
- libzmq version (commit hash if unreleased): 4.3.2
- OS: Linux/NixOS
Minimal test code / Steps to reproduce the issue
- Start with source on any system with getrandom()
-
mkdir build
-
cd build
-
cmake ..
- Ensure the following in output:
-- Performing Test ZMQ_HAVE_GETRANDOM -- Performing Test ZMQ_HAVE_GETRANDOM - Success
- Ensure the following in output:
- make VERBOSE=1 src/tweetnacl.o
-
grep getrandom CMakeFiles/objects.dir/src/tweetnacl.c.o
- Build the whole system, strace any program that initializes zeromq
What's the actual result? (include assertion message & call stack if applicable)
In step #5 above, -DZMQ_HAVE_GETRANDOM
does not appear on the command line
In step #6 above tweenacl,c.o has no match to the string "getrandom"
In step #7 above, observe that "/dev/urandom" is being opened, indicating getrandom is not in use
What's the expected result?
- We should see -DZMQ_HAVE_GETRANDOM on the build command-line
- grep should find a "getrandom" string in the tweentnacl binary file
- initializing zeromq should not open /dev/urandom
Patch that fixes the problem
The following patch fixes the issue for getrandom(). I don't know if it's the idiomatic way to do it with cmake, and I suspect that most of the other checks will need updating as well (e.g. ZMQ_HAVE_NOEXCEPT seems to similarly have no effect), so I didn't make a PR:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8eb3411f..455369f5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -980,6 +980,10 @@ if(ZMQ_HAVE_TIPC)
list(APPEND cxx-sources tipc_address.cpp tipc_connecter.cpp tipc_listener.cpp)
endif()
+if(ZMQ_HAVE_GETRANDOM)
+ add_definitions(-DZMQ_HAVE_GETRANDOM)
+endif()
+
#-----------------------------------------------------------------------------
# source generators
This issue has been automatically marked as stale because it has not had activity for 365 days. It will be closed if no further activity occurs within 56 days. Thank you for your contributions.