Beispiel #1
0
 def variables_setup_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo("")
     cpp_info.defines = ["MYDEFINE1"]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
     cpp_info = CppInfo("")
     cpp_info.defines = ["MYDEFINE2"]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     generator = SConsGenerator(conanfile)
     content = generator.content
     scons_lines = content.splitlines()
     self.assertIn("        \"CPPDEFINES\"  : [\'MYDEFINE2\', \'MYDEFINE1\'],", scons_lines)
     self.assertIn("        \"CPPDEFINES\"  : [\'MYDEFINE1\'],", scons_lines)
     self.assertIn("        \"CPPDEFINES\"  : [\'MYDEFINE2\'],", scons_lines)
Beispiel #2
0
 def escaped_flags_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder1")
     cpp_info.includedirs.append("other_include_dir")
     cpp_info.cppflags = ["-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.update(cpp_info, ref.name)
     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)
Beispiel #3
0
 def variables_setup_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder1")
     cpp_info.defines = ["MYDEFINE1"]
     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"]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn("set(CONAN_DEFINES_MYPKG -DMYDEFINE1)", cmake_lines)
     self.assertIn("set(CONAN_DEFINES_MYPKG2 -DMYDEFINE2)", cmake_lines)
     self.assertIn("set(CONAN_COMPILE_DEFINITIONS_MYPKG MYDEFINE1)", cmake_lines)
     self.assertIn("set(CONAN_COMPILE_DEFINITIONS_MYPKG2 MYDEFINE2)", cmake_lines)
Beispiel #4
0
 def cppinfo_inexistent_component_dep_test(self):
     info = CppInfo(None)
     info.components["LIB1"].requires = ["LIB2"]
     with six.assertRaisesRegex(self, ConanException, "Component 'LIB1' "
                                                      "declares a missing dependency"):
         DepCppInfo(info).libs
     info.components["LIB1"].requires = ["::LIB2"]
     with six.assertRaisesRegex(self, ConanException, "Leading character '::' not allowed in "
                                                      "LIB1 requires"):
         DepCppInfo(info).libs
Beispiel #5
0
 def escaped_flags_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder1")
     cpp_info.includedirs.append("other_include_dir")
     cpp_info.cppflags = ["-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.update(cpp_info, ref.name)
     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)
Beispiel #6
0
    def test_types(self):
        deps_cpp_info = DepsCppInfo()
        cpp_info = CppInfo("pkg", "rootpath")
        cpp_info.version = "version"
        cpp_info.libs = ["lib1", "lib2"]
        cpp_info.includedirs = ["include1"]
        deps_cpp_info.add("pkg", DepCppInfo(cpp_info))

        info_for_package = deps_cpp_info["pkg"]

        # Documented as list for 'self.cpp_info' object
        self.assertIsInstance(info_for_package.includedirs, list)
        self.assertIsInstance(info_for_package.libdirs, list)
        self.assertIsInstance(info_for_package.resdirs, list)
        self.assertIsInstance(info_for_package.bindirs, list)
        self.assertIsInstance(info_for_package.builddirs, list)
        self.assertIsInstance(info_for_package.libs, list)
        self.assertIsInstance(info_for_package.defines, list)
        self.assertIsInstance(info_for_package.cflags, list)
        self.assertIsInstance(info_for_package.cppflags, list)
        self.assertIsInstance(info_for_package.cxxflags, list)
        self.assertIsInstance(info_for_package.sharedlinkflags, list)
        self.assertIsInstance(info_for_package.exelinkflags, list)
        self.assertIsInstance(info_for_package.frameworks, list)
        self.assertIsInstance(info_for_package.frameworkdirs, list)
        self.assertIsInstance(info_for_package.rootpath, six.string_types)
        self.assertIsInstance(info_for_package.name, six.string_types)
        self.assertIsInstance(info_for_package.system_libs, list)
        self.assertIsInstance(info_for_package.build_modules, list)
        self.assertIsInstance(info_for_package.components, dict)

        # Documented as list for `deps_cpp_info["pkg"]`
        self.assertIsInstance(info_for_package.include_paths, list)
        self.assertIsInstance(info_for_package.lib_paths, list)
        self.assertIsInstance(info_for_package.bin_paths, list)
        self.assertIsInstance(info_for_package.build_paths, list)
        self.assertIsInstance(info_for_package.res_paths, list)
        self.assertIsInstance(info_for_package.framework_paths, list)
        self.assertIsInstance(info_for_package.build_modules_paths, list)
        self.assertIsInstance(info_for_package.get_name("generator"),
                              six.string_types)
        self.assertIsInstance(info_for_package.version, six.string_types)
        self.assertIsInstance(info_for_package.components, dict)
