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

Add more options for xerces-c recipe #6959

Merged
45 changes: 23 additions & 22 deletions recipes/xerces-c/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
from typing import Union, Tuple


class XercesCConan(ConanFile):
Expand All @@ -26,6 +25,15 @@ class XercesCConan(ConanFile):
"message_loader": ["inmemory", "icu", "iconv"],
"mutex_manager": ["standard", "posix", "windows"],
}
default_options = {
"shared": False,
"fPIC": True,
"char_type": "uint16_t",
"network_accessor": "socket",
"transcoder": "gnuiconv",
"message_loader": "inmemory",
"mutex_manager": "standard",
}

_cmake = None

Expand All @@ -37,7 +45,7 @@ def _source_subfolder(self):
def _build_subfolder(self):
return "build_subfolder"

def _validate(self, option: str, value: str, os: Union[str, Tuple[str]]):
def _validate(self, option, value, os):
"""
Validate that the given `option` has the required `value` for the given `os`
If not raises a ConanInvalidConfiguration error
Expand All @@ -47,34 +55,31 @@ def _validate(self, option: str, value: str, os: Union[str, Tuple[str]]):
:param os: either a single string or a tuple of strings containing the
OS(es) that `value` is valid on
"""
if ((isinstance(os, str) and self.settings.os != os) or \
(isinstance(os, tuple) and self.settings.os not in os)) \
and getattr(self.options, option) == value:
if self.settings.os not in os and getattr(self.options, option) == value:
raise ConanInvalidConfiguration(
f"Option '{option}={value}' is only supported on {os}"
"Option '{option}={value}' is only supported on {os}".format(
option=option, value=value, os=os
)
)

def validate(self):
self._validate("char_type", "wchar_t", "Windows")
self._validate("network_accessor", "winsock", "Windows")
self._validate("network_accessor", "cfurl", "Macos")
self._validate("char_type", "wchar_t", ("Windows", ))
self._validate("network_accessor", "winsock", ("Windows", ))
self._validate("network_accessor", "cfurl", ("Macos", ))
self._validate("network_accessor", "socket", ("Linux", "Macos"))
self._validate("network_accessor", "curl", ("Linux", "Macos"))
self._validate("transcoder", "macosunicodeconverter", "Macos")
self._validate("transcoder", "windows", "Windows")
self._validate("transcoder", "macosunicodeconverter", ("Macos", ))
self._validate("transcoder", "windows", ("Windows", ))
self._validate("mutex_manager", "posix", ("Linux", "Macos"))
self._validate("mutex_manager", "windows", "Windows")
self._validate("mutex_manager", "windows", ("Windows", ))

def requirements(self):
if "icu" in (self.options.transcoder, self.options.message_loader):
self.requires("icu/69.1")
if self.options.network_accessor == "curl":
self.requires("libcurl/7.78.0")

def config_options(self):
self.options.shared = False
self.options.fPIC = True
self.options.char_type = "uint16_t"
self.options.message_loader = "inmemory"

if self.settings.os == "Windows":
del self.options.fPIC
self.options.network_accessor = "winsock"
Expand All @@ -85,8 +90,6 @@ def config_options(self):
self.options.transcoder = "macosunicodeconverter"
self.options.mutex_manager = "posix"
elif self.settings.os == "Linux":
self.options.network_accessor = "socket"
self.options.transcoder = "gnuiconv"
self.options.mutex_manager = "posix"

def configure(self):
Expand All @@ -111,7 +114,7 @@ def _configure_cmake(self):
self._cmake.definitions["xmlch-type"] = self.options.char_type
self._cmake.definitions["mutex-manager"] = self.options.mutex_manager
# avoid picking up system dependency
self._cmake.definitions["CMAKE_DISABLE_FIND_PACKAGE_CURL"] = self.options.network_accessor != "curl"
self._cmake.definitions["CMAKE_DISABLE_FIND_PACKAGE_CURL"] = True
FMeinicke marked this conversation as resolved.
Show resolved Hide resolved
self._cmake.definitions["CMAKE_DISABLE_FIND_PACKAGE_ICU"] = True
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
Expand All @@ -136,7 +139,5 @@ def package_info(self):
self.cpp_info.frameworks = ["CoreFoundation", "CoreServices"]
elif self.settings.os == "Linux":
self.cpp_info.system_libs.append("pthread")
if self.options.network_accessor == "curl":
self.cpp_info.system_libs.append("curl")
self.cpp_info.names["cmake_find_package"] = "XercesC"
self.cpp_info.names["cmake_find_package_multi"] = "XercesC"