Skip to content

Commit

Permalink
Merge pull request #2 from SpaceIm/fix/xerces-c-cross-build-use-find-…
Browse files Browse the repository at this point in the history
…conan

xerces-c: fix cross-build when message_loader=icu + use Find CMake module generared by conan
  • Loading branch information
FMeinicke committed Sep 7, 2021
2 parents 3ad9499 + 229b814 commit 2eb723e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 32 deletions.
4 changes: 4 additions & 0 deletions recipes/xerces-c/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ patches:
"3.2.2":
- patch_file: "patches/0001-remove-test-samples.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-find-icu-programs.patch"
base_path: "source_subfolder"
"3.2.3":
- patch_file: "patches/0001-remove-test-samples.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-find-icu-programs.patch"
base_path: "source_subfolder"
58 changes: 32 additions & 26 deletions recipes/xerces-c/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

required_conan_version = ">=1.33.0"


class XercesCConan(ConanFile):
name = "xerces-c"
description = (
Expand All @@ -13,8 +14,7 @@ class XercesCConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://xerces.apache.org/xerces-c/index.html"
license = "Apache-2.0"
exports_sources = ["CMakeLists.txt", "patches/*"]
generators = "cmake", "cmake_find_package_multi"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -36,6 +36,8 @@ class XercesCConan(ConanFile):
"mutex_manager": "standard",
}

exports_sources = ["CMakeLists.txt", "patches/*"]
generators = "cmake", "cmake_find_package"
_cmake = None

@property
Expand All @@ -46,6 +48,29 @@ def _source_subfolder(self):
def _build_subfolder(self):
return "build_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
self.options.network_accessor = "winsock"
self.options.transcoder = "windows"
self.options.mutex_manager = "windows"
elif self.settings.os == "Macos":
self.options.network_accessor = "cfurl"
self.options.transcoder = "macosunicodeconverter"
self.options.mutex_manager = "posix"
elif self.settings.os == "Linux":
self.options.mutex_manager = "posix"

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

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 _validate(self, option, value, os):
"""
Validate that the given `option` has the required `value` for the given `os`
Expand All @@ -64,6 +89,8 @@ def _validate(self, option, value, os):
)

def validate(self):
if self.settings.os not in ("Windows", "Macos", "Linux"):
raise ConanInvalidConfiguration("OS is not supported")
self._validate("char_type", "wchar_t", ("Windows", ))
self._validate("network_accessor", "winsock", ("Windows", ))
self._validate("network_accessor", "cfurl", ("Macos", ))
Expand All @@ -74,30 +101,9 @@ def validate(self):
self._validate("mutex_manager", "posix", ("Linux", "Macos"))
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):
if self.settings.os == "Windows":
del self.options.fPIC
self.options.network_accessor = "winsock"
self.options.transcoder = "windows"
self.options.mutex_manager = "windows"
elif self.settings.os == "Macos":
self.options.network_accessor = "cfurl"
self.options.transcoder = "macosunicodeconverter"
self.options.mutex_manager = "posix"
elif self.settings.os == "Linux":
self.options.mutex_manager = "posix"

def configure(self):
if self.settings.os not in ("Windows", "Macos", "Linux"):
raise ConanInvalidConfiguration("OS is not supported")
if self.options.shared:
del self.options.fPIC
def build_requirements(self):
if hasattr(self, "settings_build") and self.options.message_loader == "icu":
self.build_requires("icu/69.1")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
Expand Down
12 changes: 12 additions & 0 deletions recipes/xerces-c/all/patches/0002-find-icu-programs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1146,6 +1146,9 @@ if(XERCES_USE_MSGLOADER_ICU)
list(APPEND libxerces_c_SOURCES ${msgicu_sources} ${msgicu_nodist_sources})
list(APPEND libxerces_c_HEADERS ${msgicu_headers})
list(APPEND libxerces_c_DEPS ICU::uc ICU::data)
+ find_program(ICU_GENCMN_EXECUTABLE gencmn PATHS ENV PATH NO_DEFAULT_PATH)
+ find_program(ICU_GENRB_EXECUTABLE genrb PATHS ENV PATH NO_DEFAULT_PATH)
+ find_program(ICU_GENCCODE_EXECUTABLE genccode PATHS ENV PATH NO_DEFAULT_PATH)

# Resource shortname
set(PKGNAME xercesc_messages_${INTERFACE_VERSION_U})
6 changes: 4 additions & 2 deletions recipes/xerces-c/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ cmake_minimum_required(VERSION 3.1)
project(test_package)

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

find_package(XercesC REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} XercesC::XercesC)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
8 changes: 4 additions & 4 deletions recipes/xerces-c/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import os
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
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.settings):
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 2eb723e

Please sign in to comment.