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

soci: conan v2 support #17026

Merged
merged 4 commits into from
Apr 24, 2023
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: 0 additions & 7 deletions recipes/soci/all/CMakeLists.txt

This file was deleted.

13 changes: 4 additions & 9 deletions recipes/soci/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ sources:
"4.0.3":
url: "https://github.com/SOCI/soci/archive/v4.0.3.tar.gz"
sha256: "4b1ff9c8545c5d802fbe06ee6cd2886630e5c03bf740e269bb625b45cf934928"
"4.0.2":
url: "https://github.com/SOCI/soci/archive/v4.0.2.tar.gz"
sha256: "f293192a412ed82693d17dfe46e2734b140bff835bc3259e3cbd7c315e5e2d74"
"4.0.1":
url: "https://github.com/SOCI/soci/archive/4.0.1.tar.gz"
sha256: "fa69347b1a1ef74450c0382b665a67bd6777cc7005bbe09726479625bcf1e29c"
patches:
"4.0.2":
- patch_file: "patches/0001-handle-libmysqlclient8.patch"
base_path: "source_subfolder"
"4.0.3":
- patch_file: "patches/0001-Remove-hardcoded-INSTALL_NAME_DIR-for-relocatable-li.patch"
patch_description: "Generate relocatable libraries on MacOS"
patch_type: "portability"
145 changes: 52 additions & 93 deletions recipes/soci/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from conan.tools.files import rename
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.55.0"


class SociConan(ConanFile):
Expand Down Expand Up @@ -42,41 +46,31 @@ class SociConan(ConanFile):
"with_boost": False,
}

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

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

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

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

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

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

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

def requirements(self):
if self.options.with_sqlite3:
self.requires("sqlite3/3.38.0")
self.requires("sqlite3/3.41.1")
if self.options.with_odbc and self.settings.os != "Windows":
self.requires("odbc/2.3.9")
self.requires("odbc/2.3.11")
if self.options.with_mysql:
self.requires("libmysqlclient/8.0.25")
self.requires("libmysqlclient/8.0.31")
if self.options.with_postgresql:
self.requires("libpq/13.4")
self.requires("libpq/14.7")
if self.options.with_boost:
self.requires("boost/1.78.0")
self.requires("boost/1.81.0")

@property
def _minimum_compilers_version(self):
Expand All @@ -89,12 +83,12 @@ def _minimum_compilers_version(self):

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
check_min_cppstd(self, 11)

compiler = str(self.settings.compiler)
compiler_version = tools.Version(self.settings.compiler.version.value)
compiler_version = Version(self.settings.compiler.version.value)
if compiler not in self._minimum_compilers_version:
self.output.warn("{} recipe lacks information about the {} compiler support.".format(self.name, self.settings.compiler))
self.output.warning("{} recipe lacks information about the {} compiler support.".format(self.name, self.settings.compiler))
elif compiler_version < self._minimum_compilers_version[compiler]:
raise ConanInvalidConfiguration("{} requires a {} version >= {}".format(self.name, compiler, compiler_version))

Expand All @@ -111,84 +105,49 @@ def validate(self):
raise ConanInvalidConfiguration("{} firebird {} ".format(prefix, message))

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

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmakelists = os.path.join(self._source_subfolder, "CMakeLists.txt")
tools.replace_in_file(cmakelists,
"set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})",
"list(APPEND CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake)")
tools.replace_in_file(cmakelists,
"set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})",
"list(APPEND CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake/modules)")

# Remove hardcoded install_name_dir, it prevents relocatable shared lib on macOS
soci_backend_cmake = os.path.join(self._source_subfolder, "cmake", "SociBackend.cmake")
soci_core_cmake = os.path.join(self._source_subfolder, "src", "core", "CMakeLists.txt")
tools.replace_in_file(soci_backend_cmake, "INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib", "")
tools.replace_in_file(soci_core_cmake, "INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib", "")

def _configure_cmake(self):
if self._cmake:
return self._cmake

self._cmake = CMake(self)

self._cmake.definitions["SOCI_SHARED"] = self.options.shared
self._cmake.definitions["SOCI_TESTS"] = False
self._cmake.definitions["SOCI_CXX11"] = True

if self.options.shared:
self._cmake.definitions["SOCI_STATIC"] = False

