Skip to content

Commit

Permalink
CMAKE_MAKE_PROGRAM for mingw (#10770)
Browse files Browse the repository at this point in the history
* Set CMAKE_MAKE_PROGRAM when mingw

* simplify code

* Replace path

* In command line

* Test configure

* Fix import

* another bad import
  • Loading branch information
lasote committed Mar 14, 2022
1 parent adb4067 commit 456b5c4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
7 changes: 6 additions & 1 deletion conan/tools/cmake/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ def configure(self, variables=None, build_script_folder=None):
pkg_folder = self._conanfile.package_folder.replace("\\", "/")
arg_list.append('-DCMAKE_INSTALL_PREFIX="{}"'.format(pkg_folder))
if platform.system() == "Windows" and self._generator == "MinGW Makefiles":
# It seems this doesn't work in the toolchain file, it needs to be here in command line
# It seems these don't work in the toolchain file, they need to be here in command line
arg_list.append('-DCMAKE_SH="CMAKE_SH-NOTFOUND"')
cmake_make_program = self._conanfile.conf.get("tools.gnu:make_program", default=None)
if cmake_make_program:
cmake_make_program = cmake_make_program.replace("\\", "/")
arg_list.append('-DCMAKE_MAKE_PROGRAM="{}"'.format(cmake_make_program))

if variables:
arg_list.extend(["-D{}={}".format(k, v) for k, v in variables.items()])
arg_list.append('"{}"'.format(cmakelist_folder))
Expand Down
45 changes: 45 additions & 0 deletions conans/test/unittests/tools/cmake/test_cmake_configure_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest
from mock import mock
from mock.mock import Mock

from conan.tools.cmake import CMake
from conan.tools.files.files import save_toolchain_args
from conans import ConanFile, Settings
from conans.model.conf import Conf
from conans.model.env_info import EnvValues
from conans.test.utils.test_files import temp_folder


@pytest.fixture(scope="module")
def conanfile():
c = ConanFile(Mock(), None)
c.settings = "os", "compiler", "build_type", "arch"
c.initialize(Settings({"os": ["Windows"],
"compiler": {"gcc": {"libcxx": ["libstdc++"]}},
"build_type": ["Release"],
"arch": ["x86"]}), EnvValues())
c.settings.build_type = "Release"
c.settings.arch = "x86"
c.settings.compiler = "gcc"
c.settings.compiler.libcxx = "libstdc++"
c.settings.os = "Windows"
c.conf = Conf()
tmp_folder = temp_folder()
c.folders.set_base_generators(tmp_folder)
c.folders.generators = "."
c.folders.set_base_build(tmp_folder)
return c


def test_cmake_make_program(conanfile):
save_toolchain_args({"cmake_generator": "MinGW Makefiles"},
generators_folder=conanfile.folders.generators_folder)

def run(command):
assert '-DCMAKE_MAKE_PROGRAM="C:/mymake.exe"' in command

conanfile.run = run
conanfile.conf.define("tools.gnu:make_program", "C:\\mymake.exe")
with mock.patch("platform.system", mock.MagicMock(return_value='Windows')):
cmake = CMake(conanfile)
cmake.configure()

0 comments on commit 456b5c4

Please sign in to comment.