# Poco Conan package
# <NAME>, Odant, 2018-20


from conans import ConanFile, CMake, tools
import os


class PocoConan(ConanFile):
    name = "poco"
    version = "1.11.0+0"
    license = "Boost Software License Version 1.0. https://pocoproject.org/license.html"
    description = "Modern, powerful open source C++ class libraries for building network- and internet-based applications that run on desktop, server, mobile and embedded systems."
    url = "https://github.com/odant/conan-poco"
    settings = {
        "os": ["Windows", "Linux"],
        "compiler": ["Visual Studio", "gcc"],
        "build_type": ["Debug", "Release"],
        "arch": ["x86_64", "x86", "mips", "armv7"]
    }
    generators = "cmake"
    exports_sources = "src/*", "CMakeLists.txt", "FindPoco.cmake"
    no_copy_source = True
    build_policy = "missing"
    #
    _openssl_version = "1.1.1k+0"
    _openssl_channel = "stable"

    def configure(self):
        # Only C++11
        if self.settings.compiler.get_safe("libcxx") == "libstdc++":
            raise Exception("This package is only compatible with libstdc++11")

    def requirements(self):
        self.requires("zlib/[>=1.2.11]@%s/stable" % self.user)
        self.requires("pcre/[>=8.43]@%s/stable" % self.user)
        self.requires("openssl/%s@%s/%s" % (self._openssl_version, self.user, self._openssl_channel))

    def source(self):
        # Disable install compiler runtime
        tools.replace_in_file(os.path.join("src", "CMakeLists.txt"), "include(InstallRequiredSystemLibraries)", "")
        tools.replace_in_file(os.path.join("src", "Foundation", "CMakeLists.txt"), "Pcre::Pcre", "PCRE::PCRE")
        
        

    def build(self):
        cmake = CMake(self)
        #
        cmake.definitions["CMAKE_INSTALL_PREFIX:STRING"] = self.package_folder.replace("\\", "/")
        if self.settings.os != "Windows":
            cmake.definitions["CMAKE_POSITION_INDEPENDENT_CODE:BOOL"] = "ON"
        if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio":
            cmake.definitions["POCO_MT"] = "OFF"
            cmake.definitions["ENABLE_MSVC_MP"] = "OFF"
        cmake.definitions["BUILD_SHARED_LIBS:BOOL"] = "OFF"
        cmake.definitions["DISABLE_CPP14:BOOL"] = "OFF"
        cmake.definitions["DISABLE_CPP11:BOOL"] = "OFF"
        cmake.definitions["POCO_UNBUNDLED:BOOL"] = "ON"
        #
        cmake.definitions["ENABLE_ACTIVERECORD:BOOL"] = "OFF"
        cmake.definitions["ENABLE_ACTIVERECORD_COMPILER:BOOL"] = "OFF"
        cmake.definitions["ENABLE_ENCODINGS:BOOL"] = "ON"
        cmake.definitions["ENABLE_ENCODINGS_COMPILER:BOOL"] = "OFF"
        cmake.definitions["ENABLE_XML:BOOL"] = "OFF"
        cmake.definitions["ENABLE_JSON:BOOL"] = "ON"
        cmake.definitions["ENABLE_JWT:BOOL"] = "ON"
        cmake.definitions["ENABLE_MONGODB:BOOL"] = "OFF"
        cmake.definitions["ENABLE_REDIS:BOOL"] = "OFF"
        cmake.definitions["ENABLE_PDF:BOOL"] = "OFF"
        cmake.definitions["ENABLE_UTIL:BOOL"] = "ON"
        cmake.definitions["ENABLE_NET:BOOL"] = "ON"
        cmake.definitions["ENABLE_NETSSL:BOOL"] = "ON"
        cmake.definitions["ENABLE_NETSSL_WIN:BOOL"] = "OFF"
        cmake.definitions["ENABLE_CRYPTO:BOOL"] = "ON"
        cmake.definitions["ENABLE_DATA:BOOL"] = "OFF"
        cmake.definitions["ENABLE_DATA_SQLITE:BOOL"] = "OFF"
        cmake.definitions["ENABLE_DATA_MYSQL:BOOL"] = "OFF"
        cmake.definitions["ENABLE_DATA_POSTGRESQL:BOOL"] = "OFF"
        cmake.definitions["ENABLE_DATA_ODBC:BOOL"] = "OFF"
        cmake.definitions["ENABLE_SEVENZIP:BOOL"] = "OFF"
        cmake.definitions["ENABLE_ZIP:BOOL"] = "OFF"
        cmake.definitions["ENABLE_APACHECONNECTOR:BOOL"] = "OFF"
        cmake.definitions["ENABLE_CPPPARSER:BOOL"] = "OFF"
        cmake.definitions["ENABLE_POCODOC:BOOL"] = "OFF"
        cmake.definitions["ENABLE_PAGECOMPILER:BOOL"] = "OFF"
        cmake.definitions["ENABLE_PAGECOMPILER_FILE2PAGE:BOOL"] = "OFF"
        cmake.definitions["ENABLE_TESTS:BOOL"] = "OFF"
        #
        cmake.configure()
        cmake.build()
        cmake.install()

    def package(self):
        # Remove autogenerated CMake scripts
        tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
        # CMake script
        self.copy("FindPoco.cmake", dst=".", src=".", keep_path=False)
        # PDB
        if self.settings.os == "Windows":
            self.copy("*.pdb", dst="bin", keep_path=False)
        
    def package_info(self):
        # Libraries
        self.cpp_info.libs = tools.collect_libs(self)
        # Defines
        if self.settings.os == "Windows":
            self.cpp_info.defines.extend(["POCO_STATIC", "POCO_NO_AUTOMATIC_LIBS"])
            if self.settings.compiler == "Visual Studio":
                self.cpp_info.libs.extend(["ws2_32", "iphlpapi"])

