Issue
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?
Solution
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 variableFOO
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.
Answered By - usr1234567 Answer Checked By - Candace Johnson (WPSolving Volunteer)