[CMake] option, configure_file and ON/OFF
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.deg...@jhu.edu, iChat: anton.deg...@mac.com phone: 410-790-0456 JHU, LCSR, Hackerman Hall 137b, 3400 North Charles Street, Baltimore, MD 21218, USA ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] option, configure_file and ON/OFF
On 11/23/2010 10:30 PM, Anton Deguet wrote: > 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? In your config.h.in, simply write: #cmakedefine01 MYLIB_HAS_WHATEVER With CONFIGURE_FILE(), this expands to #define MYLIB_HAS_WHATEVER 0 or #define MYLIB_HAS_WHATEVER 1 depending on the value of MYLIB_HAS_WHATEVER. Regards, Michael ___ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake