Skip to content

Commit

Permalink
(#14185) libstudxml: add 1.1.0-b.10+1 & bump dependencies
Browse files Browse the repository at this point in the history
* move 1.0.1 to 1.0.x folder

* bump dependencies

* add libstudxml/1.1.0-b.10+1

* partial conan v2 migration of 1.0.x

* small change

* fix conversion of Version to int

* improve support of compiler=msvc in 1.0.x
  • Loading branch information
SpaceIm authored Nov 25, 2022
1 parent 8740901 commit b2dc1a2
Show file tree
Hide file tree
Showing 19 changed files with 311 additions and 60 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from conans import ConanFile, AutoToolsBuildEnvironment, MSBuild, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import apply_conandata_patches, chdir, collect_libs, copy, export_conandata_patches, get, replace_in_file, rm, rmdir
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version
from conans import AutoToolsBuildEnvironment, MSBuild, tools
import os
import shutil

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.53.0"


class LibStudXmlConan(ConanFile):
Expand All @@ -13,10 +16,8 @@ class LibStudXmlConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.codesynthesis.com/projects/libstudxml/"
license = "MIT"
settings = "os", "compiler", "build_type", "arch"

exports_sources = "patches/*"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -32,36 +33,41 @@ class LibStudXmlConan(ConanFile):
def _source_subfolder(self):
return "source_subfolder"

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

def export_sources(self):
export_conandata_patches(self)

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

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

def layout(self):
pass

def requirements(self):
self.requires("expat/2.4.1")
self.requires("expat/2.5.0", transitive_headers=True, transitive_libs=True)

def validate(self):
if self.settings.compiler == "Visual Studio":
if tools.Version(self.settings.compiler.version) < "9":
raise ConanInvalidConfiguration("Visual Studio {} is not supported.".format(self.settings.compiler.version))

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
if self.info.settings.compiler == "Visual Studio" and Version(self.info.settings.compiler.version) < "9":
raise ConanInvalidConfiguration(f"Visual Studio {self.info.settings.compiler.version} is not supported.")

def build_requirements(self):
if self.settings.compiler != "Visual Studio":
self.build_requires("gnu-config/cci.20201022")
self.build_requires("libtool/2.4.6")
if not is_msvc(self):
self.tool_requires("gnu-config/cci.20210814")
self.tool_requires("libtool/2.4.7")
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")
self.tool_requires("msys2/cci.latest")

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_subfolder, strip_root=True)

def _configure_autotools(self):
if not self._autotools:
Expand All @@ -75,59 +81,75 @@ def _configure_autotools(self):
self._autotools.configure(configure_dir=self._source_subfolder, args=args)
return self._autotools

@property
def _vc_ver(self):
if self.settings.compiler == "Visual Studio":
return str(Version(self.settings.compiler.version).major)
elif self.settings.compiler == "msvc":
return {
"170": "11",
"180": "12",
"190": "14",
"191": "15",
"192": "16",
"193": "17",
}[str(self.settings.compiler.version)]
return None

def _build_vs(self):
vc_ver = int(tools.Version(self.settings.compiler.version).major)
vc_ver = int(self._vc_ver)
sln_path = None
def get_sln_path():
return os.path.join(self._source_subfolder, "libstudxml-vc{}.sln".format(vc_ver))
return os.path.join(self.source_folder, self._source_subfolder, f"libstudxml-vc{vc_ver}.sln")

sln_path = get_sln_path()
while not os.path.exists(sln_path):
vc_ver -= 1
sln_path = get_sln_path()

proj_path = os.path.join(self._source_subfolder, "xml", "libstudxml-vc{}.vcxproj".format(vc_ver))
proj_path = os.path.join(self.source_folder, self._source_subfolder, "xml", f"libstudxml-vc{vc_ver}.vcxproj")

if not self.options.shared:
tools.replace_in_file(proj_path, "DynamicLibrary", "StaticLibrary")
tools.replace_in_file(proj_path, "LIBSTUDXML_DYNAMIC_LIB", "LIBSTUDXML_STATIC_LIB")
replace_in_file(self, proj_path, "DynamicLibrary", "StaticLibrary")
replace_in_file(self, proj_path, "LIBSTUDXML_DYNAMIC_LIB", "LIBSTUDXML_STATIC_LIB")

msbuild = MSBuild(self)
msbuild.build(sln_path, platforms={"x86": "Win32"})

@property
def _user_info_build(self):
return getattr(self, "user_info_build", self.deps_user_info)

def _build_autotools(self):
shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB,
os.path.join(self._source_subfolder, "config", "config.sub"))
shutil.copy(self._user_info_build["gnu-config"].CONFIG_GUESS,
os.path.join(self._source_subfolder, "config", "config.guess"))
for gnu_config in [
self.conf.get("user.gnu-config:config_guess", check_type=str),
self.conf.get("user.gnu-config:config_sub", check_type=str),
]:
if gnu_config:
copy(
self,
os.path.basename(gnu_config),
src=os.path.dirname(gnu_config),
dst=os.path.join(self.source_folder, self._source_subfolder, "config"),
)

if self.settings.compiler.get_safe("libcxx") == "libc++":
# libc++ includes a file called 'version', and since libstudxml adds source_subfolder as an
# include dir, libc++ ends up including their 'version' file instead, causing a compile error
tools.remove_files_by_mask(self._source_subfolder, "version")
rm(self, "version", os.path.join(self.source_folder, self._source_subfolder))

