Skip to content

Commit

Permalink
conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm committed Oct 15, 2022
1 parent 5a274d8 commit e5428de
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 74 deletions.
7 changes: 0 additions & 7 deletions recipes/xerces-c/all/CMakeLists.txt

This file was deleted.

4 changes: 0 additions & 4 deletions recipes/xerces-c/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ sources:
patches:
"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"
"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"
96 changes: 46 additions & 50 deletions recipes/xerces-c/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.env import VirtualBuildEnv
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, collect_libs, copy, export_conandata_patches, get, rmdir
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.52.0"


class XercesCConan(ConanFile):
Expand Down Expand Up @@ -36,21 +39,8 @@ class XercesCConan(ConanFile):
"mutex_manager": "standard",
}

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

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

@property
def _build_subfolder(self):
return "build_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"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -67,13 +57,19 @@ def config_options(self):

def configure(self):
if self.options.shared:
del self.options.fPIC
try:
del self.options.fPIC
except Exception:
pass

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

def requirements(self):
if "icu" in (self.options.transcoder, self.options.message_loader):
self.requires("icu/70.1")
self.requires("icu/71.1")
if self.options.network_accessor == "curl":
self.requires("libcurl/7.80.0")
self.requires("libcurl/7.85.0")

def _validate(self, option, value, os):
"""
Expand All @@ -85,15 +81,15 @@ def _validate(self, option, value, os):
:param os: either a single string or a tuple of strings containing the
OS(es) that `value` is valid on
"""
if self.settings.os not in os and getattr(self.options, option) == value:
if self.info.settings.os not in os and getattr(self.info.options, option) == value:
raise ConanInvalidConfiguration(
"Option '{option}={value}' is only supported on {os}".format(
option=option, value=value, os=os
)
)

def validate(self):
if self.settings.os not in ("Windows", "Macos", "Linux"):
if self.info.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", ))
Expand All @@ -107,51 +103,51 @@ def validate(self):

def build_requirements(self):
if hasattr(self, "settings_build") and self.options.message_loader == "icu":
self.build_requires("icu/70.1")
self.tool_requires("icu/71.1")

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 _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
def generate(self):
env = VirtualBuildEnv(self)
env.generate()
tc = CMakeToolchain(self)
# https://xerces.apache.org/xerces-c/build-3.html
self._cmake.definitions["network-accessor"] = self.options.network_accessor
self._cmake.definitions["transcoder"] = self.options.transcoder
self._cmake.definitions["message-loader"] = self.options.message_loader
self._cmake.definitions["xmlch-type"] = self.options.char_type
self._cmake.definitions["mutex-manager"] = self.options.mutex_manager
tc.variables["network-accessor"] = self.options.network_accessor
tc.variables["transcoder"] = self.options.transcoder
tc.variables["message-loader"] = self.options.message_loader
tc.variables["xmlch-type"] = self.options.char_type
tc.variables["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_ICU"] = "icu" not in (self.options.transcoder, self.options.message_loader)
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
tc.variables["CMAKE_DISABLE_FIND_PACKAGE_CURL"] = self.options.network_accessor != "curl"
tc.variables["CMAKE_DISABLE_FIND_PACKAGE_ICU"] = "icu" not in (self.options.transcoder, self.options.message_loader)
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
self.copy(pattern="NOTICE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
for license in ("LICENSE", "NOTICE"):
copy(self, license, src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
# remove unneeded directories
tools.rmdir(os.path.join(self.package_folder, "share"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "cmake"))

def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "XercesC")
self.cpp_info.set_property("cmake_target_name", "XercesC::XercesC")
self.cpp_info.set_property("pkg_config_name", "xerces-c")
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.libs = collect_libs(self)
if self.settings.os == "Macos":
self.cpp_info.frameworks = ["CoreFoundation", "CoreServices"]
elif self.settings.os in ["Linux", "FreeBSD"]:
Expand Down
13 changes: 5 additions & 8 deletions recipes/xerces-c/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

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

find_package(XercesC REQUIRED CONFIG)
find_package(XercesC REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} XercesC::XercesC)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_link_libraries(${PROJECT_NAME} PRIVATE XercesC::XercesC)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
19 changes: 14 additions & 5 deletions recipes/xerces-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", "cmake_find_package_multi"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

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)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
11 changes: 11 additions & 0 deletions recipes/xerces-c/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

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

find_package(XercesC REQUIRED)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE XercesC::XercesC)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
17 changes: 17 additions & 0 deletions recipes/xerces-c/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"

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 e5428de

Please sign in to comment.