<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p></p>
<div>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.<br>
<br>
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....<br>
<br>
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.<br>
<br>
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.<br>
<br>
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.<br>
<br>
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.<br>
<br>
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.<br>
<br>
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?<br>
<br>
</div>
<p></p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(255, 255, 255); font-family: Calibri, Helvetica, sans-serif, "EmojiFont", "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
--<br>
Martin Staley<br>
CCS-7, Applied Computer Science<br>
Mail Stop B287<br>
Los Alamos National Laboratory<br>
Los Alamos, NM 87545<br>
Office: 03/508/122<br>
Phone: 1-505-667-7108<br>
<br>
</div>
</div>
</div>
</div>
</body>
</html>