Ferenc Deak
Ferenc Deak

Reputation: 35458

Check CMake's option in C++ source

I have the following option defined in CMake:

option(OURAPP-DEV-USE_EXTREME_DEBUGGING "Use extreme debugging features" OFF)

and I would like to check in a C++ file that this option was checked (in the CMake-GUI) or not.

I.e. writing C++ code like:

#if OURAPP-DEV-USE_EXTREME_DEBUGGING
 print_extra_debugging();
#endif

Please note, that our project setup requires that there is a - between the options regarding the components (such as OURAPP and DEV and the rest ...)

Any idea how to make it happen?

Upvotes: 4

Views: 1105

Answers (2)

Offirmo
Offirmo

Reputation: 19870

You can also use cmake CONFIGURE_FILE, cf. http://www.cmake.org/cmake/help/cmake2.6docs.html#command%3Aconfigure_file

Upvotes: 0

Peter
Peter

Reputation: 14947

Transfer the CMake option to the C++ world using a preprocessor define.

IF(OURAPP-DEV-USE_EXTREME_DEBUGGING)
    ADD_DEFINITIONS(-DUSE_EXTREME_DEBUGGING)
ENDIF()

Under the hood, this adds the define to the compiler command line, and is then available to the preprocessor:

#ifdef USE_EXTREME_DEBUGGING
    print_extra_debugging();
#endif

Note that a hyphen is not a valid character in a C preprocessor token, so you'll have to change the name in the define.

Upvotes: 6

Related Questions