Skip to content

CMAKE_EXPORT_COMPILE_COMMANDS: allow configuration per target

CMAKE_EXPORT_COMPILE_COMMANDS is a global setting currently, and might produce several commands for the same input file, e.g.:

{
  "directory": "…/Vcs/neovim/build",
  "command": "/usr/local/bin/cc -DINCLUDE_GENERATED_DECLARATIONS -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -D_GNU_SOURCE -Dnvim_test_EXPORTS -Iconfig -I../src -Isrc/nvim/auto -Iinclude -I../.deps/usr/include/luajit-2.0 -isystem ../.deps/usr/include   -Werror -g -fPIC    -DUNIT_TESTING  -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=always -Wno-array-bounds  -Wno-conversion -o src/nvim/CMakeFiles/nvim-test.dir/edit.c.o   -c …/Vcs/neovim/src/nvim/edit.c",
  "file": "…/Vcs/neovim/src/nvim/edit.c"
},

and

{
  "directory": "…/Vcs/neovim/build",
  "command": "/usr/local/bin/cc -DINCLUDE_GENERATED_DECLARATIONS -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -D_GNU_SOURCE -Iconfig -I../src -Isrc/nvim/auto -Iinclude -I../.deps/usr/include/luajit-2.0 -isystem ../.deps/usr/include   -Werror -g   -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=always -Wno-array-bounds  -Wno-conversion -o src/nvim/CMakeFiles/nvim.dir/edit.c.o   -c …/Vcs/neovim/src/nvim/edit.c",
  "file": "…/Vcs/neovim/src/nvim/edit.c"
},

The differences here are the output file, and different compile definitions.

This then results in clang-tidy and clang-check to running basically the same command twice.

It would be nice if this could be configured as a (target) property for example, so that it could be made to only be used with the main target.

(clang-tidy / clang-check themselves do not support options for running a particular set of those commands only, e.g. only the first one)

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information