Beispiel #7
0
 def paths_cmake_multi_user_vars_test(self):
     settings_mock = _MockSettings(build_type="Release")
     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(tmp_folder)
     cpp_info.name = ref.name
     cpp_info.release.libs = ["hello"]
     cpp_info.debug.libs = ["hello_D"]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     generator = CMakeMultiGenerator(conanfile)
     release = generator.content["conanbuildinfo_release.cmake"]
     release = release.replace(tmp_folder.replace("\\", "/"), "root_folder")
     cmake_lines = release.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)
Beispiel #8
0
    def valid_xml_test(self):
        conanfile = ConanFile(None, None, Settings({}), None)
        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)
Beispiel #9
0
    def test_valid_xml(self):
        conanfile = ConanFile(Mock(), None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("MyPkg/0.1@user/testing")
        cpp_info = CppInfo(ref.name, "dummy_root_folder1")
        conanfile.deps_cpp_info.add(ref.name, cpp_info)
        ref = ConanFileReference.loads("My.Fancy-Pkg_2/0.1@user/testing")
        cpp_info = CppInfo(ref.name, "dummy_root_folder2")
        conanfile.deps_cpp_info.add(ref.name, cpp_info)
        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)
Beispiel #10
0
 def test_escaped_flags(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)
Beispiel #11
0
    def _get_conanfile(self, settings):
        conan_file = ConanFileMock()
        conan_file.settings = settings
        conan_file.source_folder = "my_cache_source_folder"
        conan_file.build_folder = "my_cache_build_folder"
        conan_file.deps_env_info = DepsEnvInfo()
        conan_file.deps_user_info = DepsUserInfo()
        conan_file.deps_cpp_info = DepsCppInfo()
        cpp_info = CppInfo("/root")
        cpp_info.include_paths.append("path/to/include1")
        cpp_info.lib_paths.append("path/to/lib1")
        cpp_info.libs.append("mylib")
        cpp_info.bindirs = "path/to/bin1"
        cpp_info.cflags.append("c_flag1")
        cpp_info.cppflags.append("cxx_flag1")
        cpp_info.defines.append("mydefine1")

        conan_file.deps_cpp_info.update(cpp_info, "zlib")
        conan_file.env_info = EnvInfo()
        return conan_file
Beispiel #12
0
    def _get_graph(self, reference, current_path, remote, options, settings,
                   filename, update, check_updates, manifest_manager, scopes):

        loader = self._loader(current_path, settings, options, scopes)
        # Not check for updates for info command, it'll be checked when dep graph is built

        remote_proxy = ConanProxy(self._client_cache,
                                  self._user_io,
                                  self._remote_manager,
                                  remote,
                                  update=update,
                                  check_updates=check_updates,
                                  manifest_manager=manifest_manager)

        if isinstance(reference, ConanFileReference):
            project_reference = None
            conanfile = loader.load_virtual(reference, current_path)
            is_txt = True
        else:
            conanfile_path = reference
            project_reference = "PROJECT"
            output = ScopedOutput(project_reference, self._user_io.out)
            try:
                if filename and filename.endswith(".txt"):
                    raise NotFoundException("")
                conan_file_path = os.path.join(conanfile_path, filename
                                               or CONANFILE)
                conanfile = loader.load_conan(conan_file_path,
                                              output,
                                              consumer=True)
                is_txt = False
                if conanfile.name is not None and conanfile.version is not None:
                    project_reference = "%s/%s@" % (conanfile.name,
                                                    conanfile.version)
                    project_reference += "PROJECT"
            except NotFoundException:  # Load requirements.txt
                conan_path = os.path.join(conanfile_path, filename
                                          or CONANFILE_TXT)
                conanfile = loader.load_conan_txt(conan_path, output)
                is_txt = True
        # build deps graph and install it
        builder = DepsBuilder(remote_proxy, self._user_io.out, loader)
        deps_graph = builder.load(None, conanfile)
        # These lines are so the conaninfo stores the correct complete info
        if is_txt:
            conanfile.info.settings = loader._settings.values
        conanfile.info.full_settings = loader._settings.values
        conanfile.info.scope = self._current_scopes
        conanfile.cpp_info = CppInfo(current_path)
        conanfile.env_info = EnvInfo(current_path)
        registry = RemoteRegistry(self._client_cache.registry,
                                  self._user_io.out)
        return (builder, deps_graph, project_reference, registry, conanfile,
                remote_proxy, loader)