self._cmake.definitions["SOCI_EMPTY"] = self.options.empty
self._cmake.definitions["WITH_SQLITE3"] = self.options.with_sqlite3
self._cmake.definitions["WITH_DB2"] = self.options.with_db2
self._cmake.definitions["WITH_ODBC"] = self.options.with_odbc
self._cmake.definitions["WITH_ORACLE"] = self.options.with_oracle
self._cmake.definitions["WITH_FIREBIRD"] = self.options.with_firebird
self._cmake.definitions["WITH_MYSQL"] = self.options.with_mysql
self._cmake.definitions["WITH_POSTGRESQL"] = self.options.with_postgresql
self._cmake.definitions["WITH_BOOST"] = self.options.with_boost

# Relocatable shared lib on macOS
self._cmake.definitions["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"

self._cmake.configure()

return self._cmake
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)

tc.variables["SOCI_SHARED"] = self.options.shared
tc.variables["SOCI_STATIC"] = not self.options.shared
tc.variables["SOCI_TESTS"] = False
tc.variables["SOCI_CXX11"] = True
tc.variables["SOCI_EMPTY"] = self.options.empty
tc.variables["WITH_SQLITE3"] = self.options.with_sqlite3
tc.variables["WITH_DB2"] = self.options.with_db2
tc.variables["WITH_ODBC"] = self.options.with_odbc
tc.variables["WITH_ORACLE"] = self.options.with_oracle
tc.variables["WITH_FIREBIRD"] = self.options.with_firebird
tc.variables["WITH_MYSQL"] = self.options.with_mysql
tc.variables["WITH_POSTGRESQL"] = self.options.with_postgresql
tc.variables["WITH_BOOST"] = self.options.with_boost
tc.generate()

deps = CMakeDeps(self)
deps.generate()

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

def package(self):
self.copy("LICENSE_1_0.txt", dst="licenses", src=self._source_subfolder)
copy(self, "LICENSE_1_0.txt", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)

cmake = self._configure_cmake()
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "cmake"))

if os.path.isdir(os.path.join(self.package_folder, "lib64")):
if os.path.isdir(os.path.join(self.package_folder, "lib")):
self.copy("*", dst="lib", src="lib64", keep_path=False, symlinks=True)
tools.rmdir(os.path.join(self.package_folder, "lib64"))
else:
rename(self, os.path.join(self.package_folder, "lib64"), os.path.join(self.package_folder, "lib"))

os.remove(os.path.join(self.package_folder, "include", "soci", "soci-config.h.in"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "SOCI")

target_suffix = "" if self.options.shared else "_static"
lib_prefix = "lib" if self._is_msvc and not self.options.shared else ""
version = tools.Version(self.version)
lib_prefix = "lib" if is_msvc(self) and not self.options.shared else ""
version = Version(self.version)
lib_suffix = "_{}_{}".format(version.major, version.minor) if self.settings.os == "Windows" else ""

# soci_core
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From d491bf7b5040d314ffd0c6310ba01f78ff44c85e Mon Sep 17 00:00:00 2001
From: Rasmus Thomsen <[email protected]>
Date: Fri, 14 Apr 2023 09:16:29 +0200
Subject: [PATCH] Remove hardcoded INSTALL_NAME_DIR for relocatable libraries
on MacOS

---
cmake/SociBackend.cmake | 2 +-
src/core/CMakeLists.txt | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/cmake/SociBackend.cmake b/cmake/SociBackend.cmake
index 5d4ef0df..39fe1f77 100644
--- a/cmake/SociBackend.cmake
+++ b/cmake/SociBackend.cmake
@@ -171,7 +171,7 @@ macro(soci_backend NAME)
set_target_properties(${THIS_BACKEND_TARGET}
PROPERTIES
SOVERSION ${${PROJECT_NAME}_SOVERSION}
- INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
+ )

if(APPLE)
set_target_properties(${THIS_BACKEND_TARGET}
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 3e7deeae..f9eae564 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -59,7 +59,6 @@ if (SOCI_SHARED)
PROPERTIES
VERSION ${SOCI_VERSION}
SOVERSION ${SOCI_SOVERSION}
- INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib
CLEAN_DIRECT_OUTPUT 1)
endif()

--
2.25.1

17 changes: 0 additions & 17 deletions recipes/soci/all/patches/0001-handle-libmysqlclient8.patch

This file was deleted.

3 changes: 0 additions & 3 deletions recipes/soci/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(SOCI REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
Expand Down
20 changes: 14 additions & 6 deletions recipes/soci/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
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", "cmake_find_package_multi"
settings = "os", "arch", "compiler", "build_type",
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"

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")
8 changes: 8 additions & 0 deletions recipes/soci/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
17 changes: 17 additions & 0 deletions recipes/soci/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
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 tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
4 changes: 0 additions & 4 deletions recipes/soci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
versions:
"4.0.3":
folder: all
"4.0.2":
folder: all
"4.0.1":
folder: all