<commit_before>from conans.paths import (BUILD_INFO_GCC, BUILD_INFO_CMAKE, BUILD_INFO_QMAKE,
                          BUILD_INFO, BUILD_INFO_VISUAL_STUDIO, 
                          BUILD_INFO_XCODE, BUILD_INFO_YCM)
from conans.util.files import save
import os


class Generator(object):

    def __init__(self, deps_build_info, build_info):
        self._deps_build_info = deps_build_info
        self._build_info = build_info

    @property
    def content(self):
        raise NotImplementedError()


class DepsCppCmake(object):
    def __init__(self, deps_cpp_info):
        self.include_paths = "\n\t\t\t".join('"%s"' % p.replace("\\", "/")
                                             for p in deps_cpp_info.include_paths)
        self.lib_paths = "\n\t\t\t".join('"%s"' % p.replace("\\", "/")
                                         for p in deps_cpp_info.lib_paths)
        self.libs = " ".join(deps_cpp_info.libs)
        self.defines = "\n\t\t\t".join("-D%s" % d for d in deps_cpp_info.defines)
        self.cppflags = " ".join(deps_cpp_info.cppflags)
        self.cflags = " ".join(deps_cpp_info.cflags)
        self.sharedlinkflags = " ".join(deps_cpp_info.sharedlinkflags)
        self.exelinkflags = " ".join(deps_cpp_info.exelinkflags)
        self.bin_paths = "\n\t\t\t".join('"%s"' % p.replace("\\", "/")
                                         for p in deps_cpp_info.bin_paths)

        self.rootpath = '"%s"' % deps_cpp_info.rootpath.replace("\\", "/")