Beispiel #13
0
 def test_components_set(self):
     cpp_info = CppInfo("", "root_folder")
     cpp_info.components["liba"].name = "LIBA"
     cpp_info.components["libb"].includedirs.append("includewhat")
     cpp_info.components["libc"].libs.append("thelibc")
     self.assertListEqual(list(cpp_info.components.keys()),
                          ["liba", "libb", "libc"])
     self.assertEqual(cpp_info.components["liba"].get_name("any"), "LIBA")
     self.assertListEqual(cpp_info.components["libb"].includedirs,
                          ["include", "includewhat"])
     self.assertListEqual(cpp_info.components["libc"].libs, ["thelibc"])
Beispiel #14
0
 def multi_flag_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder1")
     cpp_info.includedirs.append("other_include_dir")
     cpp_info.cppflags = ["-DGTEST_USE_OWN_TR1_TUPLE=1", "-DGTEST_LINKED_AS_SHARED_LIBRARY=1"]
     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.cflags = ["-DSOMEFLAG=1"]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_C_FLAGS_MYPKG2 "-DSOMEFLAG=1")', cmake_lines)
     self.assertIn('set(CONAN_CXX_FLAGS_MYPKG "-DGTEST_USE_OWN_TR1_TUPLE=1'
                   ' -DGTEST_LINKED_AS_SHARED_LIBRARY=1")', cmake_lines)
     self.assertIn('set(CONAN_C_FLAGS "-DSOMEFLAG=1 ${CONAN_C_FLAGS}")', cmake_lines)
     self.assertIn('set(CONAN_CXX_FLAGS "-DGTEST_USE_OWN_TR1_TUPLE=1'
                   ' -DGTEST_LINKED_AS_SHARED_LIBRARY=1 ${CONAN_CXX_FLAGS}")', cmake_lines)
Beispiel #15
0
 def cpp_info_build_modules_test(self):
     folder = temp_folder()
     info = CppInfo(folder)
     info.build_modules.append("my_module.cmake")
     info.debug.build_modules = ["mod-release.cmake"]
     deps_cpp_info = DepsCppInfo()
     deps_cpp_info.update(info, "myname")
     self.assertListEqual([os.path.join(folder, "my_module.cmake")],
                          deps_cpp_info["myname"].build_modules_paths)
     self.assertListEqual([os.path.join(folder, "mod-release.cmake")],
                          deps_cpp_info["myname"].debug.build_modules_paths)
Beispiel #16
0
    def _get_conanfile(self, settings):
        conan_file = ConanFileMock()
        conan_file.settings = settings
        conan_file.source_folder = "my_cache_source_folder"
        conan_file.build_folder = "my_cache_build_folder"
        conan_file.deps_env_info = DepsEnvInfo()
        conan_file.deps_user_info = DepsUserInfo()
        conan_file.deps_cpp_info = DepsCppInfo()
        cpp_info = CppInfo("/root")
        cpp_info.include_paths.append("path/to/include1")
        cpp_info.lib_paths.append("path/to/lib1")
        cpp_info.libs.append("mylib")
        cpp_info.bindirs = "path/to/bin1"
        cpp_info.cflags.append("c_flag1")
        cpp_info.cppflags.append("cxx_flag1")
        cpp_info.defines.append("mydefine1")

        conan_file.deps_cpp_info.update(cpp_info, "zlib")
        conan_file.env_info = EnvInfo()
        return conan_file
Beispiel #17
0
def test_cmake_deps_links_flags():
    # https://github.com/conan-io/conan/issues/8703
    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")
    # https://github.com/conan-io/conan/issues/8811 regression, fix with explicit - instead of /
    cpp_info.sharedlinkflags = ["-NODEFAULTLIB", "-OTHERFLAG"]
    cpp_info.exelinkflags = ["-OPT:NOICF"]
    cpp_info.objects = ["myobject.o"]
    conanfile_dep = ConanFile(Mock(), None)
    conanfile_dep.cpp_info = cpp_info
    conanfile_dep._conan_node = Mock()
    conanfile_dep._conan_node.ref = ConanFileReference.loads("mypkg/1.0")
    conanfile_dep._conan_node.context = "host"
    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("OriginalDepName/1.0"))
        mock_deps.return_value = ConanFileDependencies(
            {req: ConanFileInterface(conanfile_dep)})

        cmakedeps = CMakeDeps(conanfile)
        files = cmakedeps.content
        data_cmake = files["mypkg-release-x86-data.cmake"]
        assert 'set(mypkg_SHARED_LINK_FLAGS_RELEASE "-NODEFAULTLIB;-OTHERFLAG")' in data_cmake
        assert 'set(mypkg_EXE_LINK_FLAGS_RELEASE "-OPT:NOICF")' in data_cmake
        assert 'set(mypkg_OBJECTS_RELEASE "${mypkg_PACKAGE_FOLDER_RELEASE}/myobject.o")' \
               in data_cmake
