[DO-981] qt package (!15)

Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/15
This commit is contained in:
Aleksandr Vodyanov
2025-02-13 12:25:48 +03:00
parent 60445ac09e
commit 3759e1163f
228 changed files with 16106 additions and 12 deletions

View File

@@ -0,0 +1,40 @@
sources:
"8.1.0":
url: "https://dev.mysql.com/get/Downloads/MySQL-8.1/mysql-8.1.0.tar.gz"
sha256: "3dd017a940734aa90796a4c65e125e6712f64bbbbe3388d36469deaa87b599eb"
"8.0.34":
url: "https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.34.tar.gz"
sha256: "e65d03a3c42618b5fbf99042aed33209402e9b27aa62c7c8743ffd4788d8db1d"
"8.0.31":
url: "https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.31.tar.gz"
sha256: "67bb8cba75b28e95c7f7948563f01fb84528fcbb1a35dba839d4ce44fe019baa"
"8.0.30":
url: "https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30.tar.gz"
sha256: "c988d5c6ba9a56692a6cd6e9813465b5fc9368ed4b461df97059a2fc160c8b84"
"8.0.25":
url: "https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.25.tar.gz"
sha256: "c16aa9cf621bc028efba2bb11f3c36a323b125fa0d108ff92fab60e46309206e"
patches:
"8.1.0":
- patch_file: "patches/0006-fix-cpp20-build-8.1.0.patch"
patch_description: "Fix C++20 compilation"
patch_type: "portability"
"8.0.34":
- patch_file: "patches/0006-fix-cpp20-build-8.0.29.patch"
patch_description: "Fix C++20 compilation"
patch_type: "portability"
"8.0.31":
- patch_file: "patches/0006-fix-cpp20-build-8.0.29.patch"
patch_description: "Fix C++20 compilation"
patch_type: "portability"
"8.0.30":
- patch_file: "patches/0006-fix-cpp20-build-8.0.29.patch"
patch_description: "Fix C++20 compilation"
patch_type: "portability"
"8.0.25":
- patch_file: "patches/0004-fix-805-cpp17-build.patch"
patch_description: "Fix C++17 compilation"
patch_type: "portability"
- patch_file: "patches/0005-fix-macos-12.0.x-version-detection.patch"
patch_description: "Fix macOS 12.0 version detection"
patch_type: "bugfix"

View File