class CMakeGenerator(Generator):

    @property
    def content(self):
        sections = []

        # DEPS VARIABLES
        template_dep = ('SET(CONAN_{dep}_ROOT {deps.rootpath})\n'
                        'SET(CONAN_INCLUDE_DIRS_{dep} {deps.include_paths})\n'
                        'SET(CONAN_LIB_DIRS_{dep} {deps.lib_paths})\n'
                        'SET(CONAN_BIN_DIRS_{dep} {deps.bin_paths})\n'
                        'SET(CONAN_LIBS_{dep} {deps.libs})\n'
                        'SET(CONAN_DEFINES_{dep} {deps.defines})\n'
                        'SET(CONAN_CXX_FLAGS_{dep} "{deps.cppflags}")\n'
                        'SET(CONAN_SHARED_LINK_FLAGS_{dep} "{deps.sharedlinkflags}")\n'
                        'SET(CONAN_EXE_LINKER_FLAGS_{dep} "{deps.exelinkflags}")\n'
                        'SET(CONAN_C_FLAGS_{dep} "{deps.cflags}")\n')

        for dep_name, dep_cpp_info in self._deps_build_info.dependencies:
            deps = DepsCppCmake(dep_cpp_info)
            dep_flags = template_dep.format(dep=dep_name.upper(),
                                            deps=deps)
            sections.append(dep_flags)

        # GENERAL VARIABLES
        deps = DepsCppCmake(self._deps_build_info)

        template = ('SET(CONAN_INCLUDE_DIRS {deps.include_paths} ${{CONAN_INCLUDE_DIRS}})\n'
            'SET(CONAN_LIB_DIRS {deps.lib_paths} ${{CONAN_LIB_DIRS}})\n'
            'SET(CONAN_BIN_DIRS {deps.bin_paths} ${{CONAN_BIN_DIRS}})\n'
            'SET(CONAN_LIBS {deps.libs} ${{CONAN_LIBS}})\n'
            'SET(CONAN_DEFINES {deps.defines} ${{CONAN_DEFINES}})\n'
            'SET(CONAN_CXX_FLAGS "{deps.cppflags} ${{CONAN_CXX_FLAGS}}")\n'
            'SET(CONAN_SHARED_LINK_FLAGS "{deps.sharedlinkflags} ${{CONAN_SHARED_LINK_FLAGS}}")\n'
            'SET(CONAN_EXE_LINKER_FLAGS "{deps.exelinkflags} ${{CONAN_EXE_LINKER_FLAGS}}")\n'
            'SET(CONAN_C_FLAGS "{deps.cflags} ${{CONAN_C_FLAGS}}")\n'
            'SET(CONAN_CMAKE_MODULE_PATH {module_paths} ${{CONAN_CMAKE_MODULE_PATH}})')

        rootpaths = [DepsCppCmake(dep_cpp_info).rootpath for _, dep_cpp_info
                     in self._deps_build_info.dependencies]
        module_paths = " ".join(rootpaths)
        all_flags = template.format(deps=deps, module_paths=module_paths)
        sections.append(all_flags)

        # MACROS
        sections.append(self._aux_cmake_test_setup())

        return "\n".join(sections)

    def _aux_cmake_test_setup(self):
        return """MACRO(CONAN_BASIC_SETUP)
    CONAN_CHECK_COMPILER()
    CONAN_OUTPUT_DIRS_SETUP()
    CONAN_FLAGS_SETUP()
    # CMake can find findXXX.cmake files in the root of packages
    SET(CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_MODULE_PATH})
ENDMACRO()

MACRO(CONAN_FLAGS_SETUP)
    INCLUDE_DIRECTORIES(${CONAN_INCLUDE_DIRS})
    LINK_DIRECTORIES(${CONAN_LIB_DIRS})
    ADD_DEFINITIONS(${CONAN_DEFINES})
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CONAN_CXX_FLAGS}")
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CONAN_C_FLAGS}")
    SET(CMAKE_SHARED_LINK_FLAGS "${CMAKE_SHARED_LINK_FLAGS} ${CONAN_SHARED_LINK_FLAGS}")
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CONAN_EXE_LINKER_FLAGS}")

    IF(APPLE)
        # https://cmake.org/Wiki/CMake_RPATH_handling
        # CONAN GUIDE: All generated libraries should have the id and dependencies to other
        # dylibs without path, just the name, EX:
        # libMyLib1.dylib:
        #     libMyLib1.dylib (compatibility version 0.0.0, current version 0.0.0)
        #     libMyLib0.dylib (compatibility version 0.0.0, current version 0.0.0)
        #     /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
        #     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
        SET(CMAKE_SKIP_RPATH 1)  # AVOID RPATH FOR *.dylib, ALL LIBS BETWEEN THEM AND THE EXE
                                 # SHOULD BE ON THE LINKER RESOLVER PATH (./ IS ONE OF THEM)
    ENDIF()
    IF(CONAN_LINK_RUNTIME)
        STRING(REPLACE "/MD" ${CONAN_LINK_RUNTIME} CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
        STRING(REPLACE "/MDd" ${CONAN_LINK_RUNTIME} CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
        STRING(REPLACE "/MD" ${CONAN_LINK_RUNTIME} CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
        STRING(REPLACE "/MDd" ${CONAN_LINK_RUNTIME} CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})<commit_msg>Tested libxml2 without custom find_package<commit_after>from conans.paths import (BUILD_INFO_GCC, BUILD_INFO_CMAKE, BUILD_INFO_QMAKE,
                          BUILD_INFO, BUILD_INFO_VISUAL_STUDIO, 
                          BUILD_INFO_XCODE, BUILD_INFO_YCM)
from conans.util.files import save
import os


class Generator(object):

    def __init__(self, deps_build_info, build_info):
        self._deps_build_info = deps_build_info
        self._build_info = build_info

    @property
    def content(self):
        raise NotImplementedError()


class DepsCppCmake(object):
    def __init__(self, deps_cpp_info):
        self.include_paths = "\n\t\t\t".join('"%s"' % p.replace("\\", "/")
                                             for p in deps_cpp_info.include_paths)
        self.lib_paths = "\n\t\t\t".join('"%s"' % p.replace("\\", "/")
                                         for p in deps_cpp_info.lib_paths)
        self.libs = " ".join(deps_cpp_info.libs)
        self.defines = "\n\t\t\t".join("-D%s" % d for d in deps_cpp_info.defines)
        self.cppflags = " ".join(deps_cpp_info.cppflags)
        self.cflags = " ".join(deps_cpp_info.cflags)
        self.sharedlinkflags = " ".join(deps_cpp_info.sharedlinkflags)
        self.exelinkflags = " ".join(deps_cpp_info.exelinkflags)
        self.bin_paths = "\n\t\t\t".join('"%s"' % p.replace("\\", "/")
                                         for p in deps_cpp_info.bin_paths)

        self.rootpath = '"%s"' % deps_cpp_info.rootpath.replace("\\", "/")


class CMakeGenerator(Generator):

    @property
    def content(self):
        sections = []

        # DEPS VARIABLES
        template_dep = ('SET(CONAN_{dep}_ROOT {deps.rootpath})\n'
                        'SET(CONAN_INCLUDE_DIRS_{dep} {deps.include_paths})\n'
                        'SET(CONAN_LIB_DIRS_{dep} {deps.lib_paths})\n'
                        'SET(CONAN_BIN_DIRS_{dep} {deps.bin_paths})\n'
                        'SET(CONAN_LIBS_{dep} {deps.libs})\n'
                        'SET(CONAN_DEFINES_{dep} {deps.defines})\n'
                        'SET(CONAN_CXX_FLAGS_{dep} "{deps.cppflags}")\n'
                        'SET(CONAN_SHARED_LINK_FLAGS_{dep} "{deps.sharedlinkflags}")\n'
                        'SET(CONAN_EXE_LINKER_FLAGS_{dep} "{deps.exelinkflags}")\n'
                        'SET(CONAN_C_FLAGS_{dep} "{deps.cflags}")\n')

        for dep_name, dep_cpp_info in self._deps_build_info.dependencies:
            deps = DepsCppCmake(dep_cpp_info)
            dep_flags = template_dep.format(dep=dep_name.upper(),
                                            deps=deps)
            sections.append(dep_flags)

        # GENERAL VARIABLES
        deps = DepsCppCmake(self._deps_build_info)

        template = ('SET(CONAN_INCLUDE_DIRS {deps.include_paths} ${{CONAN_INCLUDE_DIRS}})\n'
            'SET(CONAN_LIB_DIRS {deps.lib_paths} ${{CONAN_LIB_DIRS}})\n'
            'SET(CONAN_BIN_DIRS {deps.bin_paths} ${{CONAN_BIN_DIRS}})\n'
            'SET(CONAN_LIBS {deps.libs} ${{CONAN_LIBS}})\n'
            'SET(CONAN_DEFINES {deps.defines} ${{CONAN_DEFINES}})\n'
            'SET(CONAN_CXX_FLAGS "{deps.cppflags} ${{CONAN_CXX_FLAGS}}")\n'
            'SET(CONAN_SHARED_LINK_FLAGS "{deps.sharedlinkflags} ${{CONAN_SHARED_LINK_FLAGS}}")\n'
            'SET(CONAN_EXE_LINKER_FLAGS "{deps.exelinkflags} ${{CONAN_EXE_LINKER_FLAGS}}")\n'
            'SET(CONAN_C_FLAGS "{deps.cflags} ${{CONAN_C_FLAGS}}")\n'
            'SET(CONAN_CMAKE_MODULE_PATH {module_paths} ${{CONAN_CMAKE_MODULE_PATH}})')

        rootpaths = [DepsCppCmake(dep_cpp_info).rootpath for _, dep_cpp_info
                     in self._deps_build_info.dependencies]
        module_paths = " ".join(rootpaths)
        all_flags = template.format(deps=deps, module_paths=module_paths)
        sections.append(all_flags)

        # MACROS
        sections.append(self._aux_cmake_test_setup())

        return "\n".join(sections)

    def _aux_cmake_test_setup(self):
        return """MACRO(CONAN_BASIC_SETUP)
    CONAN_CHECK_COMPILER()
    CONAN_OUTPUT_DIRS_SETUP()
    CONAN_FLAGS_SETUP()
    # CMake can find findXXX.cmake files in the root of packages
    SET(CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_MODULE_PATH})