Beispiel #18
0
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"]
Beispiel #19
0
    def multi_config_test(self):
        tmp_folder = temp_folder()
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        cpp_info = CppInfo(tmp_folder)
        cpp_info.defines = ["_WIN32_WINNT=x0501"]
        cpp_info.debug.defines = ["_DEBUG", "DEBUG"]
        cpp_info.release.defines = ["NDEBUG"]
        cpp_info.custom.defines = ["CUSTOM_BUILD"]
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        generator = VisualStudioGenerator(conanfile)

        content = generator.content

        defines_common = "<ConanPreprocessorDefinitions>" \
                         "_WIN32_WINNT=x0501;" \
                         "</ConanPreprocessorDefinitions>"
        defines_debug = "<ConanPreprocessorDefinitions>" \
                        "_DEBUG;DEBUG;" \
                        "</ConanPreprocessorDefinitions>"
        defines_release = "<ConanPreprocessorDefinitions>" \
                          "NDEBUG;" \
                          "</ConanPreprocessorDefinitions>"
        defines_custom = "<ConanPreprocessorDefinitions>" \
                         "CUSTOM_BUILD;" \
                         "</ConanPreprocessorDefinitions>"
        defines_always = "<PreprocessorDefinitions>$(ConanPreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>"

        self.assertIn(defines_common, content)
        self.assertIn(defines_debug, content)
        self.assertIn(defines_release, content)
        self.assertIn(defines_custom, content)
        self.assertIn(defines_always, content)

        condition_debug = "<ItemDefinitionGroup Condition=\"'$(Configuration)' == 'debug'\">"
        condition_release = "<ItemDefinitionGroup Condition=\"'$(Configuration)' == 'release'\">"
        condition_custom = "<ItemDefinitionGroup Condition=\"'$(Configuration)' == 'custom'\">"
        self.assertIn(condition_debug, content)
        self.assertIn(condition_release, content)
        self.assertIn(condition_custom, content)
