<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mar. 11 juin 2019 à 05:16, Staley, Martin Frank via CMake <<a href="mailto:cmake@cmake.org">cmake@cmake.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div id="gmail-m_5853066602706148405divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);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.<span style="font-family:Arial,Helvetica,sans-serif;font-size:small;color:rgb(34,34,34)"> </span></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div id="gmail-m_5853066602706148405divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr"><div>
<br>
Is this in fact available, and my googling skills aren't up to par?</div></div></div></blockquote><div><br></div><div><div>This is not exactly what you are looking for but you may certainly use the CMake file-api:</div><div><a href="https://cmake.org/cmake/help/v3.14/manual/cmake-file-api.7.html#manual:cmake-file-api(7)">https://cmake.org/cmake/help/v3.14/manual/cmake-file-api.7.html#manual:cmake-file-api(7)</a></div><div>in order to get what you want (namelly the list of files for a given target)</div></div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Eric<br></div></div></div></div></div></div>