Repository: conan-io/conan

Issue:
CMake() build helper should also use CONAN_MAKE_PROGRAM
This is a feature request. CMAKE_MAKE_PROGRAM can be set to indicate where to find the ``make`` program when a Makefile-like generator is specified.

(Note to myself: partially implemented in my fork in branch `feature/make_program_in_make`, pending tests)



Discussion:

Resolving patch:
diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py
--- a/conans/client/build/cmake.py
+++ b/conans/client/build/cmake.py
@@ -25,7 +25,7 @@ def _get_env_cmake_system_name():
 class CMake(object):
 
     def __init__(self, conanfile, generator=None, cmake_system_name=True,
-                 parallel=True, build_type=None, toolset=None):
+                 parallel=True, build_type=None, toolset=None, make_program=None):
         """
         :param settings_or_conanfile: Conanfile instance (or settings for retro compatibility)
         :param generator: Generator name to use or none to autodetect
@@ -65,6 +65,15 @@ def __init__(self, conanfile, generator=None, cmake_system_name=True,
             # Call the setter to warn and update the definitions if needed
             self.build_type = build_type
 
+        make_program = os.getenv("CONAN_MAKE_PROGRAM") or make_program
+        if make_program:
+            if not tools.which(make_program):
+                self._conanfile.output.warn("The specified make program '%s' cannot be found"
+                                            "and will be ignored" % make_program)
+            else:
+                self._conanfile.output.info("Using '%s' as CMAKE_MAKE_PROGRAM" % make_program)
+                self.definitions["CMAKE_MAKE_PROGRAM"] = make_program
+
     @property
     def build_folder(self):
         return self.build_dir
@@ -318,10 +327,11 @@ def get_dir(folder, origin):
 
     def configure(self, args=None, defs=None, source_dir=None, build_dir=None,
                   source_folder=None, build_folder=None, cache_build_folder=None):
+
+
         # TODO: Deprecate source_dir and build_dir in favor of xxx_folder
         args = args or []
         defs = defs or {}
-
         source_dir, self.build_dir = self._get_dirs(source_folder, build_folder,
                                                     source_dir, build_dir,
                                                     cache_build_folder)


Test patch:
diff --git a/conans/test/build_helpers/cmake_test.py b/conans/test/build_helpers/cmake_test.py
--- a/conans/test/build_helpers/cmake_test.py
+++ b/conans/test/build_helpers/cmake_test.py
@@ -1,5 +1,6 @@
 import os
 import shutil
+import stat
 import sys
 import unittest
 import platform
@@ -33,6 +34,33 @@ def cmake_generator_test(self):
             cmake = CMake(conan_file)
             self.assertIn('-G "My CMake Generator"', cmake.command_line)
 
+    def cmake_make_program_test(self):
+        settings = Settings.loads(default_settings_yml)
+        settings.os = "Linux"
+        settings.compiler = "gcc"
+        settings.compiler.version = "6.3"
+        settings.arch = "x86"
+        settings.build_type = "Release"
+        conan_file = ConanFileMock()
+        conan_file.settings = settings
+        conan_file.source_folder = os.path.join(self.tempdir, "my_cache_source_folder")
+        conan_file.build_folder = os.path.join(self.tempdir, "my_cache_build_folder")
+
+        # Existing make
+        make_path = os.path.join(self.tempdir, "make")
+        save(make_path, "")
+        st = os.stat(make_path)
+        os.chmod(make_path, st.st_mode | stat.S_IEXEC)
+        with tools.environment_append({"CONAN_MAKE_PROGRAM": make_path}):
+            cmake = CMake(conan_file)
+            self.assertEquals(cmake.definitions["CMAKE_MAKE_PROGRAM"], make_path)
+
+        # Not existing make
+        with tools.environment_append({"CONAN_MAKE_PROGRAM": "fake_path/make"}):
+            cmake = CMake(conan_file)
+            self.assertNotIn("CMAKE_MAKE_PROGRAM", cmake.definitions)
+            self.assertIn("The specified make program 'fake_path/make' cannot be found", conan_file.output)
+
     def folders_test(self):
         def quote_var(var):
             return "'%s'" % var if platform.system() != "Windows" else var