UseJava fails when activating CMAKE_DISABLE_SOURCE_CHANGES (since 3.11 only)
Hello,
when passing -DCMAKE_DISABLE_SOURCE_CHANGES=on to our project, it fails with the following error message:
14:24:47 CMake Error at /usr/share/cmake/Modules/UseJava.cmake:514 (file):
14:24:47 file attempted to create a directory:
14:24:47 /builds/workspace/SimGrid-Multi/build_mode/Debug/node/simgrid-fedora-rawhide-64/build/SimGrid-3.19.90/build
14:24:47 into a source directory.
14:24:47 Call Stack (most recent call first):
14:24:47 tools/cmake/Java.cmake:64 (add_jar)
14:24:47 CMakeLists.txt:888 (include)
This is caused by https://github.com/Kitware/CMake/blob/master/Modules/UseJava.cmake#L514:
# ensure output directory exists
file (MAKE_DIRECTORY "${_add_jar_OUTPUT_DIR}")
My code calling this macro is the following https://github.com/simgrid/simgrid/blob/master/tools/cmake/Java.cmake#L64:
add_jar(simgrid-java_jar ${JMSG_JAVA_SRC} OUTPUT_NAME simgrid)
I have traced the execution of my cmake, and it takes this path https://github.com/Kitware/CMake/blob/master/Modules/UseJava.cmake#L509
set(_add_jar_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
So, UseJava is trying to create the directory CMAKE_CURRENT_BINARY_DIR, and this is detected as an error. This seems to be a cmake bug since my build is actually out of dir. The full log is available here: https://ci.inria.fr/simgrid/job/SimGrid-Multi/build_mode=Debug,node=simgrid-fedora-rawhide-64/5454/console (that log is a bit complex to read because we checkout the code, build an archive our of it (triggering a cmake run), unpack the archive elsewhere and then do an out-of-tree build on what we unpacked from the archive).
In my setting, the source is unpacked into /builds/workspace/SimGrid-Multi/build_mode/Debug/node/simgrid-fedora-rawhide-64/build/SimGrid-3.19.90 and the build dir is /builds/workspace/SimGrid-Multi/build_mode/Debug/node/simgrid-fedora-rawhide-64/build/SimGrid-3.19.90/build, which is CMAKE_SOURCE_DIR/build.
The jar is build in my root directory, and I think this is the problem: ${_add_jar_OUTPUT_DIR} is ${CMAKE_CURRENT_BINARY_DIR}, which is ${CMAKE_SOURCE_DIR}/build. So at the end, this directory IS in the source directory. But since that's also the root of the build dir, I think that this behavior should still be allowed.
Finally, this error only seem to occur on CMake 3.11. On other slaves, I have CMake 3.10, or CMake 3.9, and they all work like a charm with the exact same building conditions on my side.
Thanks for cmake, that's a great piece of software. Mt.