ENDMACRO()

MACRO(CONAN_FLAGS_SETUP)
    INCLUDE_DIRECTORIES(${CONAN_INCLUDE_DIRS})
    LINK_DIRECTORIES(${CONAN_LIB_DIRS})
    ADD_DEFINITIONS(${CONAN_DEFINES})
    # For find_library
    SET(CMAKE_INCLUDE_PATH ${CONAN_INCLUDE_DIRS} ${CMAKE_INCLUDE_PATH})
    SET(CMAKE_LIBRARY_PATH ${CONAN_LIB_DIRS} ${CMAKE_LIBRARY_PATH})

    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CONAN_CXX_FLAGS}")
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CONAN_C_FLAGS}")
    SET(CMAKE_SHARED_LINK_FLAGS "${CMAKE_SHARED_LINK_FLAGS} ${CONAN_SHARED_LINK_FLAGS}")
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CONAN_EXE_LINKER_FLAGS}")

    IF(APPLE)
        # https://cmake.org/Wiki/CMake_RPATH_handling
        # CONAN GUIDE: All generated libraries should have the id and dependencies to other
        # dylibs without path, just the name, EX:
        # libMyLib1.dylib:
        #     libMyLib1.dylib (compatibility version 0.0.0, current version 0.0.0)
        #     libMyLib0.dylib (compatibility version 0.0.0, current version 0.0.0)
        #     /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
        #     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
        SET(CMAKE_SKIP_RPATH 1)  # AVOID RPATH FOR *.dylib, ALL LIBS BETWEEN THEM AND THE EXE
                                 # SHOULD BE ON THE LINKER RESOLVER PATH (./ IS ONE OF THEM)
    ENDIF()
    IF(CONAN_LINK_RUNTIME)
        STRING(REPLACE "/MD" ${CONAN_LINK_RUNTIME} CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
        STRING(REPLACE "/MDd" ${CONAN_LINK_RUNTIME} CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
        STRING(REPLACE "/MD" ${CONAN_LINK_RUNTIME} CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
        STRING(REPLACE "/MDd" ${CONAN_LINK_RUNTIME} CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
{'fraction_non_alphanumeric': 0.12415236500627878, 'fraction_numerical': 0.005776475512766848, 'mean_word_length': 2.6836262719703976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1046697', 'n_tokens_mistral': 4500, 'n_tokens_neox': 4226, 'n_words': 615}