#cmakedefine01 syntax is not clearly defined in the documentation
EDIT: It looks like the problem here might be that I used
#cmakedefine01 DEV_BUILD @DEV_BUILD@
like one might do#cmakedefine DEV_BUILD @DEV_BUILD@
, but the difference in syntax is really unclear from the documentation.
If you try to use #cmakedefine01
in a C++ header file with a variable defined using option()
, C++ will fail to recognize the output, with an error along the lines of the following:
application.cpp:496:53: error: expected ';' after
expression
shouldSetAutoStart = shouldSetAutoStart && !DEV_BUILD;
^
config.h:32:23: note: expanded from macro 'DEV_BUILD'
#define DEV_BUILD OFF 0
^
application.cpp:496:53: error: use of undeclared
identifier 'OFF'
config.h:32:19: note: expanded from macro 'DEV_BUILD'
#define DEV_BUILD OFF 0
^
What appears to be happening is that, rather than setting the variable DEV_BUILD
to 0
as the equivalent of the option OFF
, configure_file
is setting a new variable, OFF
, to 0
, or something like that.
The CMake documentation on configure_file
reads as follows:
depending on whether
VAR
is set in CMake to any value not considered a false constant by theif()
command. The "..." content on the line after the variable name, if any, is processed as above. Input file lines of the form#cmakedefine01 VAR
will be replaced with either#define VAR 1
or#define VAR 0
similarly.
Clicking through to the page on if()
, we see the following:
if(<constant>)
True if the constant is
1
,ON
,YES
,TRUE
,Y
, or a non-zero number. False if the constant is0
,OFF
,NO
,FALSE
,N
,IGNORE
,NOTFOUND
, the empty string, or ends in the suffix-NOTFOUND
.
Because OFF
is defined as a false constant for if(<constant>)
, #cmakedefine01
should recognize it and convert it as such.
It's possible that I'm not using option()
and #cmakedefine01
correctly, but the option variable DEV_BUILD
works properly elsewhere in the CMake scripts; there are a number of #cmakedefine
string variables that are working correctly in the same header file; and this seems like a fairly trivial case for me to be messing up...