Adding compilation options

From OTBWiki
Jump to: navigation, search

To add a compilation option within CMake you have to

  1. define the option itself for CMake with the OPTION command
  2. you can hide it by using the MARK_AS_ADVANCED
  3. you can use IF/ELSE statements using the value of the option
  4. the compilation option itself is set with the ADD_DEFINITIONS command.

For example:

      OPTION(OTB_GL_USE_ACCEL "Use video card acceleration." ON)
          # Add compiler option 

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 as follows:


This way you can write this into the external project CMakeLists.txt:

	  MESSAGE("Video card acceleration enabled.")
	  MESSAGE("Video card acceleration disabled.")

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 and add the following line:

#cmakedine OTB_GL_USE_ACCEL

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.