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

poco: conan v2 support #12868

Merged
merged 6 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
26 changes: 0 additions & 26 deletions recipes/poco/all/CMakeLists.txt

This file was deleted.

23 changes: 0 additions & 23 deletions recipes/poco/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,57 +38,34 @@ sources:
patches:
"1.12.2":
- patch_file: patches/1.12.2.patch
base_path: src
- patch_file: patches/0002-mysql-include.patch
base_path: src
"1.12.1":
- patch_file: patches/1.12.1.patch
base_path: src
- patch_file: patches/0002-mysql-include.patch
base_path: src
"1.12.0":
- patch_file: patches/1.12.0.patch
base_path: src
- patch_file: patches/0002-mysql-include.patch
base_path: src
"1.11.3":
- patch_file: patches/1.11.3.patch
base_path: src
- patch_file: patches/0002-mysql-include.patch
base_path: src
"1.11.2":
- patch_file: patches/1.11.2.patch
base_path: src
- patch_file: patches/0002-mysql-include.patch
base_path: src
"1.11.1":
- patch_file: patches/1.11.1.patch
base_path: src
- patch_file: patches/0002-mysql-include.patch
base_path: src
"1.11.0":
- patch_file: patches/1.11.0.patch
base_path: src
- patch_file: patches/0002-mysql-include.patch
base_path: src
"1.10.1":
- patch_file: patches/1.10.1.patch
base_path: src
"1.10.0":
- patch_file: patches/1.10.0.patch
base_path: src
- patch_file: patches/1.10.0-set-missing-cmake-variable.patch
base_path: src
"1.9.4":
- patch_file: patches/1.9.2.patch
base_path: src
- patch_file: patches/1.9.2-2.patch
base_path: src
"1.9.3":
- patch_file: patches/1.9.2.patch
base_path: src
- patch_file: patches/1.9.2-2.patch
base_path: src
"1.8.1":
- patch_file: patches/1.8.1.patch
base_path: src
184 changes: 114 additions & 70 deletions recipes/poco/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import msvc_runtime_flag, is_msvc
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, get, replace_in_file, rm, rmdir
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime, msvc_runtime_flag, VCVars
from conan.tools.scm import Version
from conan.tools.files import get, patch, rmdir

from conans import CMake, tools

from collections import namedtuple
import functools
import os


required_conan_version = ">=1.47.0"
required_conan_version = ">=1.50.0"


class PocoConan(ConanFile):
Expand Down Expand Up @@ -80,20 +76,9 @@ class PocoConan(ConanFile):
default_options[comp.option] = comp.default_option
del comp

generators = "cmake", "cmake_find_package"

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

@property
def _build_subfolder(self):
return "build"

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 Down Expand Up @@ -128,6 +113,9 @@ def configure(self):
foundation_external_dependencies = self._poco_component_tree["Foundation"].external_dependencies
self._poco_component_tree["Foundation"] = self._poco_component_tree["Foundation"]._replace(external_dependencies = list(map(lambda x: 'pcre2::pcre2' if x == 'pcre::pcre' else x, foundation_external_dependencies)))

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

def requirements(self):
if Version(self.version) < "1.12":
self.requires("pcre/8.45")
Expand All @@ -151,11 +139,14 @@ def requirements(self):
if self.options.get_safe("enable_data_mysql"):
self.requires("libmysqlclient/8.0.29")

def package_id(self):
del self.info.options.enable_active_record

def validate(self):
if self.options.enable_apacheconnector:
if self.info.options.enable_apacheconnector:
# FIXME: missing apache2 recipe + few issues
raise ConanInvalidConfiguration("Apache connector not supported: https://github.com/pocoproject/poco/issues/1764")
if is_msvc(self) and self.options.shared and "MT" in msvc_runtime_flag(self):
if is_msvc(self) and self.info.options.shared and is_msvc_static_runtime(self):
raise ConanInvalidConfiguration("Cannot build shared poco libraries with MT(d) runtime")
for compopt in self._poco_component_tree.values():
if not compopt.option:
Expand All @@ -165,74 +156,127 @@ def validate(self):
if not self._poco_component_tree[compdep].option:
continue
if not self.options.get_safe(self._poco_component_tree[compdep].option, False):
raise ConanInvalidConfiguration("option {} requires also option {}".format(compopt.option, self._poco_component_tree[compdep].option))
if self.options.enable_data_sqlite:
if self.options["sqlite3"].threadsafe == 0:
raise ConanInvalidConfiguration(f"option {compopt.option} requires also option {self._poco_component_tree[compdep].option}")
if self.info.options.enable_data_sqlite:
if self.dependencies["sqlite3"].options.threadsafe == 0:
raise ConanInvalidConfiguration("sqlite3 must be built with threadsafe enabled")
if self.options.enable_netssl and self.options.get_safe("enable_netssl_win", False):
if self.info.options.enable_netssl and self.options.get_safe("enable_netssl_win", False):
raise ConanInvalidConfiguration("Conflicting enable_netssl[_win] settings")

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

