I am looking through the source-code for ZeroMQ, which I want to build from source. Inside I found platform.hpp.in
, which contains:
...
#cmakedefine ZMQ_HAVE_SO_PEERCRED
#cmakedefine ZMQ_HAVE_LOCAL_PEERCRED
#cmakedefine ZMQ_HAVE_SOCK_CLOEXEC
#cmakedefine ZMQ_HAVE_SO_KEEPALIVE
#cmakedefine ZMQ_HAVE_TCP_KEEPCNT
...
I assume these cmakedefine
macros are used as templates to generate a header file, but how exactly do they work in CMake? How can I determine what are valid values? How are values set by the user when building the project?
It's part of a file that's processed by CMake's configure_file
command. When configure_file
is called for the file, #cmakedefine FOO
is replaced by:
#define FOO
- if the CMake variable FOO
is set to ON or TRUE./* #undef FOO */
- otherwise.And that is one way to pass values from CMake into C or C++ source code: The result of configure_file()
is a C/C++ header file, which is included by the code you want to respect the CMake variable values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With