Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the #cmakedefine preprocessor directive?

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?

like image 617
sdgfsdh Avatar asked Mar 10 '17 13:03

sdgfsdh


1 Answers

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.

like image 178
usr1234567 Avatar answered Oct 05 '22 10:10

usr1234567