Adding compilation options
To add a compilation option within CMake you have to
- define the option itself for CMake with the OPTION command
- you can hide it by using the MARK_AS_ADVANCED
- you can use IF/ELSE statements using the value of the option
- the compilation option itself is set with the ADD_DEFINITIONS command.
OPTION(OTB_GL_USE_ACCEL "Use video card acceleration." ON) MARK_AS_ADVANCED(OTB_GL_USE_ACCEL) IF(OTB_GL_USE_ACCEL) # Add compiler option ADD_DEFINITIONS(-DOTB_GL_USE_ACCEL) ENDIF(OTB_GL_USE_ACCEL)
If you want to be able to use this option from outside projects (say OTB-Applications using an option defined in OTB), you have to export the option into the OTBConfig.cmake file. This is done by adding the option value into OTBConfig.cmake.in as follows:
This way you can write this into the external project CMakeLists.txt:
IF(OTB_GL_USE_ACCEL) MESSAGE("Video card acceleration enabled.") ADD_DEFINITIONS(-DOTB_GL_USE_ACCEL) ELSE(OTB_GL_USE_ACCEL) MESSAGE("Video card acceleration disabled.") ENDIF(OTB_GL_USE_ACCEL)
Another way to do this is to report this definition in some generated headers like otbConfig.h. To do this, you have to edit the otbConfig.h.in and add the following line:
This way, every c++ code include otbConfig.h will now the OTB_GL_USE_ACCEL definition. This could replace the ADD_DEFINITIONS(-DOTB_GL_USE_ACCEL) and is lighter, because you do not have to modify the CMakeLists.txt of the external projects.