# How are duplicates resolved in the CMAKE\_MODULE\_PATH?

**URL:** <https://discourse.cmake.org/t/how-are-duplicates-resolved-in-the-cmake-module-path/4242>\
**Category:** Code\
**Created:** [October 10, 2021, 10:01am UTC](https://discourse.cmake.org/t/how-are-duplicates-resolved-in-the-cmake-module-path/4242 "2021-10-10T10:01:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jspanchu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jspanchu/32/1870_2.png) [@jspanchu](https://discourse.cmake.org/u/jspanchu)\
**Post date:** [October 10, 2021, 10:01am UTC](https://discourse.cmake.org/t/how-are-duplicates-resolved-in-the-cmake-module-path/4242/1 "2021-10-10T10:01:15Z")

</div>

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](https://github.com/emscripten-core/emscripten/blob/main/cmake/Modules/Platform/Emscripten.cmake#L77).

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](https://gitlab.kitware.com/vtk/vtk/-/issues/18263)

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 10, 2021, 8:50pm UTC](https://discourse.cmake.org/t/how-are-duplicates-resolved-in-the-cmake-module-path/4242/2 "2021-10-10T20:50:04Z")

</div>

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).
