Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
(conan-io#12839) mariadb-connector-c: conan v2 support
Browse files Browse the repository at this point in the history
* conan v2 support

* remove test_package_pkgconfigdeps for the moment
  • Loading branch information
SpaceIm authored and ericLemanissier committed Sep 26, 2022
1 parent 487d15b commit 257748e
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 82 deletions.
7 changes: 0 additions & 7 deletions recipes/mariadb-connector-c/all/CMakeLists.txt

This file was deleted.

10 changes: 0 additions & 10 deletions recipes/mariadb-connector-c/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,13 @@ sources:
patches:
"3.1.12":
- patch_file: "patches/0001-fix-install-and-static-or-shared.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-msvc-no-override-md-zi.patch"
base_path: "source_subfolder"
- patch_file: "patches/0003-include-order-windows-winsock2.patch"
base_path: "source_subfolder"
- patch_file: "patches/0004-include-mysqld_error-header.patch"
base_path: "source_subfolder"
- patch_file: "patches/0005-fix-cmake-connectorname.patch"
base_path: "source_subfolder"
"3.1.11":
- patch_file: "patches/0001-fix-install-and-static-or-shared.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-msvc-no-override-md-zi.patch"
base_path: "source_subfolder"
- patch_file: "patches/0003-include-order-windows-winsock2.patch"
base_path: "source_subfolder"
- patch_file: "patches/0004-include-mysqld_error-header.patch"
base_path: "source_subfolder"
- patch_file: "patches/0005-fix-cmake-connectorname.patch"
base_path: "source_subfolder"
117 changes: 61 additions & 56 deletions recipes/mariadb-connector-c/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, collect_libs, copy, get, replace_in_file, rm, rmdir
import os

required_conan_version = ">=1.36.0"
required_conan_version = ">=1.51.1"


class MariadbConnectorcConan(ConanFile):
Expand Down Expand Up @@ -32,17 +34,9 @@ class MariadbConnectorcConan(ConanFile):
"with_ssl": "openssl",
}

generators = "cmake", "cmake_find_package"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

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

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -53,8 +47,14 @@ def config_options(self):
def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass

def requirements(self):
self.requires("zlib/1.2.12")
Expand All @@ -66,68 +66,73 @@ def requirements(self):
self.requires("openssl/1.1.1q")

def validate(self):
if self.settings.os != "Windows" and self.options.with_ssl == "schannel":
if self.info.settings.os != "Windows" and self.info.options.with_ssl == "schannel":
raise ConanInvalidConfiguration("schannel only supported on Windows")
if self.options.with_ssl == "gnutls":
if self.info.options.with_ssl == "gnutls":
raise ConanInvalidConfiguration("gnutls not yet available in CCI")

def layout(self):
cmake_layout(self, src_folder="src")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
if self.settings.os == "Windows":
tc.variables["WITH_MSI"] = False
tc.variables["WITH_SIGNCODE"] = False
tc.variables["WITH_RTC"] = False
else:
tc.variables["WITH_MYSQLCOMPAT"] = False
tc.variables["WITH_ICONV"] = self.options.with_iconv
tc.variables["WITH_UNIT_TESTS"] = False
tc.variables["WITH_DYNCOL"] = self.options.dyncol
tc.variables["WITH_EXTERNAL_ZLIB"] = True
tc.variables["WITH_CURL"] = self.options.with_curl
tc.variables["WITH_SSL"] = self.options.with_ssl
tc.variables["INSTALL_BINDIR"] = "bin"
tc.variables["INSTALL_LIBDIR"] = "lib"
tc.variables["INSTALL_PLUGINDIR"] = os.path.join("lib", "plugin").replace("\\", "/")
# To install relocatable shared libs on Macos
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
tc.generate()
deps = CMakeDeps(self)
deps.generate()

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

root_cmake = os.path.join(self._source_subfolder, "CMakeLists.txt")
tools.replace_in_file(root_cmake, "${ZLIB_LIBRARY}", "${ZLIB_LIBRARIES}")
tools.replace_in_file(
root_cmake = os.path.join(self.source_folder, "CMakeLists.txt")
replace_in_file(self, root_cmake, "${ZLIB_LIBRARY}", "${ZLIB_LIBRARIES}")
replace_in_file(self,
root_cmake,
"SET(SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})",
"SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES})"
"SET(SSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)"
)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
if self.settings.os == "Windows":
self._cmake.definitions["WITH_MSI"] = False
self._cmake.definitions["WITH_SIGNCODE"] = False
self._cmake.definitions["WITH_RTC"] = False
else:
self._cmake.definitions["WITH_MYSQLCOMPAT"] = False
self._cmake.definitions["WITH_ICONV"] = self.options.with_iconv
self._cmake.definitions["WITH_UNIT_TESTS"] = False
self._cmake.definitions["WITH_DYNCOL"] = self.options.dyncol
self._cmake.definitions["WITH_EXTERNAL_ZLIB"] = True
self._cmake.definitions["WITH_CURL"] = self.options.with_curl
self._cmake.definitions["WITH_SSL"] = self.options.with_ssl
self._cmake.definitions["INSTALL_BINDIR"] = "bin"
self._cmake.definitions["INSTALL_LIBDIR"] = "lib"
self._cmake.definitions["INSTALL_PLUGINDIR"] = os.path.join("lib", "plugin").replace("\\", "/")
# To install relocatable shared libs on Macos
self._cmake.definitions["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
self._cmake.configure()
return self._cmake
replace_in_file(self, root_cmake, "${CURL_LIBRARIES}", "CURL::libcurl")
plugins_io_cmake = os.path.join(self.source_folder, "plugins", "io", "CMakeLists.txt")
replace_in_file(self, plugins_io_cmake, "${CURL_LIBRARIES}", "CURL::libcurl")

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("COPYING.LIB", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "COPYING.LIB", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "symbols"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.pdb")
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "symbols"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "libmariadb")
self.cpp_info.includedirs.append(os.path.join("include", "mariadb"))
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.libs = collect_libs(self)
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["dl", "m", "pthread"]
elif self.settings.os == "Windows":
Expand Down
7 changes: 3 additions & 4 deletions recipes/mariadb-connector-c/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)
project(test_package LANGUAGES C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(mariadb-connector-c REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE mariadb-connector-c::mariadb-connector-c)
19 changes: 14 additions & 5 deletions recipes/mariadb-connector-c/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
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 = "cmake"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
10 changes: 10 additions & 0 deletions recipes/mariadb-connector-c/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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(mariadb-connector-c REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE mariadb-connector-c::mariadb-connector-c)
21 changes: 21 additions & 0 deletions recipes/mariadb-connector-c/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from conans import ConanFile, CMake, tools
import os


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

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

0 comments on commit 257748e

Please sign in to comment.