`find_path` unable to find correct path

I’m the author of a project (drone-flight-visualizer) using RapidJSON as a dependency, which I add with add_subdirectory. I’m using CMake 2.28.1.
RapidJSON is having trouble with the find_path call not being able to find the path to the source of GTest, a dependency of RapidJSON, which is located in the thirdparty folder inside the RapidJSON source dir.
As it can be seen in the first log, find_path ends up finding the root CMakeLists.txt file of my project instead of the GTest one, although a path to the correct GTestSrc location is passed as arguments to the find_path call.
It ends up recursively calling my CMakeLists.txt and obviosly errors out when trying to add the same targets twice.

I learned about NO_DEFAULT_PATH and after using it, it seems to work (see second log), but I don’t understand why. The default paths that find_path adds to the search locations don’t look suspicious to me.

I’ve tested this on the two machines I have, both running Windows 11. One always exhibits the issue, but I wasn’t able to reproduce it on the other one. I’m not able to spot any significant configuration differences between the two machines as both were configured the same way following the same steps from a clean starting point.

Not working log
CMake source with variables expanded:

FIND_PATH(GTEST_SOURCE_DIR
    NAMES CMakeLists.txt src/gtest_main.cc
    PATHS ;C:/Users/<user>/Desktop/drone-flight-visualizer/libraries/rapidjson/7fa9472779f197111f9f21fd80c82c46328cd5cb/CMakeModules/../thirdparty/gtest/googletest
)

find_path debug output:

CMake Debug Log at libraries/rapidjson/7fa9472779f197111f9f21fd80c82c46328cd5cb/CMakeModules/FindGTestSrc.cmake:14 (FIND_PATH):
  find_path called with the following settings:

    VAR: GTEST_SOURCE_DIR
    NAMES: "CMakeLists.txt"
           "src/gtest_main.cc"
    Documentation: Path to a file.
    Framework
      Only Search Frameworks: 0
      Search Frameworks Last: 0
      Search Frameworks First: 0
    AppBundle
      Only Search AppBundle: 0
      Search AppBundle Last: 0
      Search AppBundle First: 0
    CMAKE_FIND_USE_CMAKE_PATH: 1
    CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
    CMAKE_FIND_USE_INSTALL_PREFIX: 1

  find_path considered the following locations:

    C:/VulkanSDK/1.3.268.0/Bin/CMakeLists.txt
    C:/Windows/System32/CMakeLists.txt
    C:/Windows/CMakeLists.txt
    C:/Windows/System32/wbem/CMakeLists.txt
    C:/Windows/System32/WindowsPowerShell/v1.0/CMakeLists.txt
    C:/Windows/System32/OpenSSH/CMakeLists.txt
    C:/Program Files/Git/cmd/CMakeLists.txt
    C:/Program Files/CMake/bin/CMakeLists.txt

  The item was found at

    C:/Users/<user>/Desktop/drone-flight-visualizer/CMakeLists.txt

Call Stack (most recent call first):
  libraries/rapidjson/7fa9472779f197111f9f21fd80c82c46328cd5cb/test/CMakeLists.txt:1 (find_package)

Working log
CMake source with variables expanded:

FIND_PATH(GTEST_SOURCE_DIR
    NAMES CMakeLists.txt src/gtest_main.cc
    PATHS ;C:/Users/<user>/Desktop/drone-flight-visualizer/libraries/rapidjson/7fa9472779f197111f9f21fd80c82c46328cd5cb/CMakeModules/../thirdparty/gtest/googletest
    NO_DEFAULT_PATH
)

find_path debug output:

CMake Debug Log at libraries/rapidjson/7fa9472779f197111f9f21fd80c82c46328cd5cb/CMakeModules/FindGTestSrc.cmake:14 (FIND_PATH):
  find_path called with the following settings:

    VAR: GTEST_SOURCE_DIR
    NAMES: "CMakeLists.txt"
           "src/gtest_main.cc"
    Documentation: Path to a file.
    Framework
      Only Search Frameworks: 0
      Search Frameworks Last: 0
      Search Frameworks First: 0
    AppBundle
      Only Search AppBundle: 0
      Search AppBundle Last: 0
      Search AppBundle First: 0
    NO_DEFAULT_PATH Enabled

  find_path considered the following locations:

  The item was found at

    C:/Users/<user>/Desktop/drone-flight-visualizer/libraries/rapidjson/7fa9472779f197111f9f21fd80c82c46328cd5cb/thirdparty/gtest/googletest/CMakeLists.txt

Call Stack (most recent call first):
  libraries/rapidjson/7fa9472779f197111f9f21fd80c82c46328cd5cb/test/CMakeLists.txt:1 (find_package)

I’m not sure how to debug this further, I remain available for providing further logs or information.
Thanks in advance.

I would recommend not searching for CMakeLists.txt as it is not unique enough to give a unique result. Just searching for gtest_main.cc seems like a better approach.

Additionally, HINTS are preferred over PATHS when searching, so you could give HINTS instead of PATHS for “really should be here based on context” situations.