Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libmysqlclient: fix few issues with all shared + fix FreeBSD + modernize #9350

Merged
merged 9 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions recipes/libmysqlclient/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 2.8.12)

cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)
message(WARNING "Conan libMySQLclient Wrapped CMake")

include(../conanbuildinfo.cmake)
conan_basic_setup(NO_OUTPUT_DIRS)
conan_basic_setup(NO_OUTPUT_DIRS KEEP_RPATHS)

include("CMakeListsOriginal.txt")
30 changes: 15 additions & 15 deletions recipes/libmysqlclient/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
sources:
"8.0.17":
sha256: c6e3f38199a77bfd8a4925ca00b252d3b6159b90e4980c7232f1c58d6ca759d6
url: "https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.17.tar.gz"
"8.0.25":
sha256: c16aa9cf621bc028efba2bb11f3c36a323b125fa0d108ff92fab60e46309206e
url: "https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.25.tar.gz"
patches:
sha256: "c16aa9cf621bc028efba2bb11f3c36a323b125fa0d108ff92fab60e46309206e"
"8.0.17":
- base_path: "source_subfolder"
patch_file: "patches/0001-find-cmake.patch"
- base_path: "source_subfolder"
patch_file: "patches/0002-dont-install-static-libraries+fix-mysql-config.patch"
- base_path: "source_subfolder"
patch_file: "patches/0003-msvc-install-no-pdb.patch"
url: "https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.17.tar.gz"
sha256: "c6e3f38199a77bfd8a4925ca00b252d3b6159b90e4980c7232f1c58d6ca759d6"
patches:
"8.0.25":
- base_path: "source_subfolder"
patch_file: "patches/0004-fix-805-cpp17-build.patch"
- base_path: "source_subfolder"
patch_file: "patches/0005-fix-macos-12.0.x-version-detection.patch"
- patch_file: "patches/0004-fix-805-cpp17-build.patch"
base_path: "source_subfolder"
- patch_file: "patches/0005-fix-macos-12.0.x-version-detection.patch"
base_path: "source_subfolder"
"8.0.17":
- patch_file: "patches/0001-find-cmake.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-dont-install-static-libraries+fix-mysql-config.patch"
base_path: "source_subfolder"
- patch_file: "patches/0003-msvc-install-no-pdb.patch"
base_path: "source_subfolder"
193 changes: 128 additions & 65 deletions recipes/libmysqlclient/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
from conan.tools.microsoft import msvc_runtime_flag
from conan.tools.files import rename
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conans.tools import Version
import functools
import os

required_conan_version = ">=1.36.0"


class LibMysqlClientCConan(ConanFile):
name = "libmysqlclient"
url = "https://github.com/conan-io/conan-center-index"
description = "A MySQL client library for C development."
topics = ("conan", "mysql", "sql", "connector", "database")
topics = ("mysql", "sql", "connector", "database")
homepage = "https://dev.mysql.com/downloads/mysql/"
license = "GPL-2.0"
exports_sources = ["CMakeLists.txt", "patches/*"]
generators = "cmake"

settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False], "with_ssl": [True, False], "with_zlib": [True, False]}
default_options = {"shared": False, "fPIC": True, "with_ssl": True, "with_zlib": True}
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_ssl": [True, False],
"with_zlib": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_ssl": True,
"with_zlib": True,
}

short_paths = True
generators = "cmake", "pkg_config"

_cmake = None
@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]

@property
def _with_zstd(self):
Expand All @@ -28,24 +50,77 @@ def _with_lz4(self):
return tools.Version(self.version) > "8.0.17"

@property
def _source_subfolder(self):
return "source_subfolder"
def _compilers_minimum_version(self):
return {
"Visual Studio": "16" if tools.Version(self.version) > "8.0.17" else "15",
"gcc": "5.3",
"clang": "6",
}

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC

def requirements(self):
if self.options.with_ssl:
self.requires("openssl/1.1.1k")

self.requires("openssl/1.1.1m")
if self.options.with_zlib:
self.requires("zlib/1.2.11")
if self._with_zstd:
self.requires("zstd/1.5.0")
self.requires("zstd/1.5.2")
if self._with_lz4:
self.requires("lz4/1.9.3")
if self.settings.os == "FreeBSD":
self.requires("libunwind/1.5.0")

SpaceIm marked this conversation as resolved.
Show resolved Hide resolved
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("{} {} requires {} {} or newer".format(
self.name, self.version, self.settings.compiler, minimum_version,
))