def _patch_sources(self):
for data in self.conan_data.get("patches", {}).get(self.version, []):
patch(self, **data)
def _dep_include_paths(self, dep):
dep_info = self.dependencies[dep]
return [os.path.join(dep_info.package_folder, dir).replace("\\", "/") for dir in dep_info.cpp_info.includedirs]

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["CMAKE_BUILD_TYPE"] = self.settings.build_type
def _dep_lib_paths(self, dep):
dep_info = self.dependencies[dep]
return [os.path.join(dep_info.package_folder, dir).replace("\\", "/") for dir in dep_info.cpp_info.libdirs]

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CMAKE_BUILD_TYPE"] = self.settings.build_type
if Version(self.version) < "1.10.1":
cmake.definitions["POCO_STATIC"] = not self.options.shared
tc.variables["POCO_STATIC"] = not self.options.shared
for comp in self._poco_component_tree.values():
if comp.option:
cmake.definitions[comp.option.upper()] = self.options.get_safe(comp.option, False)
cmake.definitions["POCO_UNBUNDLED"] = True
cmake.definitions["CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP"] = True
tc.variables[comp.option.upper()] = self.options.get_safe(comp.option, False)
tc.variables["POCO_UNBUNDLED"] = True
tc.variables["CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP"] = True
if is_msvc(self):
cmake.definitions["POCO_MT"] = "MT" in msvc_runtime_flag(self)
tc.variables["POCO_MT"] = is_msvc_static_runtime(self)
if self.options.get_safe("enable_data_postgresql", False):
cmake.definitions["PostgreSQL_ROOT_DIR"] = self.deps_cpp_info["libpq"].rootpath
cmake.definitions["PostgreSQL_ROOT_INCLUDE_DIRS"] = ";".join(self.deps_cpp_info["libpq"].include_paths)
cmake.definitions["PostgreSQL_ROOT_LIBRARY_DIRS"] = ";".join(self.deps_cpp_info["libpq"].lib_paths)
tc.variables["PostgreSQL_ROOT_DIR"] = self.dependencies["libpq"].package_folder.replace("\\", "/")
tc.variables["PostgreSQL_ROOT_INCLUDE_DIRS"] = ";".join(self._dep_include_paths("libpq"))
tc.variables["PostgreSQL_ROOT_LIBRARY_DIRS"] = ";".join(self._dep_lib_paths("libpq"))
if self.options.get_safe("enable_data_mysql", False):
cmake.definitions["MYSQL_ROOT_DIR"] = self.deps_cpp_info["libmysqlclient"].rootpath
cmake.definitions["MYSQL_ROOT_INCLUDE_DIRS"] = ";".join(self.deps_cpp_info["libmysqlclient"].include_paths)
cmake.definitions["MYSQL_INCLUDE_DIR"] = ";".join(self.deps_cpp_info["libmysqlclient"].include_paths)
cmake.definitions["MYSQL_ROOT_LIBRARY_DIRS"] = ";".join(self.deps_cpp_info["libmysqlclient"].lib_paths)
tc.variables["MYSQL_ROOT_DIR"] = self.dependencies["libmysqlclient"].package_folder.replace("\\", "/")
tc.variables["MYSQL_ROOT_INCLUDE_DIRS"] = ";".join(self._dep_include_paths("libmysqlclient"))
tc.variables["MYSQL_INCLUDE_DIR"] = ";".join(self._dep_include_paths("libmysqlclient"))
tc.variables["MYSQL_ROOT_LIBRARY_DIRS"] = ";".join(self._dep_lib_paths("libmysqlclient"))
if self.options.enable_apacheconnector:
cmake.definitions["APR_ROOT_DIR"] = self.deps_cpp_info["apr"].rootpath
cmake.definitions["APR_ROOT_INCLUDE_DIRS"] = ";".join(self.deps_cpp_info["apr"].include_paths)
cmake.definitions["APR_ROOT_LIBRARY_DIRS"] = ";".join(self.deps_cpp_info["apr"].lib_paths)
cmake.definitions["APRUTIL_ROOT_DIR"] = self.deps_cpp_info["apr-util"].rootpath
cmake.definitions["APRUTIL_ROOT_INCLUDE_DIRS"] = ";".join(self.deps_cpp_info["apr-util"].include_paths)
cmake.definitions["APRUTIL_ROOT_LIBRARY_DIRS"] = ";".join(self.deps_cpp_info["apr-util"].lib_paths)

