Search code examples
cmakecompiler-errorsdependenciesninja

CMake 3.20.6 : missing dependency file


So my project uses CMake as mentionned (with Ninja as a generator), and I have a server that builds my stuff for me, and it fails to do so telling me :

../path/Foo.cpp:309:1: fatal error: opening dependency file \path\in\build\folder\then\CMakeFiles\folder\Foo.cpp.obj.d: No such file or directory
 }
 ^
compilation terminated.

Now, my research tells me that this strange file name is actually generated by CMake and is supposed to contain all the dependencies for this compilation unit. I'm fine with that, but here are two strange things for me :

  • If I compile locally, it works (and yes, I checked, I'm compiling the same thing)
  • There is no such .d file anywhere for me locally when I compile.

The file is mentioned in DEP_FILE = in build.ninja for this compilation unit, at least on my local build.

Now, I am actually not very knowledgeable about the inner workings of CMake and/or Ninja. Any leads as to what can be going on, or where to look, or what to look for, or even how to think about it ?


Solution

  • Ok so as @Tsyvarev suggested, this .d file was actually never generated in the first place because its filename is too long. This is a more recent limitation of the version of Ninja that comes with CMake 3.20 something (as opposed to 3.19 something which I had previously). Seems that enabling Long Paths in Windows in the Local Group Policy Editor doesn't help. It rather seems to be an open point on Ninja's side. I have worked around this by playing with filenames and running my build from a virtual drive mapped to my project folder. This circumvents the problem, but doesn't really solve it ...

    CMake was actually warning me at configuration time :

    CMake Warning in path/to/CMakeLists.txt:
      The object file directory
    
        \path\in\build\folder\then\CMakeFiles\folder
    
      has 190 characters.  The maximum full path to an object file is 250
      characters (see CMAKE_OBJECT_PATH_MAX).  Object file
    
        path/to/Foo.cpp.obj
    
      cannot be safely placed under this directory.  The build may not work
      correctly.