I have a section of code that is conditionally activated depending on a #define, like this:
#ifdef VARIABLE
code.function();
#endif
The cmake script has an 'options' command that sets the VARIABLE like this:
option(VARIABLE "Want to use VARIABLE?" ON)
if(VARIABLE)
message(STATUS "VARIABLE")
set(VARIABLE_FLAG "-DVARIABLE")
endif()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VARIABLE_FLAG} -Wall")
I'm using cmake to build the project and qtcreator as IDE. My problem is that qtcreator thinks that VARIABLE is not defined so my code has is not highlighted, but when I build it on a console, VARIABLE is defined. So, what parameters should I pass to qtcreator to run cmake, so that it knows VARIABLE is defined and highlights my code? Is there a way to do this?
Ps: I just use qtcreator to edit files, the build part is done via console commands.
Another alternative would be to use a configured header file, and include it only where you need the definition:
and
and finally
I do not use QtCreator regularly, so I don't know if this technique works in terms of their syntax highlighting, but I'd assume it would, since they must read header files in order to do a proper job of it...
You can also use the project_name.config file. It is specifically used for your need. You can add defines which are only interpreted by QtCreator for highlighting and auto-completion.
This file is normally in the root folder of your project.
Take a look at add_definitions(). It adds a preprocessor-define to the compiler and can be used like any ordinary
#define
:However... I am not sure if this will make qtcreator pick it up as a 'known variable'.