4

I was wondering if there is any possibility to override an existing (shipped with CMake) find module with my own? This is so I can supply my slightly updated module with my project without forcing anyone to replace the one that is shipped with CMake.

I tried doing the following:

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "cmake/Modules/FindBullet.cmake")

where "cmake/Modules/FindBullet.cmake" is in my project directory, but it did not seem to work.

prayforbacon
  • 165
  • 5

1 Answers1

5

The CMAKE_MODULE_PATH must be set to the directory containing your version of the find module file:

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
sakra
  • 62,199
  • 16
  • 168
  • 151
  • I'm experiencing issues with this approach. In my case, I need to override `FindProtobuf.cmake`. The problem is, it includes `SelectLibraryConfigurations.cmake` (which includes more files) and the overridden version tries to look for this file in the same location which fails. This could be connected with `CMAKE_MODULE_PATH` being an empty list before appending my own path. I ended up copying all included modules as well, but this is a poor solution. Any idea how to work around it besides adding original path to `CMAKE_MODULE_PATH`? (Why it is not there from the start?) – Adam Badura Jul 10 '20 at 08:24
  • BTW, we have used `list` instead: `list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)` although I think it doesn't matter in the end. – Adam Badura Jul 10 '20 at 08:25
  • Oh... I found out the root of the problem myself. `FindProtobuf.cmake` does `include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)` which is why I need to copy those files. :( – Adam Badura Jul 10 '20 at 09:44