CMAKE_EXPORT_COMPILE_COMMANDS.rst 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. CMAKE_EXPORT_COMPILE_COMMANDS
  2. -----------------------------
  3. .. versionadded:: 3.5
  4. Enable/Disable output of compile commands during generation.
  5. If enabled, generates a ``compile_commands.json`` file containing the exact
  6. compiler calls for all translation units of the project in machine-readable
  7. form. The format of the JSON file looks like:
  8. .. code-block:: javascript
  9. [
  10. {
  11. "directory": "/home/user/development/project",
  12. "command": "/usr/bin/c++ ... -c ../foo/foo.cc",
  13. "file": "../foo/foo.cc",
  14. "output": "../foo.dir/foo.cc.o"
  15. },
  16. ...
  17. {
  18. "directory": "/home/user/development/project",
  19. "command": "/usr/bin/c++ ... -c ../foo/bar.cc",
  20. "file": "../foo/bar.cc",
  21. "output": "../foo.dir/bar.cc.o"
  22. }
  23. ]
  24. This is initialized by the :envvar:`CMAKE_EXPORT_COMPILE_COMMANDS` environment
  25. variable, and initializes the :prop_tgt:`EXPORT_COMPILE_COMMANDS` target
  26. property for all targets.
  27. .. note::
  28. This option is implemented only by :ref:`Makefile Generators`
  29. and :ref:`Ninja Generators`. It is ignored on other generators.
  30. This option currently does not work well in combination with
  31. the :prop_tgt:`UNITY_BUILD` target property or the
  32. :variable:`CMAKE_UNITY_BUILD` variable.