3

I've got a project with a very tall source tree and sadly I'm stuck developing on Windows atm -- I hit the dreaded Windows file path length limit: (note: actual paths and names changed for anonymity, so the lengths reported won't be quite right. The real thing is even longer)

The object file directory
C:/Users/ccj/work/my-project/submodules/sdk-module/engine-module/platform/android/sdk-engine/.externalNativeBuild/cmake/fastDebug/armeabi-v7a/CMakeFiles/CMakeTmp/CMakeFiles/cmTC_0f0bd.dir/
has 226 characters.  The maximum full path to an object file is 250
characters (see CMAKE_OBJECT_PATH_MAX).  Object file
CMakeCXXCompilerABI.cpp.o
cannot be safely placed under this directory.  The build may not work correctly.

When I actually try to build, I get a garbled nonsense error during C++ compilation mentioning output files/dirs not existing which I've come to associate with this problem:

...
[28/74] Building CXX object CMakeFiles/my-engine.dir/C_/Users/ccj/work/my-project/submodules/sdk-module/engine-module/platform/android/services/MyTouchService.cpp.o
ninja: build stopped: .
ninja: error: mkdir(CMakeFiles/my-engine.dir/C_/Users/ccj/work/my-project): No such file or directory

I already set the Gradle buildDir to a higher directory to have a partially out-of-source build:

allprojects {
  buildDir = "${high_dir}/build_all/${project.name}-build"
}

However, the C++ object files are apparently still getting built in-source (per the cmake and build errors above).

According to this answer and this answer, cmake doesn't really allow you to change where object files are built (at least directly). However, I'm not 100% convinced there isn't a way around my specific problem -- I don't want anything fancy, simply to be able to build within OS file path limitations. I can't modify the build variants, supported ABIs, or source tree structure.

What are my options? I'm happy enough to move my project up to the root of my %USERPROFILE% dir per this answer, but that doesn't shave off much and the build still fails. The trouble with that strat is that the amount you can move up in the filesystem is bounded but the path length of generated build files is not. Gradle solutions to e.g. shove the externalNativeBuild dir itself someplace else and maybe circumvent cmake entirely would be fine.

EDIT: Checking out Windows docs re: enabling long file paths in the registry here looked promising, but it didn't help anything AFAICS. OP in this Gitlab post had the same result. After updating the registry and rebooting, I also tried putting set(CMAKE_OBJECT_PATH_MAX 9999) in one of my top level CMakeLists.txt files; sadly I still see the 'The maximum full path to an object file is 250 characters (see CMAKE_OBJECT_PATH_MAX)' warning from cmake (for the top level module I added that property set directive to as well as the others) and the build still fails with a similar missing generated file/dir error.

CCJ
  • 1,619
  • 26
  • 41
  • 1
    Related https://gitlab.kitware.com/cmake/cmake/-/issues/19675 – Richard Critten Mar 20 '21 at 22:40
  • 1
    Also might help https://stackoverflow.com/questions/33905687/error-file-path-too-long-on-windows-keep-below-240-characters – Richard Critten Mar 20 '21 at 22:49
  • 1
    I believe this is a Ninja problem and not a CMake problem. CMake itself has no problem using long paths. –  Mar 21 '21 at 15:43
  • @jpr33 I'd be happy with a Ninja based solution too! All I know is somebody in the toolchain has a problem with the path length and the root of the problem seems to be where cmake is building object files. If there's a way to tell Gradle to put the .externalNativeBuild and .cxx dirs at a higher level that might work too, but I haven't found a way to do so yet. – CCJ Mar 22 '21 at 17:50
  • @RichardCritten https://stackoverflow.com/questions/33905687/error-file-path-too-long-on-windows-keep-below-240-characters unfortunately doesn't do the trick since its thesis is basically to move the project dir up as high as possible. I tried moving to the root of my %USERPROFILE% dir but it didn't help -- the source tree is still too tall (or rather, the c++ is pretty far down in a tall source tree such that the generated object file paths wind up way too tall). – CCJ Mar 22 '21 at 17:54
  • 2
    I found the Ninja issue: https://github.com/ninja-build/ninja/issues/1900 –  Mar 23 '21 at 00:54

0 Answers0