def _run(self, command): compiler = self._settings.get_safe("compiler") conan_v2_error("compiler setting should be defined.", not compiler) the_os = self._settings.get_safe("os") is_clangcl = the_os == "Windows" and compiler == "clang" is_msvc = compiler == "Visual Studio" is_intel = compiler == "intel" context = tools.no_op() if (is_msvc or is_clangcl) and platform.system() == "Windows": if self.generator in [ "Ninja", "NMake Makefiles", "NMake Makefiles JOM" ]: vcvars_dict = tools.vcvars_dict(self._settings, force=True, filter_known_paths=False, output=self._conanfile.output) context = _environment_add(vcvars_dict, post=self._append_vcvars) elif is_intel: if self.generator in [ "Ninja", "NMake Makefiles", "NMake Makefiles JOM", "Unix Makefiles" ]: intel_compilervars_dict = tools.intel_compilervars_dict( self._conanfile, force=True) context = _environment_add(intel_compilervars_dict, post=self._append_vcvars) with context: self._conanfile.run(command)
def test_cmake_multi_find(self): if platform.system() not in ["Windows", "Linux"]: return client = TestClient() conanfile = """from conans import ConanFile, CMake class HelloConan(ConanFile): name = "Hello" version = "0.1" settings = "build_type" exports = '*' def package(self): self.copy(pattern="*", src="%s" % self.settings.build_type) """ client.save({"conanfile.py": conanfile, "Debug/FindHello.cmake": 'message(STATUS "FIND HELLO DEBUG!")', "Release/FindHello.cmake": 'message(STATUS "FIND HELLO RELEASE!")', "RelWithDebInfo/FindHello.cmake": 'message(STATUS "FIND HELLO RELWITHDEBINFO!")', "MinSizeRel/FindHello.cmake": 'message(STATUS "FIND HELLO MINSIZEREL!")' }) client.run("export . lasote/testing") cmake = """set(CMAKE_CXX_COMPILER_WORKS 1) project(MyHello CXX) cmake_minimum_required(VERSION 2.8) include(conanbuildinfo_multi.cmake) conan_basic_setup() find_package(Hello) """ conanfile = """from conans import ConanFile, CMake class HelloConan(ConanFile): requires = "Hello/0.1@lasote/testing" settings = "build_type" generators = "cmake_multi" """ client.save({"conanfile.py": conanfile, "CMakeLists.txt": cmake}, clean_first=True) client.run("install . --build=missing ") client.run("install . -s build_type=Debug --build=missing ") client.run("install . -s build_type=RelWithDebInfo --build=missing ") client.run("install . -s build_type=MinSizeRel --build=missing ") # in Linux it can remove /usr/bin from the path invalidating "cmake" and everything with remove_from_path("sh") if platform.system() == "Windows" else no_op(): generator = "MinGW Makefiles" if platform.system() == "Windows" else "Unix Makefiles" client.run_command('cmake . -G "%s" -DCMAKE_BUILD_TYPE=Debug' % generator) self.assertIn("FIND HELLO DEBUG!", client.out) self.assertNotIn("FIND HELLO RELEASE!", client.out) client.run_command('cmake . -G "%s" -DCMAKE_BUILD_TYPE=Release' % generator) self.assertIn("FIND HELLO RELEASE!", client.out) self.assertNotIn("FIND HELLO DEBUG!", client.out) client.run_command('cmake . -G "%s" -DCMAKE_BUILD_TYPE=RelWithDebInfo' % generator) self.assertIn("FIND HELLO RELWITHDEBINFO!", client.out) client.run_command('cmake . -G "%s" -DCMAKE_BUILD_TYPE=MinSizeRel' % generator) self.assertIn("FIND HELLO MINSIZEREL!", client.out)
def _run(self, command): with tools.vcvars(self._settings, output=self._conanfile.output ) if self._vcvars_needed else tools.no_op(): env_build = AutoToolsBuildEnvironment(self._conanfile) with tools.environment_append(env_build.vars): self._conanfile.run(command)