Beispiel #20
0
    def test_apple_frameworks(self):
        settings = Settings.loads(get_default_settings_yml())
        settings.os = "Macos"
        settings.compiler = "apple-clang"
        settings.compiler.version = "9.1"
        settings.compiler.libcxx = "libc++"
        settings.arch = "x86_64"
        settings.build_type = "Debug"
        conanfile = ConanFile(Mock(), 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.frameworkdirs.extend(
            ["path/to/Frameworks1", "path/to/Frameworks2"])
        cpp_info.frameworks = ["OpenGL", "OpenCL"]
        cpp_info.filter_empty = False
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        generator = CMakeGenerator(conanfile)
        content = generator.content
        self.assertIn(
            'find_library(CONAN_FRAMEWORK_${_FRAMEWORK}_FOUND NAME ${_FRAMEWORK} PATHS'
            ' ${CONAN_FRAMEWORK_DIRS${SUFFIX}} CMAKE_FIND_ROOT_PATH_BOTH)',
            content)
        self.assertIn(
            'set(CONAN_FRAMEWORK_DIRS "dummy_root_folder1/Frameworks"\n'
            '\t\t\t"dummy_root_folder1/path/to/Frameworks1"\n'
            '\t\t\t"dummy_root_folder1/path/to/Frameworks2" '
            '${CONAN_FRAMEWORK_DIRS})', content)
        self.assertIn(
            'set(CONAN_LIBS ${CONAN_LIBS} ${CONAN_SYSTEM_LIBS} '
            '${CONAN_FRAMEWORKS_FOUND})', content)

        generator = CMakeFindPackageGenerator(conanfile)
        content = generator.content
        content = content['FindMyPkg.cmake']
        self.assertIn(
            'conan_find_apple_frameworks(MyPkg_FRAMEWORKS_FOUND "${MyPkg_FRAMEWORKS}"'
            ' "${MyPkg_FRAMEWORK_DIRS}")', content)
def test_from_old_cppinfo_no_components():
    oldcppinfo = CppInfo("ref", "/root/")
    oldcppinfo.requires = ["my_req::my_component"]
    for n in _DIRS_VAR_NAMES + _FIELD_VAR_NAMES:
        setattr(oldcppinfo, n, ["var_{}_1".format(n), "var_{}_2".format(n)])

    oldcppinfo.build_modules = {
        "cmake_find_package": ["my_scripts.cmake", "foo.cmake"],
        "cmake_find_package_multi": ["my_scripts.cmake", "foo2.cmake"]
    }

    cppinfo = from_old_cppinfo(oldcppinfo)

    assert isinstance(cppinfo, NewCppInfo)

    for n in _DIRS_VAR_NAMES + _FIELD_VAR_NAMES:
        assert getattr(cppinfo,
                       n) == ["var_{}_1".format(n), "var_{}_2".format(n)]

    assert cppinfo.get_property("cmake_build_modules") is None
    assert cppinfo.requires == ["my_req::my_component"]
Beispiel #22
0
def test_cmake_deps_links_flags():
    # https://github.com/conan-io/conan/issues/8703
    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")
    cpp_info.sharedlinkflags = ["/NODEFAULTLIB", "/OTHERFLAG"]
    cpp_info.exelinkflags = ["/OPT:NOICF"]
    conanfile.deps_cpp_info.add("mypkg", cpp_info)

    cmakedeps = CMakeDeps(conanfile)
    files = cmakedeps.content
    data_cmake = files["mypkg-release-x86-data.cmake"]
    assert "set(mypkg_SHARED_LINK_FLAGS_RELEASE -NODEFAULTLIB;-OTHERFLAG)" in data_cmake
    assert "set(mypkg_EXE_LINK_FLAGS_RELEASE -OPT:NOICF)" in data_cmake
Beispiel #23
0
    def cmake_vars_unit_test(self):
        settings = _MockSettings("Release")
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(settings, EnvValues())
        tmp = temp_folder()
        cpp_info = CppInfo(tmp)
        cpp_info.name = "MyLib"
        custom_dir = os.path.join(tmp, "custom_build_dir")
        os.mkdir(custom_dir)
        cpp_info.builddirs.append(os.path.join(tmp, "custom_build_dir"))
        conanfile.deps_cpp_info.update(cpp_info, "MyLib")

        generator = CMakePathsGenerator(conanfile)
        path = tmp.replace('\\', '/')
        custom_dir = custom_dir.replace('\\', '/')
        cmake_lines = generator.content.replace('\\', '/').replace("\n\t\t\t", " ").splitlines()
        self.assertEqual('set(CONAN_MYLIB_ROOT "%s")' % path, cmake_lines[0])
        self.assertEqual('set(CMAKE_MODULE_PATH "%s/" "%s" ${CMAKE_MODULE_PATH} '
                         '${CMAKE_CURRENT_LIST_DIR})' % (path, custom_dir), cmake_lines[1])
        self.assertEqual('set(CMAKE_PREFIX_PATH "%s/" "%s" ${CMAKE_PREFIX_PATH} '
                         '${CMAKE_CURRENT_LIST_DIR})' % (path, custom_dir), cmake_lines[2])
Beispiel #24
0
 def test_cpp_info_build_modules(self):
     folder = temp_folder()
     info = CppInfo("myname", folder)
     info.build_modules.append("my_module.cmake")
     info.debug.build_modules = ["mod-release.cmake"]
     deps_cpp_info = DepsCppInfo()
     deps_cpp_info.add("myname", DepCppInfo(info))
     self.assertListEqual([os.path.join(folder, "my_module.cmake")],
                          list(deps_cpp_info["myname"].build_modules_paths))
     self.assertListEqual(
         [os.path.join(folder, "mod-release.cmake")],
         list(deps_cpp_info["myname"].debug.build_modules_paths))
Beispiel #25
0
def test_from_old_cppinfo_components():
    oldcppinfo = CppInfo("ref", "/root/")
    for n in _DIRS_VAR_NAMES + _FIELD_VAR_NAMES:
        setattr(oldcppinfo.components["foo"], n,
                ["var_{}_1".format(n), "var_{}_2".format(n)])
        setattr(oldcppinfo.components["foo2"], n,
                ["var2_{}_1".format(n), "var2_{}_2".format(n)])

    # The names and filenames are not copied to the new model
    oldcppinfo.components["foo"].names["Gen"] = ["MyName"]
    oldcppinfo.filenames["Gen"] = ["Myfilename"]

    cppinfo = NewCppInfo.from_old_cppinfo(oldcppinfo)

    assert isinstance(cppinfo, NewCppInfo)

    for n in _DIRS_VAR_NAMES + _FIELD_VAR_NAMES:
        assert getattr(cppinfo.components["foo"],
                       n) == ["var_{}_1".format(n), "var_{}_2".format(n)]
        assert getattr(cppinfo.components["foo2"],
                       n) == ["var2_{}_1".format(n), "var2_{}_2".format(n)]
Beispiel #26
0
def test_from_old_cppinfo_no_components():
    oldcppinfo = CppInfo("ref", "/root/")
    for n in _DIRS_VAR_NAMES + _FIELD_VAR_NAMES:
        setattr(oldcppinfo, n, ["var_{}_1".format(n), "var_{}_2".format(n)])

    cppinfo = NewCppInfo.from_old_cppinfo(oldcppinfo)

    assert isinstance(cppinfo, NewCppInfo)

    for n in _DIRS_VAR_NAMES + _FIELD_VAR_NAMES:
        assert getattr(cppinfo,
                       n) == ["var_{}_1".format(n), "var_{}_2".format(n)]
Beispiel #27
0
 def cppinfo_inexistent_component_dep_test(self):
     info = CppInfo("", None)
     info.components["LIB1"].requires = ["LIB2"]
     with six.assertRaisesRegex(
             self, ConanException, "Component 'LIB1' required components "
             "not found in this package: 'LIB2'"):
         _ = DepCppInfo(info).libs
     info.components["LIB1"].requires = ["::LIB2"]
     with six.assertRaisesRegex(
             self, ConanException, "Leading character '::' not allowed in "
             "LIB1 requires"):
         _ = DepCppInfo(info).libs
Beispiel #28
0
    def user_profile_test(self):
        conanfile = ConanFile(None, None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("MyPkg/0.1@user/testing")
        tmp_folder = temp_folder()
        pkg1 = os.path.join(tmp_folder, "pkg1")
        cpp_info = CppInfo(pkg1)
        cpp_info.includedirs = ["include"]
        save(os.path.join(pkg1, "include/file.h"), "")
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        ref = ConanFileReference.loads("My.Fancy-Pkg_2/0.1@user/testing")
        pkg2 = os.path.join(tmp_folder, "pkg2")
        cpp_info = CppInfo(pkg2)
        cpp_info.includedirs = ["include"]
        save(os.path.join(pkg2, "include/file.h"), "")
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        generator = VisualStudioGenerator(conanfile)

        with tools.environment_append({"USERPROFILE": tmp_folder}):
            content = generator.content
            xml.etree.ElementTree.fromstring(content)
            self.assertIn("<AdditionalIncludeDirectories>$(USERPROFILE)/pkg1/include;"
                          "$(USERPROFILE)/pkg2/include;", content)

        with tools.environment_append({"USERPROFILE": tmp_folder.upper()}):
            content = generator.content
            xml.etree.ElementTree.fromstring(content)
            self.assertIn("<AdditionalIncludeDirectories>$(USERPROFILE)/pkg1/include;"
                          "$(USERPROFILE)/pkg2/include;", content)
Beispiel #29
0
    def variables_setup_test(self):
        conanfile = ConanFile(None, None, Settings({}), None)
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder1")
        cpp_info.defines = ["MYDEFINE1"]
        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"]
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        conanfile.deps_user_info["LIB1"].myvar = "myvalue"
        conanfile.deps_user_info["LIB1"].myvar2 = "myvalue2"
        conanfile.deps_user_info["lib2"].MYVAR2 = "myvalue4"
        generator = CMakeGenerator(conanfile)
        content = generator.content
        cmake_lines = content.splitlines()
        self.assertIn("set(CONAN_DEFINES_MYPKG -DMYDEFINE1)", cmake_lines)
        self.assertIn("set(CONAN_DEFINES_MYPKG2 -DMYDEFINE2)", cmake_lines)
        self.assertIn("set(CONAN_COMPILE_DEFINITIONS_MYPKG MYDEFINE1)",
                      cmake_lines)
        self.assertIn("set(CONAN_COMPILE_DEFINITIONS_MYPKG2 MYDEFINE2)",
                      cmake_lines)

        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)
Beispiel #30
0
    def test_variables_setup(self):
        conanfile = ConanFile(Mock(), None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "dummy_root_folder1")
        cpp_info.defines = ["MYDEFINE1"]
        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.defines = ["MYDEFINE2"]
        conanfile.deps_cpp_info.add(ref.name, cpp_info)
        conanfile.deps_user_info["LIB1"].myvar = "myvalue"
        conanfile.deps_user_info["LIB1"].myvar2 = "myvalue2"
        conanfile.deps_user_info["lib2"].MYVAR2 = "myvalue4"
        generator = CMakeGenerator(conanfile)
        content = generator.content
        cmake_lines = content.splitlines()
        self.assertIn('set(CONAN_DEFINES_MYPKG "-DMYDEFINE1")', cmake_lines)
        self.assertIn('set(CONAN_DEFINES_MYPKG2 "-DMYDEFINE2")', cmake_lines)
        self.assertIn('set(CONAN_COMPILE_DEFINITIONS_MYPKG "MYDEFINE1")',
                      cmake_lines)
        self.assertIn('set(CONAN_COMPILE_DEFINITIONS_MYPKG2 "MYDEFINE2")',
                      cmake_lines)

        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)
