Skip to content

Commit

Permalink
(#14427) libxml2: fix CMake vars in CMakeDeps & bump icu
Browse files Browse the repository at this point in the history
* fix CMake vars

* bump icu

* reduce path size in test package
  • Loading branch information
SpaceIm authored Dec 8, 2022
1 parent 63ce451 commit e72e91e
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 71 deletions.
33 changes: 19 additions & 14 deletions recipes/libxml2/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def configure(self):
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

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

def requirements(self):
if self.options.zlib:
self.requires("zlib/1.2.13")
Expand All @@ -94,10 +97,7 @@ def requirements(self):
if self.options.iconv:
self.requires("libiconv/1.17")
if self.options.icu:
self.requires("icu/71.1")

def layout(self):
basic_layout(self, src_folder="src")
self.requires("icu/72.1")

def build_requirements(self):
if not (is_msvc(self) or self._is_mingw_windows):
Expand Down Expand Up @@ -151,7 +151,6 @@ def generate(self):
tc = AutotoolsDeps(self)
tc.generate()


def _build_msvc(self):
with chdir(self, os.path.join(self.source_folder, 'win32')):
debug = "yes" if self.settings.build_type == "Debug" else "no"
Expand Down Expand Up @@ -215,7 +214,6 @@ def _package_msvc(self):
if self.options.include_utils:
self.run("nmake /f Makefile.msvc install-dist")


def _build_mingw(self):
with chdir(self, os.path.join(self.source_folder, "win32")):
# configuration
Expand Down Expand Up @@ -269,7 +267,6 @@ def _package_mingw(self):
if self.options.include_utils:
self.run("mingw32-make -f Makefile.mingw install-dist")


def _patch_sources(self):
# Break dependency of install on build
for makefile in ("Makefile.mingw", "Makefile.msvc"):
Expand All @@ -281,7 +278,6 @@ def _patch_sources(self):
"-install_name \\$rpath/",
"-install_name @rpath/")


def build(self):
self._patch_sources()
if is_msvc(self):
Expand Down Expand Up @@ -345,22 +341,31 @@ def package(self):
def _create_cmake_module_variables(self, module_file):
# FIXME: also define LIBXML2_XMLLINT_EXECUTABLE variable
content = textwrap.dedent("""\
if(DEFINED LibXml2_FOUND)
set(LIBXML2_FOUND ${LibXml2_FOUND})
endif()
if(DEFINED LibXml2_INCLUDE_DIR)
set(LIBXML2_INCLUDE_DIR ${LibXml2_INCLUDE_DIR})
set(LIBXML2_INCLUDE_DIRS ${LibXml2_INCLUDE_DIR})
set(LibXml2_FOUND TRUE)
set(LIBXML2_FOUND TRUE)
if(DEFINED LibXml2_INCLUDE_DIRS)
set(LIBXML2_INCLUDE_DIR ${LibXml2_INCLUDE_DIRS})
set(LIBXML2_INCLUDE_DIRS ${LibXml2_INCLUDE_DIRS})
elseif(DEFINED libxml2_INCLUDE_DIRS)
set(LIBXML2_LIBRARIES ${libxml2_INCLUDE_DIRS})
set(LIBXML2_LIBRARY ${libxml2_INCLUDE_DIRS})
endif()
if(DEFINED LibXml2_LIBRARIES)
set(LIBXML2_LIBRARIES ${LibXml2_LIBRARIES})
set(LIBXML2_LIBRARY ${LibXml2_LIBRARIES})
elseif(DEFINED libxml2_LIBRARIES)
set(LIBXML2_LIBRARIES ${libxml2_LIBRARIES})
set(LIBXML2_LIBRARY ${libxml2_LIBRARIES})
endif()
if(DEFINED LibXml2_DEFINITIONS)
set(LIBXML2_DEFINITIONS ${LibXml2_DEFINITIONS})
elseif(DEFINED libxml2_DEFINITIONS)
set(LIBXML2_DEFINITIONS ${libxml2_DEFINITIONS})
endif()
if(DEFINED LibXml2_VERSION)
set(LIBXML2_VERSION_STRING ${LibXml2_VERSION})
elseif(DEFINED libxml2_VERSION)
set(LIBXML2_VERSION_STRING ${libxml2_VERSION})
endif()
""")
save(self, module_file, content)
Expand Down
15 changes: 0 additions & 15 deletions recipes/libxml2/all/test_cmake_module_package/CMakeLists.txt