# Poco Conan package
# <NAME>, Odant, 2018-20


from conans import ConanFile, CMake, tools
import os


class PocoConan(ConanFile):
    name = "poco"
    version = "1.11.0+0"
    license = "Boost Software License Version 1.0. https://pocoproject.org/license.html"
    description = "Modern, powerful open source C++ class libraries for building network- and internet-based applications that run on desktop, server, mobile and embedded systems."
    url = "https://github.com/odant/conan-poco"
    settings = {
        "os": ["Windows", "Linux"],
        "compiler": ["Visual Studio", "gcc"],
        "build_type": ["Debug", "Release"],
        "arch": ["x86_64", "x86", "mips", "armv7"]
    }
    generators = "cmake"
    exports_sources = "src/*", "CMakeLists.txt", "FindPoco.cmake"
    no_copy_source = True
    build_policy = "missing"
    #
    _openssl_version = "1.1.1k+0"
    _openssl_channel = "stable"

    def configure(self):
        # Only C++11
        if self.settings.compiler.get_safe("libcxx") == "libstdc++":
            raise Exception("This package is only compatible with libstdc++11")

    def requirements(self):
        self.requires("zlib/[>=1.2.11]@%s/stable" % self.user)
        self.requires("pcre/[>=8.43]@%s/stable" % self.user)
        self.requires("openssl/%s@%s/%s" % (self._openssl_version, self.user, self._openssl_channel))

    def source(self):
        # Disable install compiler runtime
        tools.replace_in_file(os.path.join("src", "CMakeLists.txt"), "include(InstallRequiredSystemLibraries)", "")
        tools.replace_in_file(os.path.join("src", "Foundation", "CMakeLists.txt"), "Pcre::Pcre", "PCRE::PCRE")
        
        

    def build(self):
        cmake = CMake(self)
        #
        cmake.definitions["CMAKE_INSTALL_PREFIX:STRING"] = self.package_folder.replace("\\", "/")
        if self.settings.os != "Windows":
            cmake.definitions["CMAKE_POSITION_INDEPENDENT_CODE:BOOL"] = "ON"
        if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio":
            cmake.definitions["POCO_MT"] = "OFF"
            cmake.definitions["ENABLE_MSVC_MP"] = "OFF"
        cmake.definitions["BUILD_SHARED_LIBS:BOOL"] = "OFF"
        cmake.definitions["DISABLE_CPP14:BOOL"] = "OFF"
        cmake.definitions["DISABLE_CPP11:BOOL"] = "OFF"
        cmake.definitions["POCO_UNBUNDLED:BOOL"] = "ON"
        #
        cmake.definitions["ENABLE_ACTIVERECORD:BOOL"] = "OFF"
        cmake.definitions["ENABLE_ACTIVERECORD_COMPILER:BOOL"] = "OFF"
        cmake.definitions["ENABLE_ENCODINGS:BOOL"] = "ON"
        cmake.definitions["ENABLE_ENCODINGS_COMPILER:BOOL"] = "OFF"
        cmake.definitions["ENABLE_XML:BOOL"] = "OFF"
        cmake.definitions["ENABLE_JSON:BOOL"] = "ON"
        cmake.definitions["ENABLE_JWT:BOOL"] = "ON"
        cmake.definitions["ENABLE_MONGODB:BOOL"] = "OFF"
        cmake.definitions["ENABLE_REDIS:BOOL"] = "OFF"
        cmake.definitions["ENABLE_PDF:BOOL"] = "OFF"
        cmake.definitions["ENABLE_UTIL:BOOL"] = "ON"
        cmake.definitions["ENABLE_NET:BOOL"] = "ON"
        cmake.definitions["ENABLE_NETSSL:BOOL"] = "ON"
        cmake.definitions["ENABLE_NETSSL_WIN:BOOL"] = "OFF"
        cmake.definitions["ENABLE_CRYPTO:BOOL"] = "ON"
        cmake.definitions["ENABLE_DATA:BOOL"] = "OFF"
        cmake.definitions["ENABLE_DATA_SQLITE:BOOL"] = "OFF"
        cmake.definitions["ENABLE_DATA_MYSQL:BOOL"] = "OFF"
        cmake.definitions["ENABLE_DATA_POSTGRESQL:BOOL"] = "OFF"
        cmake.definitions["ENABLE_DATA_ODBC:BOOL"] = "OFF"
        cmake.definitions["ENABLE_SEVENZIP:BOOL"] = "OFF"
        cmake.definitions["ENABLE_ZIP:BOOL"] = "OFF"
        cmake.definitions["ENABLE_APACHECONNECTOR:BOOL"] = "OFF"
        cmake.definitions["ENABLE_CPPPARSER:BOOL"] = "OFF"
        cmake.definitions["ENABLE_POCODOC:BOOL"] = "OFF"
        cmake.definitions["ENABLE_PAGECOMPILER:BOOL"] = "OFF"
        cmake.definitions["ENABLE_PAGECOMPILER_FILE2PAGE:BOOL"] = "OFF"
        cmake.definitions["ENABLE_TESTS:BOOL"] = "OFF"
        #
        cmake.configure()
        cmake.build()
        cmake.install()

    def package(self):
        # Remove autogenerated CMake scripts
        tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
        # CMake script
        self.copy("FindPoco.cmake", dst=".", src=".", keep_path=False)
        # PDB
        if self.settings.os == "Windows":
            self.copy("*.pdb", dst="bin", keep_path=False)
        
    def package_info(self):
        # Libraries
        self.cpp_info.libs = tools.collect_libs(self)
        # Defines
        if self.settings.os == "Windows":
            self.cpp_info.defines.extend(["POCO_STATIC", "POCO_NO_AUTOMATIC_LIBS"])
            if self.settings.compiler == "Visual Studio":
                self.cpp_info.libs.extend(["ws2_32", "iphlpapi"])

# Poco Conan package # <NAME>, Odant, 2018-20 # # Only C++11 # Disable install compiler runtime # # # # Remove autogenerated CMake scripts # CMake script # PDB # Libraries # Defines