Add capability to propagate `CMAKE_MODULE_PATH` from package to caller
zero9178 opened this issue · comments
Hope I didn't miss anything in the docs, code nor other issues. I very recently started using CPM and it worked great without any troubles installing. The only slight hiccup I had was that my expectation was that CMAKE_MODULE_PATH
from packages used would be propagated to the caller so I could use include
with a cmake module from an included package.
My concrete case was using Catch2 which has a Catch.cmake
in its extras
directory for test registration with ctest
.
Their docs explicitly state that one simply has to do include(Catch)
so naturally my first attempt was:
CPMAddPackage("gh:catchorg/Catch2@3.3.2")
include(Catch)
which failed due to not finding Catch.cmake
. I later found that Catch2 even goes out of their way to make sure when included as a subdirectory that it propagates the CMAKE_MODULE_PATH
to the caller.
https://github.com/catchorg/Catch2/blob/8008625d7e00d42120b1e10e991f044c280dc88a/CMakeLists.txt#L49
Ideally CPM would forward it (or add an option to do so) to the caller of CPMAddPackage
too if that is possible.
My luckily very easy workaround for now was to simply add list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
to the cmake file.
Hey thanks for the issue! This is an interesting use-case and breaking for CPM as it adds an additional scope between add_subdirectory
and the caller. However, if it a common pattern, it might make sense to add an extra parameter to CPMAddPackage
, that could be used to specify variables that should be promoted to the outer scope.
Until then, manually updating the module path as you did seems to be a good way to go.