tc.variables["APR_ROOT_DIR"] = self.dependencies["apr"].package_folder.replace("\\", "/")
tc.variables["APR_ROOT_INCLUDE_DIRS"] = ";".join(self._dep_include_paths("apr"))
tc.variables["APR_ROOT_LIBRARY_DIRS"] = ";".join(self._dep_lib_paths("apr"))
tc.variables["APRUTIL_ROOT_DIR"] = self.dependencies["apr-util"].package_folder.replace("\\", "/")
tc.variables["APRUTIL_ROOT_INCLUDE_DIRS"] = ";".join(self._dep_include_paths("apr-util"))
tc.variables["APRUTIL_ROOT_LIBRARY_DIRS"] = ";".join(self._dep_lib_paths("apr-util"))
# Disable fork
if not self.options.get_safe("enable_fork", True):
cmake.definitions["POCO_NO_FORK_EXEC"] = True
# On Windows, Poco needs a message (MC) compiler.
with tools.vcvars(self.settings) if is_msvc(self) else tools.no_op():
cmake.configure(build_dir=self._build_subfolder)
return cmake
tc.variables["POCO_NO_FORK_EXEC"] = True
# Disable automatic linking on MSVC
tc.preprocessor_definitions["POCO_NO_AUTOMATIC_LIBS"] = "1"
# Picked up from conan v1 CMake wrapper, don't know the rationale
if Version(self.version) >= "1.11.0":
tc.preprocessor_definitions["XML_DTD"] = "1"
# Honor BUILD_SHARED_LIBS from conan_toolchain (see https://github.com/conan-io/conan/issues/11840)
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
tc.generate()

deps = CMakeDeps(self)
deps.generate()

if is_msvc(self):
# On Windows, Poco needs a message (MC) compiler.
vcvars = VCVars(self)
vcvars.generate()

def _patch_sources(self):
apply_conandata_patches(self)
# mysql
if self.options.get_safe("enable_data_mysql"):
mysql_cpp_info = self.dependencies["libmysqlclient"].cpp_info
mysql_config_file = mysql_cpp_info.get_property("cmake_file_name") or "libmysqlclient"
replace_in_file(
self,
os.path.join(self.source_folder, "CMakeLists.txt"),
"find_package(MySQL REQUIRED)",
f"find_package({mysql_config_file} REQUIRED CONFIG)\nset(MYSQL_FOUND TRUE)",
)
mysql_target_name = mysql_cpp_info.get_property("cmake_target_name") or "libmysqlclient::libmysqlclient"
replace_in_file(
self,
os.path.join(self.source_folder, "Data", "MySQL", "CMakeLists.txt"),
"MySQL::client",
mysql_target_name,
)
# libpq
replace_in_file(
self,
os.path.join(self.source_folder, "CMakeLists.txt"),
"find_package(PostgreSQL REQUIRED)",
"find_package(PostgreSQL REQUIRED)\nset(POSTGRESQL_FOUND TRUE)",
)
replace_in_file(
self,
os.path.join(self.source_folder, "Data", "PostgreSQL", "CMakeLists.txt"),
"PostgreSQL::client",
"PostgreSQL::PostgreSQL",
)
# Ensure to use FindEXPAT.cmake instead of expat-config.cmake
# (side effect of CMAKE_FIND_PACKAGE_PREFER_CONFIG ON, see https://github.com/conan-io/conan/issues/10387)
replace_in_file(
self,
os.path.join(self.source_folder, "XML", "CMakeLists.txt"),
"find_package(EXPAT REQUIRED)",
"find_package(EXPAT REQUIRED MODULE)",
)

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

