[CMake] Maximum path length in CMakeFiles

Brad King brad.king at kitware.com
Wed Aug 6 14:42:11 EDT 2008


Frans.Fuerst at elektrobit.com wrote:
> Here is a directory layout example which produces errors for me (actual names replaced for confidence reasons)

Thanks for the simplified example and analysis of character counts.

> C:\aaaaa\bbbbbbbbbb\CMake_Environment\ccccccccccccccccccccc\CMakeLists.txt
> 
> mentions
> 
> C:\aaaaa\bbbbbbbbbb\dddddddddddd\eeeeeeeeeeeeee\fffffffffffffffffff\gggggggggggggggggg\hhhhhhhhhhhhhhhhhhhhhhh\iiiiiiiiiiiiiiii\jjjjjjjjjjjjjjjjjjjjj.cpp
> 
> producing
> 
> C:\aaaaa\bbbbbbbbbb\CMake_Environment\ccccccccccccccccccccc\CMakeFiles\libraryname_xxxxxx.dir\C_\aaaaa\bbbbbbbbbb\dddddddddddd\eeeeeeeeeeeeee\fffffffffffffffffff\gggggggggggggggggg\hhhhhhhhhhhhhhhhhhhhhhh\iiiiiiiiiiiiiiii\jjjjjjjjjjjjjjjjjjjjj.cpp.o  (250 characters!!)

Okay, the reason the names are getting so long is that the source files
are not within what CMake thinks is the source tree (that containing the
top level CMakeLists.txt file).  Therefore every path to a source file
is treated as a full path, leading to long object file path names.  If
you put the CMakeLists.txt files in with the source then the object
names will be computed using a relative path.

> and will make nmake crash. And so does _every_ file with about(!!) the same file name length (about +- 1)
> 
> Important: Compiling a file in the same directory as jjjjjjjjjjjjjjjjjjjjj.cpp but with a three characters longer filename will compile fine.

That's probably because it pushes it over CMake's 250 character limit
which switches to the md5-hashed directory name and produces a *much*
shorter but totally unreadable object file path name.

> And here the proof of concept: renaming "CMake_Environment" to "CMake_Environm" (three characters shorter) will work fine for every file EXECPT the one that compiled before. obviously the critical part is the object file name length and it must not be near 250.

Perhaps the limit of 250 is slightly too high, and you just happen to
have a few files that squeezed in between the true limit (247?) and 250.

Can you download CMake's source and build it, but modify the limit to be
less than 250?  The limit is hard-coded in Source/cmLocalGenerator.cxx
in the function "cmLocalGeneratorCheckObjectName".  If lowering the
limit fixes your problem, I'll include the change in the next CMake release.

Thanks,
-Brad


More information about the CMake mailing list