[PATCH] Generate a clang CompilationDatabase when running CMake.

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 10:21:23 PST 2015


On Mon, Dec 14, 2015 at 10:51 PM, Justin Lebar via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Thanks a lot, Justin.  I don't have commit access; would you mind
> pushing this patch for me?

Landed in r255789.

- Ben

>
> -Justin
>
> On Mon, Dec 14, 2015 at 11:42 AM, Justin Bogner <mail at justinbogner.com> wrote:
>> Justin Lebar <jlebar at google.com> writes:
>>>> We already document to do this on the command line in all of the tooling
>>>> docs
>>>
>>> FWIW that wasn't where I looked as someone new to the project; it
>>> doesn't show up in http://llvm.org/docs/GettingStarted.html.  Of
>>> course that page can't be a guide to all conceivable options.
>>>
>>>> does it actually make sense to default this to on?
>>>
>>> My thought was, one less thing you have to remember to do.  It's
>>> annoying enough that you have to add a .ycm_extra_config.
>>>
>>> In fact, while I have your attention...do you have any thoughts on how
>>> we might make adding a .ycm_extra_config file easier?  We could check
>>> one in to llvm/utils with instructions to copy it down to the root
>>> directory.  The problem with just sticking it in the root dir is that
>>> this file needs to specify where your object files are located.
>>
>> Sorry, I don't use YCM so I'm not really familiar with the problem.
>>
>>> That seems better than asking people to cargo-cult from the canonical
>>> .ycm_extra_config, which requires some minor but nontrivial
>>> modifications to work with llvm.
>>>
>>>> I suppose as long as this is fast to do (I haven't checked, is it?)
>>>> there's no harm in it.
>>>
>>> Doesn't appear to be significant.  On my macbook pro, after warming up
>>> the disk cache, I ran
>>>
>>> $ time cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
>>>
>>> Without the patch (ran 3 times):
>>>
>>> real 0m17.875s
>>> user 0m10.563s
>>> sys 0m5.935s
>>>
>>> real 0m18.335s
>>> user 0m10.948s
>>> sys 0m5.981s
>>>
>>> real 0m17.757s
>>> user 0m10.562s
>>> sys 0m5.836s
>>>
>>> With the patch:
>>>
>>> real 0m18.461s
>>> user 0m10.737s
>>> sys 0m6.215s
>>>
>>> real 0m18.243s
>>> user 0m10.805s
>>> sys 0m6.022s
>>>
>>> real 0m17.724s
>>> user 0m10.715s
>>> sys 0m6.009s
>>
>> Fair enough. This LGTM.
>>
>>> On Mon, Dec 14, 2015 at 10:53 AM, Justin Bogner <mail at justinbogner.com> wrote:
>>>> Justin Lebar via llvm-commits <llvm-commits at lists.llvm.org> writes:
>>>>> This generates a compile_commands.json file, which tells tools like
>>>>> YouCompleteMe and clang_complete exactly how to build each source file.
>>>>> ---
>>>>>  CMakeLists.txt | 4 ++++
>>>>>  1 file changed, 4 insertions(+)
>>>>> diff --git a/CMakeLists.txt b/CMakeLists.txt
>>>>> index fc46413..208c0a8 100644
>>>>> --- a/CMakeLists.txt
>>>>> +++ b/CMakeLists.txt
>>>>> @@ -86,6 +86,10 @@ set(CMAKE_MODULE_PATH
>>>>>    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
>>>>>    )
>>>>>
>>>>> +# Generate a CompilationDatabase (compile_commands.json file) for our build,
>>>>> +# for use by clang_complete, YouCompleteMe, etc.
>>>>> +set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
>>>>
>>>> We already document to do this on the command line in all of the tooling
>>>> docs, does it actually make sense to default this to on? I suppose as
>>>> long as this is fast to do (I haven't checked, is it?) there's no harm
>>>> in it.
>>>>
>>>>> +
>>>>>  option(LLVM_INSTALL_UTILS "Include utility binaries in the
>>>>> 'install' target." OFF)
>>>>>
>>>>>  option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files
>>>>> in the 'install' target." OFF)
>>>>> _______________________________________________
>>>>> llvm-commits mailing list
>>>>> llvm-commits at lists.llvm.org
>>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list