I have a Cmake project with in the cmakelists the following command
target_compile_definitions(${PROJECT_NAME}
PRIVATE CORE_CM7
PRIVATE STM32H755xx
)
The projects compiles perfectly however in the editor it shows #if defined(CORE_CM7)
as inactive piece of code.
I cannot seem to get the Indexer to recognize these definitions.
I have even thought of dirty solution as in exporting it to a header and including that everywhere. But it kinda defeats the purpose in the first place.
Your indexer not recognizing this makes sense if it's just looking at your source code. The CORE_CM7
symbol only exists when cmake constructs the command line arguments to invoke your compiler. You can see this if you have
a compile_commands.json
being made which is controlled via CMAKE_EXPORT_COMPILE_COMMANDS.
In your CMakeLists.txt
:
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
This file is typically used to inform language servers/indexers of the specific compiler invocation which is required to correctly show inactive code, etc.
I'm not using eclipse but a quick search shows the following as how to enable consulting this file as:
MCU GCC Built-in Compiler Parser
MCU GCC Build Output Parser
Compilation Database Parser