I'm using the Clang/LLMV APIs to build a code analysis tool that gives my users
some additional analysis of their C++ codes, above and beyond what the
compiler, proper, provides.
With a set(CMAKE_EXPORT_COMPILE_COMMANDS ON) in CMakeLists.txt, cmake emits a
"compilation database" file, compile_commands.json, that contains exact
compilation commands for all relevant source files. The .json can be consumed
by my analysis tool to get what it needs. Except....
Here's the problem. (And I've tried various googles, but nothing panned out.)
compile_commands.json contains data for *all* source files involved in *any*
executable for which cmake emits Makefile rules. My analysis tool needs input
that reflects those (and only those) source files that are involved in any
*one* of the (generally more than one) executables.
EXAMPLE. Say I have some general C++ constructs in a.cc, b.cc, and c.cc, and
two C++ executables (roughly speaking, with a main()): foo.cc and bar.cc.
Assume further that, linkage-wise, foo.cc needs the material from a.cc and b.cc
(but not c.cc), while bar.cc needs the material from b.cc and c.cc (but not
a.cc). These dependencies are of course programmed into a CMakeLists.txt.
In this situation, cmake will emit a compile_commands.json that has commands
for all five sources: {a.cc, b.cc, c.cc, foo.cc, bar.cc}. But my analysis tool,
run thereon, doesn't know how to divvy up the various elements, and it ends up
reporting, among other things, the moral equivalent of multiply-defined symbol
errors.
Ideally, I'd love to have a way that Cmake could emit, say, foo.json containing
only the compile commands for {a.cc, b.cc, foo.cc}, and a bar.json containing
only the commands for {b.cc, c.cc, bar.cc}. Basically, individualized
compilation databases for each executable target.
There are, of course, alternatives. Given additional input, my tool could pull
(only) the proper entries from the current, aggregated compile_commands.json.
Or, post-cmake, I could allow for a dry-run verbose make of a single
executable, and parse out the requisite information. For users, however, and
for simplicity's sake, I'm hoping for something more direct. CMake has what I
need, in some form - it must, in order to create the Makefile! So, life would
be absolutely fabulous if this existing knowledge could be used to create
executable-specific .json databases as outlined above.
Is this in fact available, and my googling skills aren't up to par? If it
isn't, might it be considered for a future CMake release?
--
Martin Staley
CCS-7, Applied Computer Science
Mail Stop B287
Los Alamos National Laboratory
Los Alamos, NM 87545
Office: 03/508/122
Phone: 1-505-667-7108
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake