finddoxygen.cmake sometimes fails with a (Permission denied) error while writing CMakeDoxygenDefaults.cmake
The problem reproduces with CMake and Visual Studio 2019. Reproducable with several versions of CMake and Doxygen (on my PC).
The same problem is also reported here: https://developercommunity.visualstudio.com/content/problem/1066492/cmake-error-file-file-failed-to-open-for-writing-p.html
The issue might be related to having
Symantec endpoint protection all monitoring my filesystem while the finddoxygen.cmake incrementally generates CMakeDoxygenDefaults.cmake
1> [CMake] -- Found Doxygen: <my_tools_path>/tool_doxygen/doxygen_win32/doxygen.exe (found version "1.8.17 (b5fa3cd1c6e6240e20d3b80a70e3f04040b32021*)") found components: doxygen dot missing components: mscgen dia 1> [CMake] CMake Error at <my_tools_path>/tool_cmake/cmake_win64/share/cmake-3.16/Modules/FindDoxygen.cmake:749 (file): 1> [CMake] file failed to open for writing (Permission denied): 1> [CMake] 1> [CMake] <my_project_path>/generated/vs-Ninja/win-msvc-x64/debug/CMakeDoxygenDefaults.cmake 1> [CMake] Call Stack (most recent call first): 1> [CMake] private/src/bundle/CMakeLists.txt:58 (find_package)
I have a working fix, where the contents of CMakeDoxygenDefaults.cmake are incrementally build up as a string. When the source input file is completely parsed, the contents are written to CMakeDoxygenDefaults.cmake. I will try to merge my fix to master.
Note: I think this approach should be used for all modules...