Add "${ROOTSYS}/compile_flags.txt" files to "official" ROOT binary releases

I’ve recently started to play with adding Language Server Protocol (LSP) support to my editor.
For C++ code, I am trying to use the clangd language server.

It turns out that there are problems with ROOT binary releases.
One gets various errors in form, e.g.:

#include "TRandom.h" In included file: 'ROOT/RConfig.hxx' file not found with <angled> include; use "quotes" instead

#include <ROOT/RConfig.hxx> In included file: 'RConfigure.h' file not found

It seems I have found a simple fix (for binary releases), shown below.
One needs to create a simple “${ROOTSYS}/compile_flags.txt” file.
Could you, please, add the procedure which automatically creates appropriate “${ROOTSYS}/compile_flags.txt” files into your procedure that creates the “official” ROOT binary releases (note: this file should not be made if there exists a “${ROOTSYS}/compile_commands.json” file).

#!/usr/bin/env bash
if [ -n "${ROOTSYS}" ] ; then
    COMPILE_COMMANDS="${ROOTSYS}/compile_commands.json"
    COMPILE_FLAGS="${ROOTSYS}/compile_flags.txt"
    if [ ! -e "${COMPILE_COMMANDS}" -a ! -e "${COMPILE_FLAGS}" ] ; then
        echo "--language=c++" > "${COMPILE_FLAGS}"
        echo "$(root-config --auxcflags)" | sed 's/ /\n/g' >> "${COMPILE_FLAGS}"
        echo "-Iinclude" >> "${COMPILE_FLAGS}"
        touch -h -r "${ROOTSYS}/bin" "${COMPILE_FLAGS}" "${ROOTSYS}"
    fi
fi

Note that one may need to remove some flags, which the “root-config --auxcflags” call returned, that are not valid “Clang command line arguments”.

Hello @Wile_E_Coyote ,
thank you for the suggestion, feel free to open a feature request at Sign in to GitHub · GitHub if you want this to be tracked.

CC: @Axel

Cheers,
Enrico

Interesting idea. QtCreator C++ LSP (Using Language Servers | Qt Creator Manual) will also be based on clangd soon Qt Creator and clangd: An Introduction so it would be a nice feature for it, too. See other integration options in Coding in ROOT with the horsepower of an F1 - ROOT

Maybe it’s better to have the JSON variant, as it can be enabled by just adding one flag to CMake when building

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1

The “compile_commands.json” file will only work if you build ROOT yourself and you keep the “source” and “build” directories.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.