Repository: conan-io/conan

Issue:
`cmake_find_package_multi` might need also CMAKE_MODULE_PATH
`cmake_flags.py` line 329, add also `CMAKE_MODULE_PATH` when using that generator. Looks like the `find_dependency`  needs it.


Discussion:
As I see often issues with ```CMAKE_MODULE_PATH```, ```CMAKE_PREFIX_PATH```, ... so I want to add a clarification that maybe the "issue search engine" will find this.


What variables are used for searching files depends on the **find_package** _call signature_ a caller issued.

If using the [basic / module](https://cmake.org/cmake/help/latest/command/find_package.html?highlight=find_package#basic-signature-and-module-mode) mode then only ```CMAKE_MODULE_PATH``` is needed. This mode searches only for files named ```Find<PackageName>.cmake```.

If using the [full / config](https://cmake.org/cmake/help/latest/command/find_package.html?highlight=find_package#full-signature-and-config-mode) mode then ```CMAKE_MODULE_PATH``` is not considered at all. Instead ```CMAKE_PREFIX_PATH``` and other variables are used. This mode searches only for files named ```<PackageName>Config.cmake``` or ```<lower-case-package-name>-config.cmake``` or if given the **NAMES** argument (```<NAME>Config.cmake``` or ```<lower-case-name>-config.cmake```) with a more advanced search algorythm ([see here](https://cmake.org/cmake/help/latest/command/find_package.html?highlight=find_package#search-procedure)).

As the [CMakeFindDependencyMacro](https://cmake.org/cmake/help/latest/module/CMakeFindDependencyMacro.html) forwards the given arguments to ```find_package``` the same rules apply as with ```find_package```.

Resolving patch:
diff --git a/conans/client/build/cmake_flags.py b/conans/client/build/cmake_flags.py
--- a/conans/client/build/cmake_flags.py
+++ b/conans/client/build/cmake_flags.py
@@ -324,13 +324,15 @@ def get_definitions(self):
 
         # Adjust automatically the module path in case the conanfile is using the
         # cmake_find_package or cmake_find_package_multi
+        install_folder = self._conanfile.install_folder.replace("\\", "/")
         if "cmake_find_package" in self._conanfile.generators:
-            ret["CMAKE_MODULE_PATH"] = self._conanfile.install_folder.replace("\\", "/")
+            ret["CMAKE_MODULE_PATH"] = install_folder
 
         if "cmake_find_package_multi" in self._conanfile.generators:
             # The cmake_find_package_multi only works with targets and generates XXXConfig.cmake
-            # that require the prefix path, not the module path
-            ret["CMAKE_PREFIX_PATH"] = self._conanfile.install_folder.replace("\\", "/")
+            # that require the prefix path and the module path
+            ret["CMAKE_PREFIX_PATH"] = install_folder
+            ret["CMAKE_MODULE_PATH"] = install_folder
 
         ret.update(self._get_make_program_definition())
 


Test patch:
diff --git a/conans/test/unittests/client/generators/cmake_test.py b/conans/test/unittests/client/generators/cmake_test.py
--- a/conans/test/unittests/client/generators/cmake_test.py
+++ b/conans/test/unittests/client/generators/cmake_test.py
@@ -6,6 +6,7 @@
 from conans.client.conf import default_settings_yml
 from conans.client.generators.cmake import CMakeGenerator
 from conans.client.generators.cmake_multi import CMakeMultiGenerator
+from conans.client.build.cmake_flags import CMakeDefinitionsBuilder
 from conans.model.build_info import CppInfo
 from conans.model.conan_file import ConanFile
 from conans.model.env_info import EnvValues
@@ -273,3 +274,18 @@ def settings_are_generated_tests(self):
         self.assertIn('set(CONAN_SETTINGS_COMPILER_VERSION "12")', cmake_lines)
         self.assertIn('set(CONAN_SETTINGS_COMPILER_RUNTIME "MD")', cmake_lines)
         self.assertIn('set(CONAN_SETTINGS_OS "Windows")', cmake_lines)
+
+    def cmake_find_package_multi_definitions_test(self):
+        """ CMAKE_PREFIX_PATH and CMAKE_MODULE_PATH must be present in cmake_find_package_multi definitions
+        """
+        settings_mock = namedtuple("Settings", "build_type, os_build, constraint, get_safe")
+        conanfile = ConanFile(TestBufferConanOutput(), None)
+        conanfile.initialize(settings_mock("Release", None, lambda x: x, lambda x: "Release"),
+                             EnvValues())
+        install_folder = "/c/foo/testing"
+        setattr(conanfile, "install_folder", install_folder)
+        conanfile.generators = ["cmake_find_package_multi"]
+        definitions_builder = CMakeDefinitionsBuilder(conanfile)
+        definitions = definitions_builder.get_definitions()
+        self.assertEqual(install_folder, definitions["CMAKE_PREFIX_PATH"])
+        self.assertEqual(install_folder, definitions["CMAKE_MODULE_PATH"])