[CMake] option, configure_file and ON/OFF
Anton Deguet
anton.deguet at jhu.edu
Tue Nov 23 16:30:36 EST 2010
Hello,
I am trying to use a UI option to set a value used in configure_file and ideally obtain a file that doesn't use ON/OFF. Here is a CMake sample:
option (MYLIB_HAS_WHATEVER "Use whatever library" OFF)
In my config.h.in I have:
#define ON 1
#define OFF 0
#define MYLIB_HAS_WHATEVER ${MYLIB_HAS_WHATEVER}
Then in my code I can use:
#if MYLIB_HAS_WHATEVER
....
#endif
It worked so far but there is an issue if we end up using other libraries which also define ON and/or OFF. There seems to be no way to tell CMake to use 1/0 instead of ON/OFF during the configure_file. My solution has been to modify my CMake to do the following:
option (MYLIB_HAS_WHATEVER "Use whatever library" OFF)
if (MYLIB_HAS_WHATEVER)
set(MYLIB_CONFIG_HAS_WHATEVER 1)
....
else (MYLIB_HAS_WHATEVER)
set(MYLIB_CONFIG_HAS_WHATEVER 0)
....
endif (MYLIB_HAS_WHATEVER)
and in the config.h.in do:
#define MYLIB_HAS_WHATEVER ${MYLIB_CONFIG_HAS_WHATEVER}
Is there a better way?
Anton
---
Anton Deguet, Research Engineer, ERC-CISST/LCSR, Johns Hopkins University
e-mail: anton.deguet at jhu.edu, iChat: anton.deguet at mac.com
phone: 410-790-0456
JHU, LCSR, Hackerman Hall 137b, 3400 North Charles Street, Baltimore, MD 21218, USA
More information about the CMake
mailing list