3

My cmake --version is 2.8.12.2.

I configure my project build with these commands:

cmake ../klein/ -DBUILD_KLEIN_DEPS=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=1
cmake ../klein/ -DBUILD_KLEIN_DEPS=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake ../klein/ -DBUILD_KLEIN_DEPS=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=on
CMAKE_EXPORT_COMPILE_COMMANDS=1 cmake ../klein/ -DBUILD_KLEIN_DEPS=1 

From a clean build, and from a directory with an existing successful build. And want to see the compiler_commands.json file, but it does not appear.

At which moment should it be created: after cmake, or after make command? Where should it be in ./, or in ../klein directory? My cmake does not say anything about this option while it always complains about unused build variables.

Should it work from in a "dirty" directory, where I've performed one successful build, or does it work only on a fresh run in an empty folder?

Edit: I use a default generator "Unix Makefiles" on my ubuntu linux machine

Edit2: I'm not an author of the project under the question (I just want to explore it with rtags which requires compile_commands.json file), and I'm not very familiar with CMake mechanics. However, the CMakeLists.txt is probably configured as a super-build (it indeed downloads and builds dependencies - like llvm, z3, ...), and it includes ExternalProject, however it also builds the project itself (klein) from sources. So it's a mix, as I would say.

Necto
  • 2,594
  • 1
  • 20
  • 45
  • At first glance, try -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON The type specifier is important. – StAlphonzo Mar 19 '15 at 15:07
  • Hm. Now it complains about uselessness: `CMake Warning: Manually-specified variables were not used by the project: CMAKE_EXPORT_COMPILE_COMMANDS` – Necto Mar 19 '15 at 15:48
  • Hmm, strange as it sounds, I feel like that's progress. I don't yet know enough about CMAKE_EXPORT_COMPILE_COMMANDS yet to advise about how you're using it internally. You might consider the following thread, in case it's generator related. http://stackoverflow.com/questions/20059670/how-to-use-cmake-export-compile-commands – StAlphonzo Mar 19 '15 at 17:25

1 Answers1

2

Can you specify what generator your using? A quick scan of the cmake source from version 3.1.0 suggests that this command is still only available in the following 2 cases.

if(CMAKE_GENERATOR MATCHES "Unix Makefiles")

and

if(CMAKE_GENERATOR MATCHES "Ninja")

if you're using Visual Studio directly you're out of luck unless you want to add a patch to CMake. Otherwise, I know many Windows developers who've gone to Ninja. One advantage is that it's vastly faster than Visual Studio for building. If you are, in fact using Ninja or Unix Makefiles, then it's worth digging deeper.

StAlphonzo
  • 736
  • 5
  • 14
  • I use Unix Makefiles, and get a bunch of makefiles as an output of `cmake`. I've also tried Ninja generator, as suggested in the mentioned thread - I've got a Ninja make file, but no traces of compiler_commands.json – Necto Mar 19 '15 at 22:48
  • ok thanks, then I guess it's worth digging in. I will ask around work to see if anyone has more insight into this command. It's not one I've used before. Maybe someone else will chime in while we wait. – StAlphonzo Mar 20 '15 at 11:45
  • 1
    For starters, in your original post, you say your using the command make .... etc .. I'm guessing you meant cmake, right? So, to answer your other initial questions 1) it should work on a clean or dirty tree (errors always have me start clean for sanity though) 2) it will produce that file after cmake command, before make. And a final question for you. Is your project a superbuild, i.e, using ExternalProject? When I configure my superbuilds, I do not get the json file either. – StAlphonzo Mar 20 '15 at 12:07
  • Thank you for noticing, @StAlphonzo, I've fixed (make->cmake). The project indeed seems to be superbuild, as it downloads and builds dependencies, but it compiles sources as well. I've updated the question – Necto Mar 20 '15 at 13:08
  • hmm, very interesting problem. I have an externalProject only build that downloads/builds third party libraries but adds no libraries of its own. Running cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ../src/ on that project produces no compile_commands.json. If I add a single add_library(foo foo.c), for example, I do get the json in the root build directory. I think it would be good to see your projects CMake ( if possible ) I can only imagine something is going wrong there. Perhaps a very simple example which shows the failure would be easiest. – StAlphonzo Mar 20 '15 at 14:14