This file was deleted.

26 changes: 26 additions & 0 deletions recipes/libxml2/all/test_module_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.12)
project(test_package LANGUAGES C)

find_package(LibXml2 REQUIRED MODULE)

add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE LibXml2::LibXml2)

# Test whether variables from https://cmake.org/cmake/help/latest/module/FindLibXml2.html
# are properly defined in conan generators
set(_custom_vars
LibXml2_FOUND # since CMake 3.14
LIBXML2_FOUND # until CMake 3.14
LIBXML2_INCLUDE_DIR
LIBXML2_INCLUDE_DIRS
LIBXML2_LIBRARIES
LIBXML2_DEFINITIONS
LIBXML2_VERSION_STRING
)
foreach(_custom_var ${_custom_vars})
if(DEFINED _custom_var)
message(STATUS "${_custom_var}: ${${_custom_var}}")
else()
message(FATAL_ERROR "${_custom_var} not defined")
endif()
endforeach()
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def build(self):
def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
xml_path = os.path.join(self.source_folder, "..", "test_package", "books.xml")
xml_path = os.path.join(self.source_folder, os.pardir, "test_package", "books.xml")
self.run(f"{bin_path} {xml_path}", env="conanrun")
6 changes: 3 additions & 3 deletions recipes/libxml2/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)
project(test_package LANGUAGES C)

find_package(libxml2 CONFIG REQUIRED)
find_package(libxml2 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} LibXml2::LibXml2)
target_link_libraries(${PROJECT_NAME} PRIVATE LibXml2::LibXml2)
18 changes: 0 additions & 18 deletions recipes/libxml2/all/test_v1_cmake_module_package/CMakeLists.txt

This file was deleted.

8 changes: 8 additions & 0 deletions recipes/libxml2/all/test_v1_module_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_module_package
${CMAKE_CURRENT_BINARY_DIR}/test_module_package)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ def build(self):
def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
xml_path = os.path.join(self.source_folder, "..", "test_package", "books.xml")
bin_arg_path = "%s %s" % (bin_path, xml_path)
self.run(bin_arg_path, run_environment=True)
xml_path = os.path.join(self.source_folder, os.pardir, "test_package", "books.xml")
self.run(f"{bin_path} {xml_path}", run_environment=True)
15 changes: 3 additions & 12 deletions recipes/libxml2/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)
project(test_package)

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

find_package(LibXml2 REQUIRED)
message("LIBXML2_FOUND: ${LIBXML2_FOUND}")
message("LIBXML2_INCLUDE_DIR: ${LIBXML2_INCLUDE_DIR}")
message("LIBXML2_INCLUDE_DIRS: ${LIBXML2_INCLUDE_DIRS}")
message("LIBXML2_LIBRARIES: ${LIBXML2_LIBRARIES}")
message("LIBXML2_LIBRARY: ${LIBXML2_LIBRARY}")
message("LIBXML2_DEFINITIONS: ${LIBXML2_DEFINITIONS}")
message("LIBXML2_VERSION_STRING: ${LIBXML2_VERSION_STRING}")

add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} LibXml2::LibXml2)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
9 changes: 4 additions & 5 deletions recipes/libxml2/all/test_v1_package/conanfile.py
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", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
Expand All @@ -14,6 +14,5 @@ def build(self):
def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
xml_path = os.path.join(self.source_folder, "..", "test_package", "books.xml")
bin_arg_path = "%s %s" % (bin_path, xml_path)
self.run(bin_arg_path, run_environment=True)
xml_path = os.path.join(self.source_folder, os.pardir, "test_package", "books.xml")
self.run(f"{bin_path} {xml_path}", run_environment=True)

0 comments on commit e72e91e

Please sign in to comment.