Beispiel #31
0
    def test_apple_frameworks(self):
        settings = Settings.loads(get_default_settings_yml())
        settings.compiler = "apple-clang"
        settings.os = "Macos"
        conanfile = ConanFile(Mock(), 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.filter_empty = False
        cpp_info.frameworks = ['AudioUnit', 'AudioToolbox']
        cpp_info.version = "1.3"
        cpp_info.description = "My cool description"
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        generator = PkgConfigGenerator(conanfile)
        files = generator.content

        self.assertEqual(
            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}" -Wl,-rpath,"${libdir}" -framework AudioUnit -framework AudioToolbox -F /dummy_root_folder1/Frameworks
Cflags: -I"${includedir}"
""")
Beispiel #32
0
 def test_multi_flag(self):
     conanfile = ConanFile(Mock(), 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 = [
         "-DGTEST_USE_OWN_TR1_TUPLE=1", "-DGTEST_LINKED_AS_SHARED_LIBRARY=1"
     ]
     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.cflags = ["-DSOMEFLAG=1"]
     conanfile.deps_cpp_info.add(ref.name, cpp_info)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_C_FLAGS_MYPKG2 "-DSOMEFLAG=1")', cmake_lines)
     self.assertIn(
         'set(CONAN_CXX_FLAGS_MYPKG "-DGTEST_USE_OWN_TR1_TUPLE=1'
         ' -DGTEST_LINKED_AS_SHARED_LIBRARY=1")', cmake_lines)
     self.assertIn('set(CONAN_C_FLAGS "-DSOMEFLAG=1 ${CONAN_C_FLAGS}")',
                   cmake_lines)
     self.assertIn(
         'set(CONAN_CXX_FLAGS "-DGTEST_USE_OWN_TR1_TUPLE=1'
         ' -DGTEST_LINKED_AS_SHARED_LIBRARY=1 ${CONAN_CXX_FLAGS}")',
         cmake_lines)
Beispiel #33
0
    def user_profile_test(self):
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("MyPkg/0.1@user/testing")
        tmp_folder = temp_folder()
        pkg1 = os.path.join(tmp_folder, "pkg1")
        cpp_info = CppInfo(pkg1)
        cpp_info.includedirs = ["include"]
        save(os.path.join(pkg1, "include", "file.h"), "")
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        ref = ConanFileReference.loads("My.Fancy-Pkg_2/0.1@user/testing")
        pkg2 = os.path.join(tmp_folder, "pkg2")
        cpp_info = CppInfo(pkg2)
        cpp_info.includedirs = ["include"]
        save(os.path.join(pkg2, "include", "file.h"), "")
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        generator = VisualStudioGenerator(conanfile)

        path1 = os.path.join("$(USERPROFILE)", "pkg1", "include")
        path2 = os.path.join("$(USERPROFILE)", "pkg2", "include")
        expected1 = "<ConanIncludeDirectories>%s;%s;" % (path1, path2)
        expected2 = "<AdditionalIncludeDirectories>$(ConanIncludeDirectories)%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>"

        with tools.environment_append({"USERPROFILE": tmp_folder}):
            content = generator.content
            xml.etree.ElementTree.fromstring(content)
            self.assertIn(expected1, content)
            self.assertIn(expected2, content)

        with tools.environment_append({"USERPROFILE": tmp_folder.upper()}):
            content = generator.content
            xml.etree.ElementTree.fromstring(content)
            self.assertIn(expected1, content)
            self.assertIn(expected2, content)
Beispiel #34
0
    def apple_frameworks_test(self):
        settings = Settings.loads(default_settings_yml)
        settings.compiler = "apple-clang"
        settings.os = "Macos"
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        conanfile.settings = settings
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder1")
        cpp_info.name = ref.name
        cpp_info.frameworks = ['AudioUnit', 'AudioToolbox']
        cpp_info.version = "1.3"
        cpp_info.description = "My cool description"
        conanfile.deps_cpp_info.update(cpp_info, ref.name)

        generator = PkgConfigGenerator(conanfile)
        files = generator.content

        self.assertEqual(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} -Wl,-rpath,"${libdir}" -framework AudioUnit -framework AudioToolbox
Cflags: -I${includedir}
""")
Beispiel #35
0
 def multi_flag_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder1")
     cpp_info.includedirs.append("other_include_dir")
     cpp_info.cppflags = [
         "-DGTEST_USE_OWN_TR1_TUPLE=1", "-DGTEST_LINKED_AS_SHARED_LIBRARY=1"
     ]
     conanfile.deps_cpp_info.update(cpp_info, ref)
     ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder2")
     cpp_info.cflags = ["-DSOMEFLAG=1"]
     conanfile.deps_cpp_info.update(cpp_info, ref)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn("set(CONAN_C_FLAGS_MYPKG2 -DSOMEFLAG=1)", cmake_lines)
     self.assertIn(
         "set(CONAN_CXX_FLAGS_MYPKG -DGTEST_USE_OWN_TR1_TUPLE=1"
         " -DGTEST_LINKED_AS_SHARED_LIBRARY=1)", cmake_lines)
     self.assertIn("set(CONAN_C_FLAGS -DSOMEFLAG=1 ${CONAN_C_FLAGS})",
                   cmake_lines)
     self.assertIn(
         "set(CONAN_CXX_FLAGS -DGTEST_USE_OWN_TR1_TUPLE=1"
         " -DGTEST_LINKED_AS_SHARED_LIBRARY=1 ${CONAN_CXX_FLAGS})",
         cmake_lines)
