How are duplicates resolved in the CMAKE_MODULE_PATH?

What happens when CMAKE_MODULE_PATH has more than one module with identical file names but different contents?

A naive google search for “CMAKE_MODULE_PATH duplicates” doesn’t show any helpful results… The documentation doesn’t help either.

I am trying to find the reason for inconsistent OpenGL include dirs in VTK with the Emscripten toolchain and noticed that the toolchain inserts FindOpenGL.cmake to the module path here.

But at the same time VTK provides its own FindOpenGL.cmake at VTK/CMake/patches/99/FindOpenGL.cmake. So does this mean VTK’s module overrides the one from Emscripten? It looks like it.

At first sight, this seems a valid behavior to me but is causing a lot of compiler errors as reported in VTK

It works like -I searching. The first instance of a file named as requested in the CMAKE_MODULE_PATH entries or the default search paths wins. Once such a file is found, the search is over.

Emscripten should get its changes upstreamed to CMake itself (and then VTK will pull them down again).