if hasattr(self, "settings_build") and tools.cross_building(self, skip_x64_x86=True):
raise ConanInvalidConfiguration("Cross compilation not yet supported by the recipe. contributions are welcome.")

# FIXME: patch libmysqlclient 8.0.17 to support apple-clang >= 12?
# current errors:
# error: expected unqualified-id MYSQL_VERSION_MAJOR=8
# error: no member named 'ptrdiff_t' in the global namespace
if self.version == "8.0.17" and self.settings.compiler == "apple-clang" and \
tools.Version(self.settings.compiler.version) >= "12.0":
raise ConanInvalidConfiguration("libmysqlclient 8.0.17 doesn't support apple-clang >= 12.0")

def build_requirements(self):
if tools.Version(self.version) >= "8.0.25" and tools.is_apple_os(self.settings.os):
# CMake 3.18 or higher is required if Apple, but CI of CCI may run CMake 3.15
self.build_requires("cmake/3.22.0")
if self.settings.os == "FreeBSD":
self.build_requires("pkgconf/1.7.4")

SpaceIm marked this conversation as resolved.
Show resolved Hide resolved
def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
tools.get(**self.conan_data["sources"][self.version],
strip_root=True, destination=self._source_subfolder)

def _patch_files(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

libs_to_remove = ["icu", "libevent", "re2", "rapidjson", "protobuf", "libedit"]
if not self._with_lz4:
libs_to_remove.append("lz4")
Expand All @@ -59,7 +134,7 @@ def _patch_files(self):
"",
strict=False)
tools.rmdir(os.path.join(self._source_subfolder, "extra"))
for folder in ['client', 'man', 'mysql-test', "libbinlogstandalone"]:
for folder in ["client", "man", "mysql-test", "libbinlogstandalone"]:
tools.rmdir(os.path.join(self._source_subfolder, folder))
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"ADD_SUBDIRECTORY(%s)\n" % folder,
Expand All @@ -83,12 +158,20 @@ def _patch_files(self):
tools.replace_in_file(os.path.join(self._source_subfolder, "cmake", "ssl.cmake"),
"NAMES crypto",
"NAMES crypto %s" % self.deps_cpp_info["openssl"].components["crypto"].libs[0])
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

# Do not copy shared libs of dependencies to package folder
deps_shared = ["SSL"]
if tools.Version(self.version) > "8.0.17":
deps_shared.extend(["KERBEROS", "SASL", "LDAP", "PROTOBUF", "CURL"])
for dep in deps_shared:
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"MYSQL_CHECK_{}_DLLS()".format(dep),
"")

sources_cmake = os.path.join(self._source_subfolder, "CMakeLists.txt")
sources_cmake_orig = os.path.join(self._source_subfolder, "CMakeListsOriginal.txt")
tools.rename(sources_cmake, sources_cmake_orig)
tools.rename("CMakeLists.txt", sources_cmake)
rename(self, sources_cmake, sources_cmake_orig)
rename(self, "CMakeLists.txt", sources_cmake)
if self.settings.os == "Macos":
tools.replace_in_file(os.path.join(self._source_subfolder, "libmysql", "CMakeLists.txt"),
"COMMAND %s" % ("$<TARGET_FILE:libmysql_api_test>" if tools.Version(self.version) < "8.0.25" else "libmysql_api_test"),
Expand All @@ -97,56 +180,32 @@ def _patch_files(self):
" INSTALL_DEBUG_SYMBOLS(",
" # INSTALL_DEBUG_SYMBOLS(")

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC

def validate(self):
if self.settings.compiler == "Visual Studio":
if tools.Version(self.version) > "8.0.17":
if Version(self.settings.compiler.version) < "16":
raise ConanInvalidConfiguration("Visual Studio 16 2019 or newer is required")
else:
if Version(self.settings.compiler.version) < "15":
raise ConanInvalidConfiguration("Visual Studio 15 2017 or newer is required")
if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "5.3":
raise ConanInvalidConfiguration("GCC 5.3 or newer is required")
if self.settings.compiler == "clang" and Version(self.settings.compiler.version) < "6":
raise ConanInvalidConfiguration("clang 6 or newer is required")
if hasattr(self, "settings_build") and tools.cross_building(self, skip_x64_x86=True):
raise ConanInvalidConfiguration("Cross compilation not yet supported by the recipe. contributions are welcome.")

