Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add CONAN_CMAKE_PROGRAM #4298

Merged
merged 2 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions conans/client/build/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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, msbuild_verbosity=None):
set_cmake_flags=False, msbuild_verbosity=None, cmake_program=None):
"""
:param conanfile: Conanfile instance
:param generator: Generator name to use or none to autodetect
Expand All @@ -33,14 +33,16 @@ 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 msbuild_verbosity: verbosity level for MSBuild (in case of Visual Studio generator)
:param msbuild_verbosity: verbosity level for MSBuild (in case of Visual Studio generator)
: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 @@ -187,7 +189,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 @@ -230,7 +232,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 @@ -205,6 +206,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
27 changes: 27 additions & 0 deletions conans/test/unittests/client/build/cmake_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,32 @@ def test_vcvars_applied(self, generator, compiler, version):
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, parallel=False)
cmake.build()
self.assertEqual("cmake --build %s" % CMakeTest.scape("."), conanfile.command)

cmake = CMake(conanfile, cmake_program="use_another_cmake", parallel=False)
cmake.build()
self.assertEqual("use_another_cmake --build %s" % CMakeTest.scape("."), conanfile.command)

with tools.environment_append({"CONAN_CMAKE_PROGRAM": "my_custom_cmake"}):
cmake = CMake(conanfile, parallel=False)
cmake.build()
self.assertEqual("my_custom_cmake --build %s" % CMakeTest.scape("."), 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", parallel=False)
cmake.build()
self.assertEqual("cmake_from_environment_has_priority --build %s" % CMakeTest.scape("."), conanfile.command)

def test_msbuild_verbosity(self):
settings = Settings.loads(default_settings_yml)
settings.os = "Windows"
Expand Down Expand Up @@ -1204,3 +1230,4 @@ def test_ctest_variables(self):
cmake.test(output_on_failure=True)
self.assertEquals(conanfile.captured_env["CTEST_OUTPUT_ON_FAILURE"], "1")
self.assertEquals(conanfile.captured_env["CTEST_PARALLEL_LEVEL"], "666")