beLow - Technical documentation
  • Compatibility
  • Installation guide
    • Installation modes
    • Installation instructions
      • Linux
        • Requirements
        • Installation
      • Windows
        • Requirements
        • Installation
  • Getting started
    • Start beLow
    • Sign up/log in
    • Setup a new project
    • Run an analysis
    • Run an optimization
  • Compatibility guide
    • Compatibility generalities
    • Compatibility specifics
    • CMake
    • Makefiles on Windows
    • STM32CubeIDE on Windows
    • IAR Embedded Workbench for ARM
    • Bazel
    • Custom Docker image
  • FAQ / Troubleshooting
    • FAQ
    • Troubleshooting
Powered by GitBook
On this page
  1. Compatibility guide

CMake

PreviousCompatibility specificsNextMakefiles on Windows

Last updated 1 month ago

CMake is able to generate a compilation database by itself at configuration. When using a CMake project you have two ways of generating it:

  • Using variable globally (from CMake 3.5)

  • Using variable for the target you want to analyze and optimize with beLow (from CMake 3.20)

Compilation database generation with CMake is only available with Makefiles generators and Ninja generators. Any other generator will ignore these variables and the compilation database will not be generated.

The first variable can be set directly from CMake command using flag -DCMAKE_EXPORT_COMPILE_COMMANDS=ON , or directly in the root CMakeLists.txt file:

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

However, if your CMake configuration has multiple targets, it is strongly recommended to activate compile commands generation only for your target, or it could lead to some undefined behaviour, if some sources are compiled multiple times with different commands in multiple targets.

To do that, start by forcing the global generation to off:

set(CMAKE_EXPORT_COMPILE_COMMANDS OFF)

Then, activate the generation for your target:

set_target_properties(mytarget PROPERTIES EXPORT_COMPILE_COMMANDS ON)

When running CMake command, compile_commands.json is then generated in the build directory. E.g, when running command:

cmake -B build -DCMAKE_BUILD_TYPE=Release .

the file ./build/compile_commands.json is generated.

In beLow, just enter the command as a Configure script when asked to, and beLow will find the file by name.

Try not to leave any compile_commands.json file in your project directory if you are able to generate it at configuration or build time, or it could be used in priority and lead to potential issues if not up to date or using absolute paths in copy mode.

CMAKE_EXPORT_COMPILE_COMMANDS
EXPORT_COMPILE_COMMANDS