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.