Beispiel #36
0
    def variables_setup_test(self):
        conanfile = ConanFile(None, None, Settings({}), None)
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder1")
        cpp_info.defines = ["MYDEFINE1"]
        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"]
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        conanfile.deps_user_info["LIB1"].myvar = "myvalue"
        conanfile.deps_user_info["LIB1"].myvar2 = "myvalue2"
        conanfile.deps_user_info["lib2"].MYVAR2 = "myvalue4"
        generator = CMakeGenerator(conanfile)
        content = generator.content
        cmake_lines = content.splitlines()
        self.assertIn('set(CONAN_DEFINES_MYPKG "-DMYDEFINE1")', cmake_lines)
        self.assertIn('set(CONAN_DEFINES_MYPKG2 "-DMYDEFINE2")', cmake_lines)
        self.assertIn('set(CONAN_COMPILE_DEFINITIONS_MYPKG "MYDEFINE1")', cmake_lines)
        self.assertIn('set(CONAN_COMPILE_DEFINITIONS_MYPKG2 "MYDEFINE2")', cmake_lines)

        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)
Beispiel #37
0
    def variables_setup_test(self):
        conanfile = ConanFile(None, None, Settings({}), None)

        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 = JsonGenerator(conanfile)
        json_out = generator.content

        parsed = json.loads(json_out)
        dependencies = parsed["dependencies"]
        self.assertEquals(len(dependencies), 2)
        my_pkg = dependencies[0]
        self.assertEquals(my_pkg["name"], "MyPkg")
        self.assertEquals(my_pkg["description"], "My cool description")
        self.assertEquals(my_pkg["defines"], ["MYDEFINE1"])
