|
| 1 | +from conan import ConanFile |
| 2 | +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps |
| 3 | +from conan.tools.files import get, copy, apply_conandata_patches, export_conandata_patches |
| 4 | +from conan.errors import ConanInvalidConfiguration |
| 5 | +from conan.tools.apple import fix_apple_shared_install_name |
| 6 | +from conan.tools.build import check_min_cppstd |
| 7 | +import os |
| 8 | + |
| 9 | +required_conan_version = ">=2.0.9" |
| 10 | + |
| 11 | +class MariadbConnectorCppRecipe (ConanFile): |
| 12 | + name = "mariadb-connector-cpp" |
| 13 | + description = "MariaDB Connector/C++ is used to connect applications " \ |
| 14 | + "developed in C++ to MariaDB and MySQL databases." |
| 15 | + license = "LGPL-2.1-or-later" |
| 16 | + url = "https://github.com/conan-io/conan-center-index" |
| 17 | + homepage = "https://mariadb.com/docs/server/connect/programming-languages/cpp" |
| 18 | + topics = ("mariadb", "mysql", "database") |
| 19 | + package_type = "library" |
| 20 | + settings = "os", "compiler", "build_type", "arch" |
| 21 | + options = { |
| 22 | + "shared": [True, False], |
| 23 | + "fPIC": [True, False], |
| 24 | + "dyncol": [True, False], |
| 25 | + "with_curl": [True, False], |
| 26 | + "with_ssl": [False, "openssl", "gnutls", "schannel"], |
| 27 | + } |
| 28 | + default_options = { |
| 29 | + "shared": False, |
| 30 | + "fPIC": True, |
| 31 | + "dyncol": True, |
| 32 | + "with_curl": True, |
| 33 | + "with_ssl": "openssl", |
| 34 | + } |
| 35 | + implements = ["auto_shared_fpic"] |
| 36 | + |
| 37 | + def export_sources(self): |
| 38 | + export_conandata_patches(self) |
| 39 | + copy(self, "conan_cmake_project_include.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src")) |
| 40 | + |
| 41 | + def config_options(self): |
| 42 | + if self.settings.os == "Windows": |
| 43 | + self.options.rm_safe("fPIC") |
| 44 | + self.options.with_ssl = "schannel" |
| 45 | + |
| 46 | + def layout(self): |
| 47 | + cmake_layout(self, src_folder="src") |
| 48 | + |
| 49 | + def requirements(self): |
| 50 | + if self.options.with_curl: |
| 51 | + self.requires("libcurl/[>=7.78.0 <9]") |
| 52 | + |
| 53 | + # with_iconv doesn't exists on Windows (Why?) |
| 54 | + self.requires ("mariadb-connector-c/3.3.8", options={ |
| 55 | + "dyncol": self.options.dyncol, |
| 56 | + "with_curl": self.options.with_curl, |
| 57 | + "with_ssl": self.options.with_ssl |
| 58 | + }) |
| 59 | + |
| 60 | + def validate(self): |
| 61 | + check_min_cppstd(self, 14) |
| 62 | + if self.settings.os != "Windows" and self.options.with_ssl == "schannel": |
| 63 | + raise ConanInvalidConfiguration("schannel only supported on Windows") |
| 64 | + if self.options.with_ssl == "gnutls": |
| 65 | + raise ConanInvalidConfiguration("gnutls not yet available in CCI") |
| 66 | + |
| 67 | + def build_requirements(self): |
| 68 | + self.tool_requires("cmake/[>=3.23 <4]") |
| 69 | + |
| 70 | + def source(self): |
| 71 | + get(self, **self.conan_data["sources"][self.version], strip_root=True) |
| 72 | + apply_conandata_patches(self) |
| 73 | + |
| 74 | + def generate(self): |
| 75 | + deps = CMakeDeps(self) |
| 76 | + deps.generate() |
| 77 | + |
| 78 | + tc = CMakeToolchain(self) |
| 79 | + tc.cache_variables["CMAKE_PROJECT_mariadb_connector_cpp_INCLUDE"] = os.path.join(self.source_folder, "conan_cmake_project_include.cmake") |
| 80 | + tc.cache_variables["WITH_UNIT_TESTS"] = False |
| 81 | + tc.cache_variables["INSTALL_BINDIR"] = "bin" |
| 82 | + tc.cache_variables["INSTALL_LIBDIR"] = "lib" |
| 83 | + tc.cache_variables["INSTALL_PLUGINDIR"] = os.path.join("lib", "plugin").replace("\\", "/") |
| 84 | + tc.cache_variables["USE_SYSTEM_INSTALLED_LIB"] = True |
| 85 | + tc.cache_variables["MARIADB_LINK_DYNAMIC"] = True |
| 86 | + |
| 87 | + if self.settings.os == "Windows": |
| 88 | + tc.cache_variables["CONC_WITH_MSI"] = False |
| 89 | + tc.cache_variables["WITH_MSI"] = False |
| 90 | + |
| 91 | + # To install relocatable shared libs on Macos |
| 92 | + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW" |
| 93 | + |
| 94 | + tc.generate() |
| 95 | + |
| 96 | + def build(self): |
| 97 | + cmake = CMake(self) |
| 98 | + cmake.configure() |
| 99 | + cmake.build() |
| 100 | + |
| 101 | + def package(self): |
| 102 | + cmake = CMake(self) |
| 103 | + cmake.install(component="Headers") |
| 104 | + if self.options.shared: |
| 105 | + cmake.install(component="SharedLibraries") |
| 106 | + else: |
| 107 | + cmake.install(component="Development") |
| 108 | + |
| 109 | + copy(self, "COPYING", src=os.path.join(self.source_folder), dst=os.path.join(self.package_folder, "licenses")) |
| 110 | + |
| 111 | + fix_apple_shared_install_name(self) |
| 112 | + |
| 113 | + def package_info(self): |
| 114 | + self.cpp_info.set_property("cmake_find_mode", "both") |
| 115 | + self.cpp_info.set_property("cmake_file_name", "mariadb-connector-cpp") |
| 116 | + self.cpp_info.set_property("cmake_target_name", "mariadb-connector-cpp::mariadb-connector-cpp") |
| 117 | + self.cpp_info.set_property("pkg_config_name", "libmariadbcpp") |
| 118 | + |
| 119 | + if self.settings.os in ["Linux", "FreeBSD"]: |
| 120 | + self.cpp_info.system_libs = ["dl", "m", "pthread"] |
| 121 | + elif self.settings.os == "Windows": |
| 122 | + self.cpp_info.system_libs = ["ws2_32", "shlwapi"] |
| 123 | + if self.options.with_ssl == "schannel": |
| 124 | + self.cpp_info.system_libs.append("secur32") |
| 125 | + |
| 126 | + if self.options.shared: |
| 127 | + self.cpp_info.libs = ["mariadbcpp"] |
| 128 | + if self.settings.os == "Windows": |
| 129 | + self.cpp_info.defines.append("MARIADB_EXPORTED=__declspec(dllimport)") |
| 130 | + else: |
| 131 | + if self.settings.os == "Windows": |
| 132 | + self.cpp_info.libs = ["mariadbcpp-static"] |
| 133 | + self.cpp_info.defines.append("MARIADB_STATIC_LINK") |
| 134 | + else: |
| 135 | + self.cpp_info.libs = ["mariadbcpp"] |
0 commit comments