Skip to content

Commit

Permalink
- add CONAN_CMAKE_PROGRAM
Browse files Browse the repository at this point in the history
Signed-off-by: SSE4 <tomskside@gmail.com>
  • Loading branch information
SSE4 committed Jan 14, 2019
1 parent 6f0c477 commit 5623de4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
8 changes: 5 additions & 3 deletions conans/client/build/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CMake(object):

def __init__(self, conanfile, generator=None, cmake_system_name=True,
parallel=True, build_type=None, toolset=None, make_program=None,
set_cmake_flags=False):
set_cmake_flags=False, cmake_program=None):
"""
:param conanfile: Conanfile instance
:param generator: Generator name to use or none to autodetect
Expand All @@ -32,13 +32,15 @@ def __init__(self, conanfile, generator=None, cmake_system_name=True,
applies only to certain generators (e.g. Visual Studio)
:param set_cmake_flags: whether or not to set CMake flags like CMAKE_CXX_FLAGS, CMAKE_C_FLAGS, etc.
it's vital to set for certain projects (e.g. using CMAKE_SIZEOF_VOID_P or CMAKE_LIBRARY_ARCHITECTURE)
:param cmake_program: Path to the custom cmake executable
"""
if not isinstance(conanfile, ConanFile):
raise ConanException("First argument of CMake() has to be ConanFile. Use CMake(self)")

self._conanfile = conanfile
self._settings = conanfile.settings
self._build_type = build_type or conanfile.settings.get_safe("build_type")
self._cmake_program = os.getenv("CONAN_CMAKE_PROGRAM") or cmake_program or "cmake"

self.generator = generator or get_generator(conanfile.settings)
self.parallel = parallel
Expand Down Expand Up @@ -184,7 +186,7 @@ def configure(self, args=None, defs=None, source_dir=None, build_dir=None,
pkg_env = {"PKG_CONFIG_PATH": self._conanfile.install_folder} if set_env else {}

with tools.environment_append(pkg_env):
command = "cd %s && cmake %s" % (args_to_string([self.build_dir]), arg_list)
command = "cd %s && %s %s" % (args_to_string([self.build_dir]), self._cmake_program, arg_list)
if platform.system() == "Windows" and self.generator == "MinGW Makefiles":
with tools.remove_from_path("sh"):
self._run(command)
Expand Down Expand Up @@ -220,7 +222,7 @@ def _build(self, args=None, build_dir=None, target=None):
self.build_config,
args_to_string(args)
])
command = "cmake --build %s" % arg_list
command = "%s --build %s" % (self._cmake_program, arg_list)
self._run(command)

def install(self, args=None, build_dir=None):
Expand Down
2 changes: 2 additions & 0 deletions conans/client/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
# non_interactive = False # environment CONAN_NON_INTERACTIVE
# conan_make_program = make # environment CONAN_MAKE_PROGRAM (overrides the make program used in AutoToolsBuildEnvironment.make)
# conan_cmake_program = cmake # environment CONAN_CMAKE_PROGRAM (overrides the make program used in CMake.cmake_program)
# cmake_generator # environment CONAN_CMAKE_GENERATOR
# http://www.vtk.org/Wiki/CMake_Cross_Compiling
Expand Down Expand Up @@ -202,6 +203,7 @@ def env_vars(self):

"CONAN_BASH_PATH": self._env_c("general.bash_path", "CONAN_BASH_PATH", None),
"CONAN_MAKE_PROGRAM": self._env_c("general.conan_make_program", "CONAN_MAKE_PROGRAM", None),
"CONAN_CMAKE_PROGRAM": self._env_c("general.conan_cmake_program", "CONAN_CMAKE_PROGRAM", None),
"CONAN_TEMP_TEST_FOLDER": self._env_c("general.temp_test_folder", "CONAN_TEMP_TEST_FOLDER", "False"),
"CONAN_SKIP_VS_PROJECTS_UPGRADE": self._env_c("general.skip_vs_projects_upgrade", "CONAN_SKIP_VS_PROJECTS_UPGRADE", "False"),
"CONAN_HOOKS": self._env_c("hooks", "CONAN_HOOKS", None),
Expand Down
26 changes: 26 additions & 0 deletions conans/test/unittests/client/build/cmake_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,3 +1160,29 @@ def test_vcvars_applied(self, generator, compiler, version):
vcvars_mock.__exit__ = mock.MagicMock(return_value=None)
cmake.build()
self.assertTrue(vcvars_mock.called, "vcvars weren't called")

def test_cmake_program(self):
conanfile = ConanFileMock()
settings = Settings.loads(default_settings_yml)
settings.os = "Windows"
settings.compiler = "Visual Studio"
settings.compiler.version = "14"
conanfile.settings = settings

cmake = CMake(conanfile)
cmake.build()
self.assertEqual("cmake --build .", conanfile.command)

cmake = CMake(conanfile, cmake_program="use_another_cmake")
cmake.build()
self.assertEqual("use_another_cmake --build .", conanfile.command)

with tools.environment_append({"CONAN_CMAKE_PROGRAM": "my_custom_cmake"}):
cmake = CMake(conanfile)
cmake.build()
self.assertEqual("my_custom_cmake --build .", conanfile.command)

with tools.environment_append({"CONAN_CMAKE_PROGRAM": "cmake_from_environment_has_priority"}):
cmake = CMake(conanfile, cmake_program="but_not_cmake_from_the_ctor")
cmake.build()
self.assertEqual("cmake_from_environment_has_priority --build .", conanfile.command)

0 comments on commit 5623de4

Please sign in to comment.