compilation database file generation for GCC and IAR toolchains

I’m generating a compilation database file compilation_commands.json by setting set(CMAKE_EXPORT_COMPILE_COMMANDS ON) in the cmake.

The compilation_commands.json file was generating for both GCC & IAR toolchains. Now the issue is for IAR the included paths generating with double backward slashes. See below for example.

“directory”: “D:\\iar-release”,
“command”: "D:\\IAR\\Ver8_50_1\\arm\\bin\\iccarm.exe --silent D:AppStub.c -Itmh -
I…\\…\\product\application -I…\\…\\shared\\common -I…\\…\\shared
“file”: “D:\AppStub.c”

whereas for GCC, it is with forwarding slash as expected.

Will it generate based on the toolchain?

Please help me in resolving.

Are the backslashes a problem? Aren’t the paths the same either way? Though it is odd that it differs based on toolchain…

Hi Ben,

Thanks for the reply!

Actually, I’m parsing this JSON file to the cppcheck tool for static analysis. This tool is ignoring the included paths (-I…\…\product\application -I…\…\shared\common -I…\…\shared) with double backslashes.

Is there a way in CMake to generate compilation_commands.json with included paths single forward slashes?

It seems like a bug that it transforms in one case but not the other. Investigation as to the difference would be needed. Could you create a small, simple example project that shows the difference when configured with each toolchain?

Hi Ben,

Cppcheck latest version accepting the paths even with double backslashes.

Thank you.