@@ -0,0 +1,287 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd, cross_building, stdcpp_library
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.env import VirtualRunEnv, VirtualBuildEnv
from conan.tools.files import rename, get, apply_conandata_patches, replace_in_file, rmdir, rm, export_conandata_patches, mkdir
from conan.tools.gnu import PkgConfigDeps
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version
import os
required_conan_version = ">=1.55.0"
class LibMysqlClientCConan(ConanFile):
name = "libmysqlclient"
description = "A MySQL client library for C development."
license = "GPL-2.0"
url = "https://github.com/conan-io/conan-center-index"
topics = ("mysql", "sql", "connector", "database")
homepage = "https://dev.mysql.com/downloads/mysql/"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}
package_type = "library"
short_paths = True
@property
def _min_cppstd(self):
return "17" if Version(self.version) >= "8.0.27" else "11"
@property
def _compilers_minimum_version(self):
return {
"Visual Studio": "16",
"msvc": "192",
"gcc": "7" if Version(self.version) >= "8.0.27" else "5.3",
"clang": "6",
}
def export_sources(self):
export_conandata_patches(self)
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
def layout(self):
cmake_layout(self, src_folder="src")
def requirements(self):
if Version(self.version) < "8.0.30":
self.requires("openssl/1.1.1w")
else:
self.requires("openssl/[>=1.1 <4]")
self.requires("zlib/[>=1.2.11 <2]")
self.requires("zstd/1.5.5")
self.requires("lz4/1.9.4")
if self.settings.os == "FreeBSD":
self.requires("libunwind/1.7.2")
def validate_build(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)
if hasattr(self, "settings_build") and cross_building(self, skip_x64_x86=True):
raise ConanInvalidConfiguration("Cross compilation not yet supported by the recipe. Contributions are welcomed.")
def validate(self):
def loose_lt_semver(v1, v2):
lv1 = [int(v) for v in v1.split(".")]
lv2 = [int(v) for v in v2.split(".")]
min_length = min(len(lv1), len(lv2))
return lv1[:min_length] < lv2[:min_length]
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and loose_lt_semver(str(self.settings.compiler.version), minimum_version):
raise ConanInvalidConfiguration(f"{self.ref} requires {self.settings.compiler} {minimum_version} or newer")
# mysql < 8.0.29 uses `requires` in source code. It is the reserved keyword in C++20.
# https://github.com/mysql/mysql-server/blob/mysql-8.0.0/include/mysql/components/services/dynamic_loader.h#L270
if self.settings.compiler.get_safe("cppstd") == "20" and Version(self.version) < "8.0.29":
raise ConanInvalidConfiguration(f"{self.ref} doesn't support C++20")
def build_requirements(self):
if is_apple_os(self):
self.tool_requires("cmake/[>=3.18 <4]")
if self.settings.os == "FreeBSD" and not self.conf.get("tools.gnu:pkg_config", check_type=str):
self.tool_requires("pkgconf/2.0.3")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def _patch_sources(self):
apply_conandata_patches(self)
libs_to_remove = ["icu", "libevent", "re2", "rapidjson", "protobuf", "libedit"]
for lib in libs_to_remove:
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
f"MYSQL_CHECK_{lib.upper()}()\n",
"",
strict=False)
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
f"INCLUDE({lib})\n",
"",
strict=False)
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
f"WARN_MISSING_SYSTEM_{lib.upper()}({lib.upper()}_WARN_GIVEN)",
f"# WARN_MISSING_SYSTEM_{lib.upper()}({lib.upper()}_WARN_GIVEN)",
strict=False)
if lib != "libevent" or Version(self.version) < "8.0.34":
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
f"SET({lib.upper()}_WARN_GIVEN)",
f"# SET({lib.upper()}_WARN_GIVEN)",
strict=False)
for folder in ["client", "man", "mysql-test", "libbinlogstandalone"]:
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
f"ADD_SUBDIRECTORY({folder})\n",
"",
strict=False)
rmdir(self, os.path.join(self.source_folder, "storage", "ndb"))
for t in ["INCLUDE(cmake/boost.cmake)\n", "MYSQL_CHECK_EDITLINE()\n"]:
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
t,
"",
strict=False)
# Upstream does not actually load lz4 directories for system, force it to
if Version(self.version) < "8.0.34":
replace_in_file(self, os.path.join(self.source_folder, "libbinlogevents", "CMakeLists.txt"),
"INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/libbinlogevents/include)",
"MY_INCLUDE_SYSTEM_DIRECTORIES(LZ4)\nINCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/libbinlogevents/include)")
replace_in_file(self, os.path.join(self.source_folder, "cmake", "zstd.cmake"),
"NAMES zstd",
f"NAMES zstd {self.dependencies['zstd'].cpp_info.aggregated_components().libs[0]}")
# Fix discovery & link to OpenSSL
ssl_cmake = os.path.join(self.source_folder, "cmake", "ssl.cmake")
replace_in_file(self, ssl_cmake,
"NAMES ssl",
f"NAMES ssl {self.dependencies['openssl'].cpp_info.components['ssl'].libs[0]}")
replace_in_file(self, ssl_cmake,
"NAMES crypto",
f"NAMES crypto {self.dependencies['openssl'].cpp_info.components['crypto'].libs[0]}")
replace_in_file(self, ssl_cmake,
"IF(NOT OPENSSL_APPLINK_C)\n",
"IF(FALSE AND NOT OPENSSL_APPLINK_C)\n",
strict=False)
replace_in_file(self, ssl_cmake,
"SET(SSL_LIBRARIES ${MY_OPENSSL_LIBRARY} ${MY_CRYPTO_LIBRARY})",
"find_package(OpenSSL REQUIRED MODULE)\nset(SSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)")
# And do not merge OpenSSL libs into mysqlclient lib
replace_in_file(self, os.path.join(self.source_folder, "cmake", "libutils.cmake"),
'IF(WIN32 AND ${TARGET} STREQUAL "mysqlclient")',
"if(0)")
# Do not copy shared libs of dependencies to package folder
deps_shared = ["SSL", "KERBEROS", "SASL", "LDAP", "PROTOBUF"]
if Version(self.version) < "8.0.34":
deps_shared.append("CURL")
for dep in deps_shared:
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
f"MYSQL_CHECK_{dep}_DLLS()",
"")
if self.settings.os == "Macos":
replace_in_file(self, os.path.join(self.source_folder, "libmysql", "CMakeLists.txt"),
f"COMMAND {'libmysql_api_test'}",
f"COMMAND DYLD_LIBRARY_PATH={os.path.join(self.build_folder, 'library_output_directory')} {os.path.join(self.build_folder, 'runtime_output_directory', 'libmysql_api_test')}")
replace_in_file(self, os.path.join(self.source_folder, "cmake", "install_macros.cmake"),
" INSTALL_DEBUG_SYMBOLS(",
" # INSTALL_DEBUG_SYMBOLS(")
def generate(self):
vbenv = VirtualBuildEnv(self)
vbenv.generate()
if not cross_building(self):
vrenv = VirtualRunEnv(self)
vrenv.generate(scope="build")
tc = CMakeToolchain(self)
# Not used anywhere in the CMakeLists
tc.cache_variables["DISABLE_SHARED"] = not self.options.shared
tc.cache_variables["STACK_DIRECTION"] = "-1" # stack grows downwards, on very few platforms stack grows upwards
tc.cache_variables["WITHOUT_SERVER"] = True
tc.cache_variables["WITH_UNIT_TESTS"] = False
tc.cache_variables["ENABLED_PROFILING"] = False
tc.cache_variables["MYSQL_MAINTAINER_MODE"] = False
tc.cache_variables["WIX_DIR"] = False
# Disable additional Linux distro-specific compiler checks.
# The recipe already checks for minimum versions of supported
# compilers.
tc.cache_variables["FORCE_UNSUPPORTED_COMPILER"] = True
tc.cache_variables["WITH_LZ4"] = "system"
tc.cache_variables["WITH_ZSTD"] = "system"
tc.cache_variables["ZSTD_INCLUDE_DIR"] = self.dependencies["zstd"].cpp_info.aggregated_components().includedirs[0].replace("\\", "/")
if is_msvc(self):
tc.cache_variables["WINDOWS_RUNTIME_MD"] = not is_msvc_static_runtime(self)
tc.cache_variables["WITH_SSL"] = self.dependencies["openssl"].package_folder.replace("\\", "/")
tc.cache_variables["WITH_ZLIB"] = "system"
# Remove to ensure reproducible build, this only affects docs generation
tc.cache_variables["CMAKE_DISABLE_FIND_PACKAGE_Doxygen"] = True
tc.generate()
deps = CMakeDeps(self)
deps.generate()
if self.settings.os == "FreeBSD":
deps = PkgConfigDeps(self)
deps.generate()
def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
cmake = CMake(self)
cmake.install()
mkdir(self, os.path.join(self.package_folder, "licenses"))
rename(self, os.path.join(self.package_folder, "LICENSE"), os.path.join(self.package_folder, "licenses", "LICENSE"))
rm(self, "README", self.package_folder)
rm(self, "*.pdb", self.package_folder, recursive=True)
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "plugin"))
rmdir(self, os.path.join(self.package_folder, "docs"))
rmdir(self, os.path.join(self.package_folder, "share"))
if self.settings.os == "Windows":
if self.options.shared:
rename(self, os.path.join(self.package_folder, "lib", "libmysql.dll"),
os.path.join(self.package_folder, "bin", "libmysql.dll"))
rm(self, "*mysqlclient.*", os.path.join(self.package_folder, "lib"))
else:
rm(self, "*.dll", os.path.join(self.package_folder, "lib"))
rm(self, "*libmysql.*", os.path.join(self.package_folder, "lib"))
else:
if self.options.shared:
rm(self, "*.a", os.path.join(self.package_folder, "lib"))
else:
rm(self, "*.dylib", os.path.join(self.package_folder, "lib"))
rm(self, "*.so*", os.path.join(self.package_folder, "lib"))
def package_info(self):
self.cpp_info.set_property("pkg_config_name", "mysqlclient")
self.cpp_info.libs = ["libmysql" if self.settings.os == "Windows" and self.options.shared else "mysqlclient"]
self.cpp_info.includedirs.append(os.path.join("include", "mysql"))
if not self.options.shared:
stdcpplib = stdcpp_library(self)
if stdcpplib:
self.cpp_info.system_libs.append(stdcpplib)
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["m", "resolv"])
if self.settings.os == "Windows":
self.cpp_info.system_libs.extend(["dnsapi", "secur32"])
# TODO: There is no official FindMySQL.cmake, but it's a common Find files in many projects
# do we want to support it in CMakeDeps?
self.cpp_info.names["cmake_find_package"] = "MySQL"
self.cpp_info.names["cmake_find_package_multi"] = "MySQL"

