This is a common pattern in CMake’s own find-modules. See FindCURL.cmake for an example of how we do it.
FindCURL.cmake