with tools.chdir(self._source_subfolder):
with chdir(self, os.path.join(self.source_folder, self._source_subfolder)):
self.run("{} -fiv".format(tools.get_env("AUTORECONF")), win_bash=tools.os_info.is_windows)

autotools = self._configure_autotools()
autotools.make()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

if self.settings.compiler == "Visual Studio":
apply_conandata_patches(self)
if is_msvc(self):
self._build_vs()
else:
self._build_autotools()

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
if self.settings.compiler == "Visual Studio":
copy(self, "LICENSE", src=os.path.join(self.source_folder, self._source_subfolder), dst=os.path.join(self.package_folder, "licenses"))
if is_msvc(self):
self.copy("xml/value-traits", dst="include", src=self._source_subfolder)
self.copy("xml/serializer", dst="include", src=self._source_subfolder)
self.copy("xml/qname", dst="include", src=self._source_subfolder)
Expand All @@ -151,14 +173,14 @@ def package(self):
else:
autotools = self._configure_autotools()
autotools.install()
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "libstudxml.la")
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.names["pkg_config"] = "libstudxml"
self.cpp_info.set_property("pkg_config_name", "libstudxml")
self.cpp_info.libs = collect_libs(self)

# If built with makefile, static library mechanism is provided by their buildsystem already
if self.settings.compiler == "Visual Studio" and not self.options.shared:
if is_msvc(self) and not self.options.shared:
self.cpp_info.defines = ["LIBSTUDXML_STATIC_LIB=1"]
7 changes: 7 additions & 0 deletions recipes/libstudxml/1.0.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES CXX)

find_package(libstudxml REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE libstudxml::libstudxml)
26 changes: 26 additions & 0 deletions recipes/libstudxml/1.0.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 = "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 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/libstudxml/1.0.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
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)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


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)
Expand Down
40 changes: 40 additions & 0 deletions recipes/libstudxml/1.1.x/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.1)
project(libstudxml LANGUAGES C CXX)

find_package(EXPAT REQUIRED MODULE)

add_library(studxml
${LIBSTUDXML_SRC_DIR}/libstudxml/parser.cxx
${LIBSTUDXML_SRC_DIR}/libstudxml/qname.cxx
${LIBSTUDXML_SRC_DIR}/libstudxml/serializer.cxx
${LIBSTUDXML_SRC_DIR}/libstudxml/value-traits.cxx
${LIBSTUDXML_SRC_DIR}/libstudxml/details/genx/char-props.c
${LIBSTUDXML_SRC_DIR}/libstudxml/details/genx/genx.c
)
target_include_directories(studxml PUBLIC ${LIBSTUDXML_SRC_DIR})
target_link_libraries(studxml PUBLIC EXPAT::EXPAT)

if(BUILD_SHARED_LIBS)
target_compile_definitions(studxml
PRIVATE LIBSTUDXML_SHARED_BUILD
INTERFACE LIBSTUDXML_SHARED
)
else()
target_compile_definitions(studxml
PRIVATE LIBSTUDXML_STATIC_BUILD
INTERFACE LIBSTUDXML_STATIC
)
endif()

include(GNUInstallDirs)
install(
TARGETS studxml
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(
DIRECTORY ${LIBSTUDXML_SRC_DIR}/libstudxml
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING REGEX "(.*).(h|hxx|ixx|txx)$"
)
4 changes: 4 additions & 0 deletions recipes/libstudxml/1.1.x/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.1.0-b.10+1":
url: "https://git.codesynthesis.com/cgit/libstudxml/libstudxml/snapshot/v1.1.0-b.10%2b1.tar.xz"
sha256: "6773bb700b0b61fb117f0737f3c754d2be67d70766d63430b8a95bf147cc0368"
78 changes: 78 additions & 0 deletions recipes/libstudxml/1.1.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, replace_in_file, rmdir
import os

required_conan_version = ">=1.53.0"


class LibStudXmlConan(ConanFile):
name = "libstudxml"
description = "A streaming XML pull parser and streaming XML serializer implementation for modern, standard C++."
topics = ("xml", "xml-parser", "serialization")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.codesynthesis.com/projects/libstudxml/"
license = "MIT"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

exports_sources = "CMakeLists.txt"

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

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

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

def requirements(self):
self.requires("expat/2.5.0", transitive_headers=True, transitive_libs=True)

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["LIBSTUDXML_SRC_DIR"] = self.source_folder.replace("\\", "/")
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
# unvendor expat
rmdir(self, os.path.join(self.source_folder, "libstudxml", "details", "expat"))
replace_in_file(
self,
os.path.join(self.source_folder, "libstudxml", "parser.hxx"),
"#ifndef LIBSTUDXML_EXTERNAL_EXPAT",
"#if 0",
)

def build(self):
self._patch_sources()
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
cmake.build()

def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "libstudxml")
self.cpp_info.libs = ["studxml"]
self.cpp_info.defines = ["LIBSTUDXML_SHARED" if self.options.shared else "LIBSTUDXML_STATIC"]
7 changes: 7 additions & 0 deletions recipes/libstudxml/1.1.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES CXX)

find_package(libstudxml REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE libstudxml::libstudxml)
Loading

0 comments on commit b2dc1a2

Please sign in to comment.