Possible to partially override files in ${CMAKE_ROOT}/Modules?

Hello,

We’re trying to use CMake with Embarcadero C++ Builder 10. In order to be able to do so, we need to replace the default Platform/Windows-Embarcadero.cmake with a version that is provided with C++ Builder, as instructed there: http://docwiki.embarcadero.com/RADStudio/Sydney/en/Using_CMake_with_C%2B%2B_Builder

An issue we have with this is that this is not possible in some environments, like build servers, or if developers are not admins on their machine. Is there a way to tell CMake to look for module files into a custom directory first, before looking at the default ${CMAKE_ROOT}/Modules?

I tried, without success, to prepend the path to Embarcadero-provided one to the CMAKE_MODULE_PATH, hoping that it would cause CMake to look there first:
cmake_minimum_required(VERSION 3.14)
list(PREPEND CMAKE_MODULE_PATH “C:/Program Files (x86)/Embarcadero/Studio/21.0/cmake/Modules”)
set(CMAKE_C_COMPILER “bcc32x”)
set(CMAKE_CXX_COMPILER “bcc32x”)
project(MyProject)

Thanks

CMake’s shipped modules prefer to include each other from the same root (they largely use ${CMAKE_ROOT} or ${CMAKE_CURRENT_LIST_DIR} to make absolute paths of includes of each other rather than CMAKE_MODULE_PATH-moderated searches). You’ll likely need to provide the entire include chain above the “lowest” file that you need to change and then finally hook into CMake-provided files.

Cc: @brad.king

See policy CMP0017. CMake does not want projects to override a builtin module that is included from another builtin module. Otherwise those modules become a public API and limits refactoring. The lack of that policy in the old days produced several cases where that caused problems, and in at least one such case we forever need to do something special in every find module to include FPHSA safely.

Embarcadero should contribute whatever changes are needed to CMake instead of telling people to modify their installations.

Thanks for the reply. That makes perfect sense (sadly for my current use case)