View File

@@ -0,0 +1,13 @@
diff --git a/mysys/my_default.cc b/mysys/my_default.cc
--- a/mysys/my_default.cc
+++ b/mysys/my_default.cc
@@ -1180,7 +1180,7 @@ static mysql_file_getline_ret mysql_file_getline(char *buff, int size,
/* If the supplied buff/size is enough to store the line, then we return the
* buff itself. In this case, we use this noop deleter */
- static auto noop_free = [](void *) {};
+ static auto noop_free = [](void *) noexcept {};
if (is_login_file) {
if (mysql_file_ftell(file) == 0) {

View File

@@ -0,0 +1,13 @@
diff --git a/cmake/package_name.cmake b/cmake/package_name.cmake
index 192035dd..dedc59c6 100644
--- a/cmake/package_name.cmake
+++ b/cmake/package_name.cmake
@@ -94,7 +94,7 @@ MACRO(GET_PACKAGE_FILE_NAME Var)
STRING(REGEX MATCH
"ProductVersion:[\n\t ]*([0-9]+)\\.([0-9]+)" UNUSED ${SW_VERS_PRODUCTVERSION})
- IF(NOT CMAKE_MATCH_1 OR NOT CMAKE_MATCH_2)
+ IF(CMAKE_MATCH_1 STREQUAL "" OR CMAKE_MATCH_2 STREQUAL "")
MESSAGE(FATAL_ERROR "Could not run sw_vers")
ENDIF()

View File

@@ -0,0 +1,17 @@
diff --git a/sql/sql_bitmap.h b/sql/sql_bitmap.h
index a03d754..381216d 100644
--- a/sql/sql_bitmap.h
+++ b/sql/sql_bitmap.h
@@ -138,10 +138,10 @@ class Bitmap<64> {
ulonglong map;
public:
- Bitmap<64>() { init(); }
+ Bitmap() { init(); }
enum { ALL_BITS = 64 };
- explicit Bitmap<64>(uint prefix_to_set) { set_prefix(prefix_to_set); }
+ explicit Bitmap(uint prefix_to_set) { set_prefix(prefix_to_set); }
void init() { clear_all(); }
void init(uint prefix_to_set) { set_prefix(prefix_to_set); }
uint length() const { return 64; }

View File

@@ -0,0 +1,17 @@
diff --git a/sql/sql_bitmap.h b/sql/sql_bitmap.h
index 0f4a540..bd81a40 100644
--- a/sql/sql_bitmap.h
+++ b/sql/sql_bitmap.h
@@ -145,10 +145,10 @@ class Bitmap<64> {
ulonglong map;
public:
- Bitmap<64>() { init(); }
+ Bitmap() { init(); }
enum { ALL_BITS = 64 };
- explicit Bitmap<64>(uint prefix_to_set) { set_prefix(prefix_to_set); }
+ explicit Bitmap(uint prefix_to_set) { set_prefix(prefix_to_set); }
void init() { clear_all(); }
void init(uint prefix_to_set) { set_prefix(prefix_to_set); }
uint length() const { return 64; }

View File

@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)
find_package(libmysqlclient REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE libmysqlclient::libmysqlclient)

View File

@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires(self.tested_reference_str)
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")

View File

@@ -0,0 +1,8 @@
#include <mysql.h>
#include <stdio.h>
int main(int argc, char **argv)
{
printf("MySQL client version: %s\n", mysql_get_client_info());
return 0;
}

View File

@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
find_package(MySQL REQUIRED CONFIG)
add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE MySQL::MySQL)

View File

@@ -0,0 +1,18 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)