def variables_cmake_multi_user_vars_test(self): settings_mock = _MockSettings(build_type="Release") conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(settings_mock, EnvValues()) conanfile.deps_user_info["LIB1"].myvar = "myvalue" conanfile.deps_user_info["LIB1"].myvar2 = "myvalue2" conanfile.deps_user_info["lib2"].MYVAR2 = "myvalue4" generator = CMakeMultiGenerator(conanfile) content = generator.content["conanbuildinfo_multi.cmake"] cmake_lines = content.splitlines() self.assertIn('set(CONAN_USER_LIB1_myvar "myvalue")', cmake_lines) self.assertIn('set(CONAN_USER_LIB1_myvar2 "myvalue2")', cmake_lines) self.assertIn('set(CONAN_USER_LIB2_MYVAR2 "myvalue4")', cmake_lines)
def test_cpp_info_name_cmakedeps_components(using_properties): conanfile = ConanFile(Mock(), None) conanfile._conan_node = Mock() conanfile._conan_node.context = "host" conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize( Settings({ "os": ["Windows"], "compiler": ["gcc"], "build_type": ["Release", "Debug"], "arch": ["x86", "x64"] }), EnvValues()) conanfile.settings.build_type = "Debug" conanfile.settings.arch = "x64" cpp_info = CppInfo("mypkg", "dummy_root_folder1") if using_properties: cpp_info.set_property("cmake_target_name", "GlobakPkgName1") cpp_info.components["mycomp"].set_property("cmake_target_name", "MySuperPkg1") cpp_info.set_property("cmake_file_name", "ComplexFileName1") else: cpp_info.names["cmake_find_package_multi"] = "GlobakPkgName1" cpp_info.components["mycomp"].names[ "cmake_find_package_multi"] = "MySuperPkg1" cpp_info.filenames["cmake_find_package_multi"] = "ComplexFileName1" conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.ref = ConanFileReference.loads( "OriginalDepName/1.0") conanfile_dep._conan_node.context = "host" conanfile_dep.package_folder = "/path/to/folder_dep" with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req = Requirement(ConanFileReference.loads("OriginalDepName/1.0")) mock_deps.return_value = ConanFileDependencies( {req: ConanFileInterface(conanfile_dep)}) cmakedeps = CMakeDeps(conanfile) files = cmakedeps.content assert "TARGET GlobakPkgName1::MySuperPkg1" in files[ "ComplexFileName1-Target-debug.cmake"] assert 'set(OriginalDepName_INCLUDE_DIRS_DEBUG ' \ '"${OriginalDepName_PACKAGE_FOLDER_DEBUG}/include")' \ in files["ComplexFileName1-debug-x64-data.cmake"] assert 'set(OriginalDepName_MySuperPkg1_INCLUDE_DIRS_DEBUG ' \ '"${OriginalDepName_PACKAGE_FOLDER_DEBUG}/include")' \ in files["ComplexFileName1-debug-x64-data.cmake"]
def test_b2_empty_settings(self): conanfile = ConanFile(Mock(), None) conanfile.initialize(Settings({}), EnvValues()) generator = B2Generator(conanfile) content = { 'conanbuildinfo.jam': _main_buildinfo_empty, 'conanbuildinfo-d41d8cd98f00b204e9800998ecf8427e.jam': _variation_empty, } for ck, cv in generator.content.items(): self.assertEqual(cv, content[ck])
def test_cmake_definitions_apple(self): #https://github.com/conan-io/conan/issues/7875 settings_mock = _MockSettings(build_type="Release") settings_mock.os = "iOS" settings_mock.os_build = "Macos" conanfile = ConanFile(TestBufferConanOutput(), None) install_folder = "/c/foo/testing" setattr(conanfile, "install_folder", install_folder) conanfile.initialize(settings_mock, EnvValues()) definitions_builder = CMakeDefinitionsBuilder(conanfile) definitions = definitions_builder.get_definitions("3.13") self.assertEqual("Darwin", definitions["CMAKE_SYSTEM_NAME"]) definitions = definitions_builder.get_definitions("3.14") self.assertEqual("iOS", definitions["CMAKE_SYSTEM_NAME"])
def __init__(self, output, runner, settings, conanfile_directory, user=None, channel=None): # User defined generators self.generators = self.generators if hasattr( self, "generators") else ["txt"] if isinstance(self.generators, str): self.generators = [self.generators] # User defined options self.options = create_options(self) self.requires = create_requirements(self) self.settings = create_settings(self, settings) self.exports = create_exports(self) self.exports_sources = create_exports_sources(self) # needed variables to pack the project self.cpp_info = None # Will be initialized at processing time self.deps_cpp_info = DepsCppInfo() # environment variables declared in the package_info self.env_info = None # Will be initialized at processing time self.deps_env_info = DepsEnvInfo() # user declared variables self.user_info = None self.deps_user_info = UserDepsInfo( ) # Keys are the package names, and the values a dict with the vars self.copy = None # initialized at runtime # an output stream (writeln, info, warn error) self.output = output # something that can run commands, as os.sytem self._runner = runner self._conanfile_directory = conanfile_directory self.package_folder = None # Assigned at runtime self._scope = None # user specified env variables self._env_values = EnvValues() # Updated at runtime, user specified -e self._user = user self._channel = channel # Are we in local cache? Suggest a better name self.in_local_cache = False
def variables_cmake_multi_user_vars_test(self): settings_mock = namedtuple("Settings", "build_type, os, os_build, constraint") conanfile = ConanFile(None, None) conanfile.initialize(settings_mock("Release", None, None, lambda x, raise_undefined_field: x,), EnvValues()) conanfile.deps_user_info["LIB1"].myvar = "myvalue" conanfile.deps_user_info["LIB1"].myvar2 = "myvalue2" conanfile.deps_user_info["lib2"].MYVAR2 = "myvalue4" generator = CMakeMultiGenerator(conanfile) content = generator.content["conanbuildinfo_multi.cmake"] cmake_lines = content.splitlines() self.assertIn('set(CONAN_USER_LIB1_myvar "myvalue")', cmake_lines) self.assertIn('set(CONAN_USER_LIB1_myvar2 "myvalue2")', cmake_lines) self.assertIn('set(CONAN_USER_LIB2_MYVAR2 "myvalue4")', cmake_lines)
def variables_cmake_multi_user_vars_escape_test(self): settings_mock = namedtuple("Settings", "build_type, os, os_build, constraint") conanfile = ConanFile(None, None) conanfile.initialize(settings_mock("Release", None, None, lambda x, raise_undefined_field: x,), EnvValues()) conanfile.deps_user_info["FOO"].myvar = 'my"value"' conanfile.deps_user_info["FOO"].myvar2 = 'my${value}' conanfile.deps_user_info["FOO"].myvar3 = 'my\\value' generator = CMakeMultiGenerator(conanfile) content = generator.content["conanbuildinfo_multi.cmake"] cmake_lines = content.splitlines() self.assertIn(r'set(CONAN_USER_FOO_myvar "my\"value\"")', cmake_lines) self.assertIn(r'set(CONAN_USER_FOO_myvar2 "my\${value}")', cmake_lines) self.assertIn(r'set(CONAN_USER_FOO_myvar3 "my\\value")', cmake_lines)
def __init__(self): # Input sections, as defined by user profile files and command line self.settings = OrderedDict() self.package_settings = defaultdict(OrderedDict) self.env_values = EnvValues() self.options = OptionsValues() self.build_requires = OrderedDict() # ref pattern: list of ref self.conf = ConfDefinition() # Cached processed values self.processed_settings = None # Settings with values, and smart completion self._user_options = None self._package_settings_values = None self.dev_reference = None # Reference of the package being develop
def setUpClass(cls): env = EnvValues() env.add("USER_FLAG", "user_value") env.add("CL", ["cl1", "cl2"]) env.add("PATH", [ "another_path", ]) env.add("PATH2", ["p1", "p2"]) conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), env) cls.generator = VirtualEnvGenerator(conanfile) cls.generator.output_path = "not-used" cls.result = cls.generator.content
def setUp(self): self.conanfile = ConanFile(TestBufferConanOutput(), None) settings = _MockSettings() settings.build_type = "Debug" self.conanfile.initialize(settings, EnvValues()) ref = ConanFileReference.loads("my_pkg/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder1") cpp_info.name = "MyPkG" self.conanfile.deps_cpp_info.update(cpp_info, ref.name) ref = ConanFileReference.loads("my_pkg2/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder2") cpp_info.name = "MyPkG2" cpp_info.public_deps = ["my_pkg"] self.conanfile.deps_cpp_info.update(cpp_info, ref.name)
def cmake_find_package_multi_version_test(self): # https://github.com/conan-io/conan/issues/6908 settings_mock = _MockSettings(build_type="Debug") conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(settings_mock, EnvValues()) ref = ConanFileReference.loads("my_pkg/0.1@user/stable") cpp_info = CppInfo(ref.name, "") cpp_info.version = ref.version cpp_info.debug.libs = ["mylib"] conanfile.deps_cpp_info.add(ref.name, cpp_info) generator = CMakeFindPackageMultiGenerator(conanfile) content = generator.content config_version = content["my_pkgConfigVersion.cmake"] self.assertIn('set(PACKAGE_VERSION "0.1")', config_version)
def test_update_priority(self): env = EnvValues() env.add("VAR", "VALUE1") env2 = EnvValues() env2.add("VAR", "VALUE2") env.update(env2) # Already set by env, discarded new value self.assertEqual(env.env_dicts(None), ({'VAR': 'VALUE1'}, {})) # Updates with lists and values env = EnvValues() env.add("VAR", ["1"]) env.add("VAR", "2") self.assertEqual(env.env_dicts(None), ({}, {'VAR': ['1', '2']})) # If the first value is not a list won't append env = EnvValues() env.add("VAR", "1") env.add("VAR", ["2"]) self.assertEqual(env.env_dicts(None), ({'VAR': '1'}, {}))
def test_frameworks(self): conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) framework_path = os.getcwd( ) # must exist, otherwise filtered by framework_paths cpp_info = CppInfo("MyPkg", "/rootpath") cpp_info.frameworks = ["HelloFramework"] cpp_info.frameworkdirs = [framework_path] conanfile.deps_cpp_info.add("MyPkg", DepCppInfo(cpp_info)) generator = QmakeGenerator(conanfile) content = generator.content qmake_lines = content.splitlines() self.assertIn('CONAN_FRAMEWORKS += -framework HelloFramework', qmake_lines) self.assertIn('CONAN_FRAMEWORK_PATHS += -F%s' % framework_path, qmake_lines)
def validate_additional_dependencies(lib, additional_dep): conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("MyPkg/0.1@user/testing") cpp_info = CppInfo("dummy_root_folder1") cpp_info.libs = [lib] conanfile.deps_cpp_info.update(cpp_info, ref.name) generator = VisualStudioGenerator(conanfile) content = generator.content self.assertIn( "<ConanLibraries>%s;</ConanLibraries>" % additional_dep, content) self.assertIn( "<AdditionalDependencies>" "$(ConanLibraries)%(AdditionalDependencies)" "</AdditionalDependencies>", content)
def test_absolute_directory(self): conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("pkg/0.1") cpp_info = CppInfo(ref.name, "C:/my/root/path") cpp_info.includedirs = ["D:/my/path/to/something"] cpp_info.filter_empty = False conanfile.deps_cpp_info.add(ref.name, cpp_info) master_content = TXTGenerator(conanfile).content after_cpp_info, _, _, _ = TXTGenerator.loads(master_content, filter_empty=False) self.assertListEqual(after_cpp_info[ref.name].includedirs, ["D:/my/path/to/something"]) self.assertListEqual(after_cpp_info[ref.name].include_paths, ["D:/my/path/to/something"])
def test_abs_path_unix(self): conanfile = ConanFile(Mock(), None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("pkg/0.1") cpp_info = CppInfo(ref.name, "/rootdir") cpp_info.includedirs = ["/an/absolute/dir"] cpp_info.filter_empty = False conanfile.deps_cpp_info.add(ref.name, cpp_info) master_content = TXTGenerator(conanfile).content after_cpp_info, _, _, _ = TXTGenerator.loads(master_content, filter_empty=False) self.assertListEqual(after_cpp_info[ref.name].includedirs, ["../an/absolute/dir"]) self.assertListEqual(after_cpp_info[ref.name].include_paths, ["/rootdir/../an/absolute/dir"])
def test_is_msvc(compiler, expected): settings = Settings({ "build_type": ["Release"], "compiler": { compiler: { "version": ["2022"] } }, "os": ["Windows"], "arch": ["x86_64"] }) conanfile = ConanFile(Mock(), None) conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize(settings, EnvValues()) conanfile.settings.compiler = compiler assert is_msvc(conanfile) == expected
def create(settings, options, requires, indirect_requires, non_devs_requirements): result = ConanInfo() result.full_settings = settings result.settings = settings.copy() result.full_options = options result.options = options.copy() result.options.clear_indirect() result.full_requires = RequirementsList(requires) result.requires = RequirementsInfo(requires, non_devs_requirements) result.scope = None result.requires.add(indirect_requires) result.full_requires.extend(indirect_requires) result.recipe_hash = None result._non_devs_requirements = non_devs_requirements # Can be None result.env_values = EnvValues() return result
def create(settings, options, requires, indirect_requires): result = ConanInfo() result.full_settings = settings result.settings = settings.copy() result.full_options = options result.options = options.copy() result.options.clear_indirect() result.full_requires = RequirementsList(requires) result.requires = RequirementsInfo(requires) result.requires.add(indirect_requires) result.full_requires.extend(indirect_requires) result.recipe_hash = None result.env_values = EnvValues() result.vs_toolset_compatible() return result
def b2_test(self): settings = Settings.loads(get_default_settings_yml()) settings.os = "Linux" settings.compiler = "gcc" settings.compiler.version = "6.3" settings.arch = "x86" settings.build_type = "Release" settings.cppstd = "gnu17" conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) conanfile.settings = settings ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables") cpp_info = CppInfo(ref.name, "dummy_root_folder1") cpp_info.defines = ["MYDEFINE1"] cpp_info.cflags.append("-Flag1=23") cpp_info.version = "1.3" cpp_info.description = "My cool description" cpp_info.libs = ["MyLib1"] conanfile.deps_cpp_info.add(ref.name, cpp_info) ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables") cpp_info = CppInfo(ref.name, "dummy_root_folder2") cpp_info.libs = ["MyLib2"] cpp_info.defines = ["MYDEFINE2"] cpp_info.version = "2.3" cpp_info.exelinkflags = ["-exelinkflag"] cpp_info.sharedlinkflags = ["-sharedlinkflag"] cpp_info.cxxflags = ["-cxxflag"] cpp_info.public_deps = ["MyPkg"] cpp_info.libdirs.extend(["Path\\with\\slashes", "regular/path/to/dir"]) cpp_info.includedirs.extend( ["other\\Path\\with\\slashes", "other/regular/path/to/dir"]) cpp_info.filter_empty = False conanfile.deps_cpp_info.add(ref.name, cpp_info) generator = B2Generator(conanfile) content = { 'conanbuildinfo.jam': _main_buildinfo_full, 'conanbuildinfo-316f2f0b155dc874a672d40d98d93f95.jam': _variation_full, } for ck, cv in generator.content.items(): self.assertEqual(cv, content[ck])
def variables_setup_test(self): conanfile = ConanFile(None, None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder1") cpp_info.defines = ["MYDEFINE1"] cpp_info.cflags.append("-Flag1=23") cpp_info.version = "1.3" cpp_info.description = "My cool description" conanfile.deps_cpp_info.update(cpp_info, ref.name) ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder2") cpp_info.defines = ["MYDEFINE2"] cpp_info.version = "2.3" cpp_info.exelinkflags = ["-exelinkflag"] cpp_info.sharedlinkflags = ["-sharedlinkflag"] cpp_info.cppflags = ["-cppflag"] cpp_info.public_deps = ["MyPkg"] conanfile.deps_cpp_info.update(cpp_info, ref.name) generator = PkgConfigGenerator(conanfile) files = generator.content self.assertEquals( files["MyPkg2.pc"], """prefix=dummy_root_folder2 libdir=${prefix}/lib includedir=${prefix}/include Name: MyPkg2 Description: Conan package: MyPkg2 Version: 2.3 Libs: -L${libdir} -sharedlinkflag -exelinkflag Cflags: -I${includedir} -cppflag -DMYDEFINE2 Requires: MyPkg """) self.assertEquals( files["MyPkg.pc"], """prefix=dummy_root_folder1 libdir=${prefix}/lib includedir=${prefix}/include Name: MyPkg Description: My cool description Version: 1.3 Libs: -L${libdir} Cflags: -I${includedir} -Flag1=23 -DMYDEFINE1 """)
def valid_xml_test(self): conanfile = ConanFile(None, None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("MyPkg/0.1@user/testing") cpp_info = CppInfo("dummy_root_folder1") conanfile.deps_cpp_info.update(cpp_info, ref.name) ref = ConanFileReference.loads("My.Fancy-Pkg_2/0.1@user/testing") cpp_info = CppInfo("dummy_root_folder2") conanfile.deps_cpp_info.update(cpp_info, ref.name) generator = VisualStudioGenerator(conanfile) content = generator.content xml.etree.ElementTree.fromstring(content) self.assertIn('<PropertyGroup Label="Conan-RootDirs">', content) self.assertIn("<Conan-MyPkg-Root>dummy_root_folder1</Conan-MyPkg-Root>", content) self.assertIn("<Conan-My-Fancy-Pkg_2-Root>dummy_root_folder2</Conan-My-Fancy-Pkg_2-Root>", content)
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() c.folders.set_base_generators(".") c._conan_node = Mock() c._conan_node.dependencies = [] return c
def escaped_flags_test(self): conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables") cpp_info = CppInfo(ref.name, "dummy_root_folder1") cpp_info.includedirs.append("other_include_dir") cpp_info.cxxflags = ["-load", r"C:\foo\bar.dll"] cpp_info.cflags = ["-load", r"C:\foo\bar2.dll"] cpp_info.defines = ['MY_DEF=My string', 'MY_DEF2=My other string'] conanfile.deps_cpp_info.add(ref.name, cpp_info) generator = CMakeGenerator(conanfile) content = generator.content cmake_lines = content.splitlines() self.assertIn(r'set(CONAN_C_FLAGS_MYPKG "-load C:\\foo\\bar2.dll")', cmake_lines) self.assertIn(r'set(CONAN_CXX_FLAGS_MYPKG "-load C:\\foo\\bar.dll")', cmake_lines) self.assertIn(r'set(CONAN_DEFINES_MYPKG "-DMY_DEF=My string"', cmake_lines) self.assertIn('\t\t\t"-DMY_DEF2=My other string")', cmake_lines)
def test_names_per_generator(self): cpp_info = CppInfo("pkg_name", "root") cpp_info.name = "name" cpp_info.names["txt"] = "txt_name" cpp_info.names["cmake_find_package"] = "SpecialName" cpp_info.filenames["cmake_find_package"] = "SpecialFileName" conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(Settings({}), EnvValues()) conanfile.deps_cpp_info.add("pkg_name", DepCppInfo(cpp_info)) content = TXTGenerator(conanfile).content parsed_deps_cpp_info, _, _, _ = TXTGenerator.loads(content, filter_empty=False) parsed_cpp_info = parsed_deps_cpp_info["pkg_name"] self.assertEqual(parsed_cpp_info.get_name("txt"), "txt_name") self.assertEqual(parsed_cpp_info.get_name("cmake_find_package"), "SpecialName") self.assertEqual(parsed_cpp_info.get_filename("cmake_find_package"), "SpecialFileName") self.assertEqual(parsed_cpp_info.get_name("pkg_config"), "pkg_name")
def test_component_name_same_package(): """ When the package and the component are the same the variables declared in data and linked to the target have to be the same. https://github.com/conan-io/conan/issues/9071""" conanfile = ConanFile(Mock(), None) conanfile._conan_node = Mock() conanfile._conan_node.context = "host" conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize( Settings({ "os": ["Windows"], "compiler": ["gcc"], "build_type": ["Release"], "arch": ["x86"] }), EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.arch = "x86" cpp_info = CppInfo("mypkg", "dummy_root_folder1") # We adjust the component with the same name as the package on purpose cpp_info.components["mypkg"].includedirs = ["includedirs1"] conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info conanfile_dep._conan_node = Mock() conanfile_dep._conan_node.context = "host" conanfile_dep._conan_node.ref = ConanFileReference.loads("mypkg/1.0") conanfile_dep.folders.set_base_package("/path/to/folder_dep") with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: req = Requirement(ConanFileReference.loads("mypkg/1.0")) mock_deps.return_value = ConanFileDependencies( {req: ConanFileInterface(conanfile_dep)}) cmakedeps = CMakeDeps(conanfile) files = cmakedeps.content target_cmake = files["mypkg-Target-release.cmake"] assert "$<$<CONFIG:Release>:${mypkg_mypkg_mypkg_INCLUDE_DIRS_RELEASE}> APPEND)" \ in target_cmake data_cmake = files["mypkg-release-x86-data.cmake"] assert 'set(mypkg_mypkg_mypkg_INCLUDE_DIRS_RELEASE ' \ '"${mypkg_PACKAGE_FOLDER_RELEASE}/includedirs1")' in data_cmake
def setUp(self): settings_mock = _MockSettings(build_type="Release") self.conanfile = ConanFile(TestBufferConanOutput(), None) self.conanfile.initialize(settings_mock, EnvValues()) ref = ConanFileReference.loads("my_pkg/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder1") cpp_info.filter_empty = False # For testing purposes only cpp_info.name = ref.name cpp_info.build_modules = ["my-module.cmake"] self.conanfile.deps_cpp_info.update(cpp_info, ref.name) ref = ConanFileReference.loads("my_pkg2/0.1@lasote/stables") cpp_info = CppInfo("dummy_root_folder2") cpp_info.filter_empty = False # For testing purposes only cpp_info.name = ref.name cpp_info.build_modules = ["other-mod.cmake", "not-a-cmake-module.pc"] cpp_info.release.build_modules = ["release-mod.cmake"] self.conanfile.deps_cpp_info.update(cpp_info, ref.name)
def test_cpp_info_name_cmakedeps(using_properties): conanfile = ConanFile(Mock(), None) conanfile.settings = "os", "compiler", "build_type", "arch" conanfile.initialize( Settings({ "os": ["Windows"], "compiler": ["gcc"], "build_type": ["Release"], "arch": ["x86"] }), EnvValues()) conanfile.settings.build_type = "Release" conanfile.settings.arch = "x86" cpp_info = CppInfo("mypkg", "dummy_root_folder1") if using_properties: cpp_info.set_property("cmake_target_name", "MySuperPkg1") cpp_info.set_property("cmake_file_name", "ComplexFileName1") else: cpp_info.names["cmake_find_package_multi"] = "MySuperPkg1" cpp_info.filenames["cmake_find_package_multi"] = "ComplexFileName1" conanfile_dep = ConanFile(Mock(), None) conanfile_dep.cpp_info = cpp_info with mock.patch('conans.ConanFile.ref', new_callable=mock.PropertyMock) as mock_ref: with mock.patch('conans.ConanFile.dependencies', new_callable=mock.PropertyMock) as mock_deps: mock_ref.return_value = ConanFileReference.loads( "OriginalDepName/1.0") mock_deps.return_value = Mock() conanfile_dep.package_folder = "/path/to/folder_dep" conanfile.dependencies.transitive_host_requires = [ ConanFileInterface(conanfile_dep) ] conanfile.dependencies.host_requires = [ ConanFileInterface(conanfile_dep) ] cmakedeps = CMakeDeps(conanfile) files = cmakedeps.content assert "TARGET MySuperPkg1::MySuperPkg1" in files[ "ComplexFileName1Config.cmake"] assert 'set(MySuperPkg1_INCLUDE_DIRS_RELEASE "${MySuperPkg1_PACKAGE_FOLDER}/include")' \ in files["ComplexFileName1-release-x86-data.cmake"]
def paths_cmake_test(self): settings_mock = _MockSettings() conanfile = ConanFile(TestBufferConanOutput(), None) conanfile.initialize(settings_mock, EnvValues()) ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables") tmp_folder = temp_folder() save(os.path.join(tmp_folder, "lib", "mylib.lib"), "") save(os.path.join(tmp_folder, "include", "myheader.h"), "") cpp_info = CppInfo(ref.name, tmp_folder) cpp_info.release.libs = ["hello"] cpp_info.debug.libs = ["hello_D"] conanfile.deps_cpp_info.add(ref.name, cpp_info) generator = CMakeGenerator(conanfile) content = generator.content content = content.replace(tmp_folder.replace("\\", "/"), "root_folder") cmake_lines = content.splitlines() self.assertIn('set(CONAN_INCLUDE_DIRS_MYPKG_RELEASE "root_folder/include")', cmake_lines) self.assertIn('set(CONAN_LIB_DIRS_MYPKG_RELEASE "root_folder/lib")', cmake_lines)
def create(settings, options, prefs_direct, prefs_indirect, default_package_id_mode): result = ConanInfo() result.full_settings = settings result.settings = settings.copy() result.full_options = options result.options = options.copy() result.options.clear_indirect() result.full_requires = _PackageReferenceList(prefs_direct) result.requires = RequirementsInfo(prefs_direct, default_package_id_mode) result.requires.add(prefs_indirect, default_package_id_mode) result.full_requires.extend(prefs_indirect) result.recipe_hash = None result.env_values = EnvValues() result.vs_toolset_compatible() result.discard_build_settings() result.default_std_matching() return result