def package_id(self):
del self.info.options.enable_active_record

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

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "Poco")
Expand All @@ -249,14 +293,14 @@ def package_info(self):

for compname, comp in self._poco_component_tree.items():
if comp.option is None or self.options.get_safe(comp.option):
conan_component = "poco_{}".format(compname.lower())
requires = ["poco_{}".format(dependency.lower()) for dependency in comp.dependencies] + comp.external_dependencies
self.cpp_info.components[conan_component].set_property("cmake_target_name", "Poco::{}".format(compname))
conan_component = f"poco_{compname.lower()}"
requires = [f"poco_{dependency.lower()}" for dependency in comp.dependencies] + comp.external_dependencies
self.cpp_info.components[conan_component].set_property("cmake_target_name", f"Poco::{compname}")
self.cpp_info.components[conan_component].set_property("cmake_file_name", compname)
self.cpp_info.components[conan_component].names["cmake_find_package"] = compname
self.cpp_info.components[conan_component].names["cmake_find_package_multi"] = compname
if comp.is_lib:
self.cpp_info.components[conan_component].libs = ["Poco{}{}".format(compname, suffix)]
self.cpp_info.components[conan_component].libs = [f"Poco{compname}{suffix}"]
self.cpp_info.components[conan_component].requires = requires

if self.settings.os in ["Linux", "FreeBSD"]:
Expand Down
2 changes: 1 addition & 1 deletion recipes/poco/all/patches/1.10.0.patch
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

if (POCO_UNBUNDLED)
- target_link_libraries(Foundation PUBLIC Pcre::Pcre ZLIB::ZLIB)
+ target_link_libraries(Foundation PUBLIC PCRE::PCRE ZLIB::ZLIB)
+ target_link_libraries(Foundation PUBLIC pcre::pcre ZLIB::ZLIB)
target_compile_definitions(Foundation PUBLIC POCO_UNBUNDLED)
endif (POCO_UNBUNDLED)

Expand Down
2 changes: 1 addition & 1 deletion recipes/poco/all/patches/1.10.1.patch
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

if(POCO_UNBUNDLED)
- target_link_libraries(Foundation PUBLIC Pcre::Pcre ZLIB::ZLIB)
+ target_link_libraries(Foundation PUBLIC PCRE::PCRE ZLIB::ZLIB)
+ target_link_libraries(Foundation PUBLIC pcre::pcre ZLIB::ZLIB)
target_compile_definitions(Foundation PUBLIC POCO_UNBUNDLED)
endif(POCO_UNBUNDLED)

Expand Down
2 changes: 1 addition & 1 deletion recipes/poco/all/patches/1.11.0.patch
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ index 6b276be..81cb8b7 100644

if(POCO_UNBUNDLED)
- target_link_libraries(Foundation PUBLIC Pcre::Pcre ZLIB::ZLIB)
+ target_link_libraries(Foundation PUBLIC PCRE::PCRE ZLIB::ZLIB)
+ target_link_libraries(Foundation PUBLIC pcre::pcre ZLIB::ZLIB)
target_compile_definitions(Foundation PUBLIC POCO_UNBUNDLED)
endif(POCO_UNBUNDLED)

Expand Down
2 changes: 1 addition & 1 deletion recipes/poco/all/patches/1.11.1.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ index 6b276be..81cb8b7 100644

if(POCO_UNBUNDLED)
- target_link_libraries(Foundation PUBLIC Pcre::Pcre ZLIB::ZLIB)
+ target_link_libraries(Foundation PUBLIC PCRE::PCRE ZLIB::ZLIB)
+ target_link_libraries(Foundation PUBLIC pcre::pcre ZLIB::ZLIB)
target_compile_definitions(Foundation PUBLIC POCO_UNBUNDLED)
endif(POCO_UNBUNDLED)

Expand Down
2 changes: 1 addition & 1 deletion recipes/poco/all/patches/1.11.2.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ index 6b276be..81cb8b7 100644

if(POCO_UNBUNDLED)
- target_link_libraries(Foundation PUBLIC Pcre::Pcre ZLIB::ZLIB)
+ target_link_libraries(Foundation PUBLIC PCRE::PCRE ZLIB::ZLIB)
+ target_link_libraries(Foundation PUBLIC pcre::pcre ZLIB::ZLIB)
target_compile_definitions(Foundation PUBLIC POCO_UNBUNDLED)
endif(POCO_UNBUNDLED)

Expand Down
Loading