@functools.lru_cache(1)
def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["DISABLE_SHARED"] = not self.options.shared
self._cmake.definitions["STACK_DIRECTION"] = "-1" # stack grows downwards, on very few platforms stack grows upwards
self._cmake.definitions["WITHOUT_SERVER"] = True
self._cmake.definitions["WITH_UNIT_TESTS"] = False
self._cmake.definitions["ENABLED_PROFILING"] = False
self._cmake.definitions["WIX_DIR"] = False
cmake = CMake(self)
cmake.definitions["DISABLE_SHARED"] = not self.options.shared
cmake.definitions["STACK_DIRECTION"] = "-1" # stack grows downwards, on very few platforms stack grows upwards
cmake.definitions["WITHOUT_SERVER"] = True
cmake.definitions["WITH_UNIT_TESTS"] = False
cmake.definitions["ENABLED_PROFILING"] = False
cmake.definitions["WIX_DIR"] = False
if self._with_lz4:
self._cmake.definitions["WITH_LZ4"] = "system"
cmake.definitions["WITH_LZ4"] = "system"

if self._with_zstd:
self._cmake.definitions["WITH_ZSTD"] = "system"
self._cmake.definitions["ZSTD_INCLUDE_DIR"] = self.deps_cpp_info["zstd"].include_paths[0]
cmake.definitions["WITH_ZSTD"] = "system"
cmake.definitions["ZSTD_INCLUDE_DIR"] = self.deps_cpp_info["zstd"].include_paths[0]

if self.settings.compiler == "Visual Studio":
self._cmake.definitions["WINDOWS_RUNTIME_MD"] = "MD" in str(self.settings.compiler.runtime)
if self._is_msvc:
cmake.definitions["WINDOWS_RUNTIME_MD"] = "MD" in msvc_runtime_flag(self)

if self.options.with_ssl:
self._cmake.definitions["WITH_SSL"] = self.deps_cpp_info["openssl"].rootpath
cmake.definitions["WITH_SSL"] = self.deps_cpp_info["openssl"].rootpath

if self.options.with_zlib:
self._cmake.definitions["WITH_ZLIB"] = "system"
self._cmake.configure(source_dir=self._source_subfolder)
return self._cmake
cmake.definitions["WITH_ZLIB"] = "system"
cmake.configure(source_dir=self._source_subfolder)
return cmake

def build(self):
self._patch_files()
Expand All @@ -159,7 +218,7 @@ def package(self):
with tools.run_environment(self):
cmake.install()
os.mkdir(os.path.join(self.package_folder, "licenses"))
tools.rename(os.path.join(self.package_folder, "LICENSE"), os.path.join(self.package_folder, "licenses", "LICENSE"))
rename(self, os.path.join(self.package_folder, "LICENSE"), os.path.join(self.package_folder, "licenses", "LICENSE"))
os.remove(os.path.join(self.package_folder, "README"))
tools.remove_files_by_mask(self.package_folder, "*.pdb")
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
Expand All @@ -175,13 +234,17 @@ def package(self):
tools.remove_files_by_mask(self.package_folder, "*.so*")

def package_info(self):
self.cpp_info.libs = ["libmysql" if self.settings.os == "Windows" and self.options.shared else "mysqlclient"]
self.cpp_info.names["cmake_find_package"] = "MySQL"
self.cpp_info.names["cmake_find_package_multi"] = "MySQL"
self.cpp_info.set_property("pkg_config_name", "mysqlclient")
self.cpp_info.names["pkg_config"] = "mysqlclient"
self.cpp_info.libs = ["libmysql" if self.settings.os == "Windows" and self.options.shared else "mysqlclient"]
if not self.options.shared:
stdcpp_library = tools.stdcpp_library(self)
if stdcpp_library:
self.cpp_info.system_libs.append(stdcpp_library)
if self.settings.os == "Linux":
self.cpp_info.system_libs.append('m')
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")

# 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"
2 changes: 1 addition & 1 deletion recipes/libmysqlclient/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
Expand Down
4 changes: 2 additions & 2 deletions recipes/libmysqlclient/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"

def build(self):
Expand All @@ -12,6 +12,6 @@ def build(self):
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
4 changes: 2 additions & 2 deletions recipes/libmysqlclient/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
versions:
"8.0.17":
folder: all
"8.0.25":
folder: all
"8.0.17":
folder: all