-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
mysql-connector-cpp: new recipe #25170
base: master
Are you sure you want to change the base?
Changes from 13 commits
e1b358f
daf4bcc
7f06c8e
8d61029
ca62fac
3169bfe
959f42d
b4a8ed3
11c4023
70c612a
f59bd4a
f8f313e
a236350
2f459ec
ed0bb9d
3b0ea6b
d1e517b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
sources: | ||
"9.0.0": | ||
url: "https://github.com/mysql/mysql-connector-cpp/archive/refs/tags/9.0.0.zip" | ||
sha256: "9d4b90a4efe8861e821136fb3024074d14875749d8b69d1821361b2f2b8bfe55" | ||
patches: | ||
"9.0.0": | ||
- patch_file: "patches/9.0.0/0001-override-cmake-policy-version.patch" | ||
patch_description: "Set CMake policy version to 3.15, move project() statement" | ||
patch_type: "conan" | ||
- patch_file: "patches/9.0.0/0002-rename-find_dependency.patch" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer having an issue pointed in the upstream about this. I understand the risk of name collision, but keeping it only here is not good as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not just a potential risk. The CMake configuration step consistently failed for me due to |
||
patch_description: "Rename find_dependency() to avoid conflicts with the official CMake function" | ||
patch_type: "conan" | ||
- patch_file: "patches/9.0.0/0003-inject-conan-dependencies.patch" | ||
patch_description: "Inject Conan dependencies" | ||
patch_type: "conan" | ||
- patch_file: "patches/9.0.0/0005-simplify-install-directories.patch" | ||
patch_description: "Do not install libraries into subdirectories" | ||
patch_type: "conan" | ||
- patch_file: "patches/9.0.0/0006-replace-merge_libraries-with-object-libs.patch" | ||
patch_description: "Replace fragile merge_libraries() call with object libraries" | ||
patch_type: "conan" |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,169 @@ | ||||||
import os | ||||||
|
||||||
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 | ||||||
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout | ||||||
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv | ||||||
from conan.tools.files import get, copy, rm, export_conandata_patches, apply_conandata_patches, replace_in_file | ||||||
from conan.tools.microsoft import is_msvc_static_runtime | ||||||
from conan.tools.scm import Version | ||||||
|
||||||
required_conan_version = ">=1.55.0" | ||||||
|
||||||
|
||||||
class MysqlConnectorCppConan(ConanFile): | ||||||
name = "mysql-connector-cpp" | ||||||
description = "MySQL database connector for C++ applications" | ||||||
license = "GPL-2.0-only WITH Universal-FOSS-exception-1.0" | ||||||
url = "https://github.com/conan-io/conan-center-index" | ||||||
homepage = "https://dev.mysql.com/doc/connector-cpp/en/" | ||||||
topics = ("mysql", "sql", "connector", "database") | ||||||
|
||||||
package_type = "library" | ||||||
settings = "os", "arch", "compiler", "build_type" | ||||||
options = { | ||||||
"shared": [True, False], | ||||||
"fPIC": [True, False], | ||||||
} | ||||||
default_options = { | ||||||
"shared": False, | ||||||
"fPIC": True, | ||||||
} | ||||||
|
||||||
@property | ||||||
def _min_cppstd(self): | ||||||
return 17 | ||||||
|
||||||
@property | ||||||
def _compilers_minimum_version(self): | ||||||
return { | ||||||
"Visual Studio": "16", | ||||||
"msvc": "192", | ||||||
"gcc": "8", | ||||||
"clang": "7", | ||||||
"apple-clang": "10", | ||||||
} | ||||||
|
||||||
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): | ||||||
# None of the dependencies are used transitively | ||||||
self.requires("protobuf/3.21.12") # v4 and newer are not supported as of v9.0.0 | ||||||
self.requires("openssl/[>=1.1 <4]") | ||||||
self.requires("rapidjson/1.1.0") | ||||||
self.requires("zlib/[>=1.2.11 <2]") | ||||||
self.requires("lz4/1.9.4") | ||||||
self.requires("zstd/[~1.5]") | ||||||
|
||||||
def validate(self): | ||||||
if self.settings.compiler.get_safe("cppstd"): | ||||||
check_min_cppstd(self, self._min_cppstd) | ||||||
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) | ||||||
if minimum_version and Version(self.settings.compiler.version) < minimum_version: | ||||||
raise ConanInvalidConfiguration(f"{self.ref} requires {self.settings.compiler} {minimum_version} or newer") | ||||||
|
||||||
def build_requirements(self): | ||||||
self.tool_requires("cmake/[>=3.24 <4]") | ||||||
self.tool_requires("protobuf/<host_version>") | ||||||
|
||||||
def source(self): | ||||||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||||||
|
||||||
def generate(self): | ||||||
VirtualBuildEnv(self).generate() | ||||||
if self.dependencies["protobuf"].options.shared: | ||||||
VirtualRunEnv(self).generate(scope="build") | ||||||
|
||||||
tc = CMakeToolchain(self) | ||||||
tc.cache_variables["BUNDLE_DEPENDENCIES"] = False | ||||||
tc.cache_variables["BUILD_STATIC"] = not self.options.shared | ||||||
tc.cache_variables["STATIC_MSVCRT"] = is_msvc_static_runtime(self) | ||||||
tc.cache_variables["WITH_TESTS"] = False | ||||||
tc.cache_variables["CMAKE_TRY_COMPILE_CONFIGURATION"] = str(self.settings.build_type) | ||||||
tc.cache_variables["WITH_SSL"] = self.dependencies["openssl"].package_folder.replace("\\", "/") | ||||||
tc.cache_variables["CMAKE_PREFIX_PATH"] = self.generators_folder.replace("\\", "/") | ||||||
tc.cache_variables["IS64BIT"] = True | ||||||
tc.generate() | ||||||
|
||||||
deps = CMakeDeps(self) | ||||||
deps.set_property("protobuf::libprotobuf", "cmake_target_name", "ext::protobuf") | ||||||
deps.set_property("protobuf::libprotobuf-lite", "cmake_target_name", "ext::protobuf-lite") | ||||||
deps.set_property("rapidjson", "cmake_target_name", "RapidJSON::rapidjson") | ||||||
deps.set_property("zlib", "cmake_target_name", "ext::z") | ||||||
deps.set_property("lz4", "cmake_target_name", "ext::lz4") | ||||||
deps.set_property("zstd", "cmake_target_name", "ext::zstd") | ||||||
deps.generate() | ||||||
|
||||||
def _patch_sources(self): | ||||||
apply_conandata_patches(self) | ||||||
# Disable boostrap(), which is unnecessary and fragile with variables set by Conan | ||||||
# https://github.com/mysql/mysql-connector-cpp/blob/9.0.0/CMakeLists.txt#L69-L71 | ||||||
# https://github.com/mysql/mysql-connector-cpp/blob/9.0.0/cdk/cmake/bootstrap.cmake#L55 | ||||||
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), "bootstrap()", "") | ||||||
|
||||||
def build(self): | ||||||
self._patch_sources() | ||||||
cmake = CMake(self) | ||||||
cmake.configure() | ||||||
cmake.build() | ||||||
|
||||||
def package(self): | ||||||
copy(self, "LICENSE.txt", self.source_folder, os.path.join(self.package_folder, "licenses")) | ||||||
cmake = CMake(self) | ||||||
cmake.install() | ||||||
rm(self, "INFO_SRC", self.package_folder) | ||||||
rm(self, "INFO_BIN", self.package_folder) | ||||||
rm(self, "*.cmake", self.package_folder) | ||||||
|
||||||
def package_info(self): | ||||||
self.cpp_info.set_property("cmake_file_name", "mysql-concpp") | ||||||
self.cpp_info.set_property("cmake_target_name", "mysql::concpp") | ||||||
|
||||||
aliases = ["mysql::concpp-xdevapi"] | ||||||
if not self.options.shared: | ||||||
aliases.append("mysql::concpp-static") | ||||||
aliases.append("mysql::concpp-xdevapi-static") | ||||||
if self.settings.build_type == "Debug": | ||||||
aliases.append("mysql::concpp-static-debug") | ||||||
aliases.append("mysql::concpp-xdevapi-static-debug") | ||||||
aliases.append("mysql::openssl") | ||||||
self.cpp_info.set_property("cmake_target_aliases", aliases) | ||||||
|
||||||
lib = "mysqlcppconnx" | ||||||
if not self.options.shared: | ||||||
lib += "-static" | ||||||
if is_msvc_static_runtime(self): | ||||||
lib += "-mt" | ||||||
self.cpp_info.libs = [lib] | ||||||
|
||||||
if self.settings.os == "Windows": | ||||||
self.cpp_info.system_libs.append("dnsapi") | ||||||
self.cpp_info.system_libs.append("ws2_32") | ||||||
valgur marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
elif self.settings.os != "FreeBSD": | ||||||
self.cpp_info.system_libs.append("resolv") | ||||||
if self.settings.os == "SunOS": | ||||||
self.cpp_info.system_libs.append("socket") | ||||||
self.cpp_info.system_libs.append("nsl") | ||||||
valgur marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
if not self.options.shared: | ||||||
self.cpp_info.defines = ["MYSQL_STATIC", "STATIC_CONCPP"] | ||||||
|
||||||
|
||||||
if is_apple_os(self) or self.settings.os in ["Linux", "FreeBSD"]: | ||||||
self.cpp_info.system_libs.extend(["resolv"]) | ||||||
if self.settings.os in ["Linux", "FreeBSD"]: | ||||||
self.cpp_info.system_libs.extend(["m", "pthread"]) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
https://github.com/mysql/mysql-connector-cpp/blob/9.0.0/mysql-concpp-config.cmake.in#L463 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
From fdc950d95b215527fb1bd1790fb24b4c427bf807 Mon Sep 17 00:00:00 2001 | ||
From: Martin Valgur <[email protected]> | ||
Date: Fri, 6 Sep 2024 17:56:39 +0300 | ||
Subject: [PATCH 1/2] Set CMake policy version to 3.15, move project() | ||
|
||
--- | ||
CMakeLists.txt | 8 ++++---- | ||
1 file changed, 4 insertions(+), 4 deletions(-) | ||
|
||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 341ed2de..4d747849 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -27,10 +27,10 @@ | ||
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
|
||
-CMAKE_MINIMUM_REQUIRED(VERSION 3.8) | ||
+CMAKE_MINIMUM_REQUIRED(VERSION 3.15) | ||
+PROJECT(MySQL_CONCPP) | ||
+ | ||
|
||
-CMAKE_POLICY(VERSION 3.1) | ||
-cmake_policy(SET CMP0022 NEW) | ||
|
||
|
||
SET(BUILDTYPE_DOCSTRING | ||
@@ -73,7 +73,7 @@ endif() | ||
|
||
########################################################################## | ||
|
||
-PROJECT(MySQL_CONCPP) | ||
+ | ||
|
||
# Load cmake modules | ||
|
||
@@ -87,7 +87,7 @@ | ||
# Detect if we are configured as stand-alone project, or sub-project. | ||
# | ||
|
||
-if(PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME) | ||
+if(1) | ||
|
||
SET(concpp_stand_alone 1) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
From 4d5a57343a8cb54a787b68c42a6b2379bbce2a84 Mon Sep 17 00:00:00 2001 | ||
From: Martin Valgur <[email protected]> | ||
Date: Fri, 6 Sep 2024 19:04:24 +0300 | ||
Subject: [PATCH 1/2] Rename find_dependency() to avoid with official version | ||
|
||
--- | ||
CMakeLists.txt | 4 ++-- | ||
cdk/CMakeLists.txt | 8 ++++---- | ||
cdk/cmake/dependency.cmake | 6 +++--- | ||
cdk/protocol/mysqlx/CMakeLists.txt | 4 ++-- | ||
4 files changed, 11 insertions(+), 11 deletions(-) | ||
|
||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 4d747849..65b043a5 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -177,7 +177,7 @@ endif() | ||
# Gcov support (Linux only) | ||
# | ||
|
||
-find_dependency(Coverage) # defines add_coverage() command | ||
+find_dep(Coverage) # defines add_coverage() command | ||
#message("WITH_COVERAGE: ${WITH_COVERAGE}") | ||
|
||
|
||
@@ -306,7 +306,7 @@ endif() | ||
# Note: Find OpenSSL early because it is needed by both CDK and JDBC (in case | ||
# of static linking with the client library) | ||
|
||
-find_dependency(SSL) | ||
+find_dep(SSL) | ||
|
||
|
||
# | ||
diff --git a/cdk/CMakeLists.txt b/cdk/CMakeLists.txt | ||
index dc8e3adc..4a9a164d 100644 | ||
--- a/cdk/CMakeLists.txt | ||
+++ b/cdk/CMakeLists.txt | ||
@@ -93,10 +93,10 @@ add_config(CDK_BIG_ENDIAN ${BIG_ENDIAN}) | ||
# Dependencies | ||
# | ||
|
||
-find_dependency(SSL) | ||
-#find_dependency(Protobuf) | ||
-find_dependency(RapidJSON) | ||
-find_dependency(Coverage) | ||
+find_dep(SSL) | ||
+#find_dep(Protobuf) | ||
+find_dep(RapidJSON) | ||
+find_dep(Coverage) | ||
|
||
|
||
# TODO: These macros should not be used in public headers because they are | ||
diff --git a/cdk/cmake/dependency.cmake b/cdk/cmake/dependency.cmake | ||
index e3fec4ee..3c38ca5c 100644 | ||
--- a/cdk/cmake/dependency.cmake | ||
+++ b/cdk/cmake/dependency.cmake | ||
@@ -33,20 +33,20 @@ include(config_options) | ||
|
||
########################################################################## | ||
# | ||
-# find_dependency(XXX) command. | ||
+# find_dep(XXX) command. | ||
# | ||
# Currently it is looking for DepFindXXX.cmake script that should perform | ||
# all steps required to locate given dependency and make it available in | ||
# the project. It is a layer on top of find_module(). | ||
# | ||
|
||
-function(find_dependency NAME) | ||
+macro(find_dep NAME) | ||
|
||
# TODO: Fallback to find_module() | ||
|
||
include(DepFind${NAME}) | ||
|
||
-endfunction(find_dependency) | ||
+endmacro(find_dep) | ||
|
||
|
||
# Variables to forward from this build configuration to external | ||
diff --git a/cdk/protocol/mysqlx/CMakeLists.txt b/cdk/protocol/mysqlx/CMakeLists.txt | ||
index a9873127..2ee4f937 100644 | ||
--- a/cdk/protocol/mysqlx/CMakeLists.txt | ||
+++ b/cdk/protocol/mysqlx/CMakeLists.txt | ||
@@ -26,8 +26,8 @@ | ||
# along with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
-find_dependency(Protobuf) | ||
-find_dependency(Compression) | ||
+find_dep(Protobuf) | ||
+find_dep(Compression) | ||
|
||
include(CheckIncludeFile) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't see an error when not using this patch. I would avoid if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, looks like the issues were caused by
bootstrap()
rather than the policy version orproject()
call location.