Beispiel #38
0
    def variables_setup_test(self):

        conanfile = ConanFile(None, None, Settings({}), None)

        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
""")
Beispiel #39
0
def extend(cpp_info, config):
    """ adds the specific config configuration to the common one
    """
    config_info = cpp_info.configs.get(config)
    if config_info:
        result = CppInfo(config_info.rootpath)
        result.includedirs = cpp_info.includedirs + config_info.includedirs
        result.libdirs = cpp_info.libdirs + config_info.libdirs
        result.bindirs = cpp_info.bindirs + config_info.bindirs
        result.resdirs = cpp_info.resdirs + config_info.resdirs
        result.builddirs = cpp_info.builddirs + config_info.builddirs
        result.libs = cpp_info.libs + config_info.libs
        result.defines = cpp_info.defines + config_info.defines
        result.cflags = cpp_info.cflags + config_info.cflags
        result.cppflags = cpp_info.cppflags + config_info.cppflags
        result.sharedlinkflags = cpp_info.sharedlinkflags + config_info.sharedlinkflags
        result.exelinkflags = cpp_info.exelinkflags + config_info.exelinkflags
        return result
    return cpp_info
Beispiel #40
0
    def variables_setup_test(self):

        conanfile = ConanFile(None, None, Settings({}), None)

        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"
        cpp_info.libs = ["MyLib1"]

        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.libs = ["MyLib2"]
        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"]
        cpp_info.lib_paths.extend(["Path\\with\\slashes", "regular/path/to/dir"])
        cpp_info.include_paths.extend(["other\\Path\\with\\slashes", "other/regular/path/to/dir"])
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        generator = BoostBuildGenerator(conanfile)

        self.assertEquals(generator.content, """lib MyLib1 :
	: # requirements
	<name>MyLib1
	: # default-build
	: # usage-requirements
	<define>MYDEFINE1
	<cflags>-Flag1=23
	;

lib MyLib2 :
	: # requirements
	<name>MyLib2
	<search>Path/with/slashes
	<search>regular/path/to/dir
	: # default-build
	: # usage-requirements
	<define>MYDEFINE2
	<include>other/Path/with/slashes
	<include>other/regular/path/to/dir
	<cxxflags>-cppflag
	<ldflags>-sharedlinkflag
	;

alias conan-deps :
	MyLib1
	MyLib2
;
""")