Skip to content

Commit

Permalink
libxml2: create FindLibXml2.cmake package (cmake spec)
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr committed Aug 29, 2020
1 parent e00c80f commit 42191a9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
47 changes: 32 additions & 15 deletions recipes/libxml2/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def build_requirements(self):
@property
def _is_msvc(self):
return self.settings.compiler == "Visual Studio"

@property
def _is_mingw(self):
return self.settings.compiler == "gcc" and self.settings.os == "Windows"
Expand Down Expand Up @@ -245,25 +245,42 @@ def package(self):

def package_info(self):
if self._is_msvc:
self.cpp_info.libs = ["libxml2" if self.options.shared else "libxml2_a"]
self.cpp_info.components["xml2lib"].libs = ["libxml2" if self.options.shared else "libxml2_a"]
else:
self.cpp_info.libs = ["xml2"]
self.cpp_info.includedirs.append(os.path.join("include", "libxml2"))
self.cpp_info.components["xml2lib"].libs = ["xml2"]
self.cpp_info.components["xml2lib"].includedirs.append(os.path.join("include", "libxml2"))
if not self.options.shared:
self.cpp_info.defines = ["LIBXML_STATIC"]
if self.options.include_utils:
bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.env_info.PATH.append(bindir)
self.cpp_info.components["xml2lib"].defines = ["LIBXML_STATIC"]

if self.settings.os == "Linux" or self.settings.os == "Macos":
self.cpp_info.system_libs.append("m")
self.cpp_info.components["xml2lib"].system_libs.append("m")
if self.settings.os == "Windows":
self.cpp_info.system_libs.append("ws2_32")
self.cpp_info.components["xml2lib"].system_libs.append("ws2_32")
if self.options.threads:
if self.settings.os == "Linux":
self.cpp_info.system_libs.append("pthread")
self.cpp_info.components["xml2lib"].system_libs.append("pthread")

if self.options.zlib:
self.cpp_info.components["xml2lib"].requires.append("zlib::zlib")
if self.options.lzma:
self.cpp_info.components["xml2lib"].requires.append("xz_utils::xz_utils")
if self.options.iconv:
self.cpp_info.components["xml2lib"].requires.append("libiconv::libiconv")
if self.options.icu:
self.cpp_info.components["xml2lib"].requires.append("icu::icu")

self.cpp_info.components["xml2lib"].names["pkg_config"] = "libxml-2.0"
self.cpp_info.filenames["cmake_find_package"] = "LibXml2"
self.cpp_info.filenames["cmake_find_package_multi"] = "LibXml2"
self.cpp_info.names["cmake_find_package"] = "LibXml2"
self.cpp_info.names["cmake_find_package_multi"] = "LibXml2"
self.cpp_info.components["xml2lib"].names["cmake_find_package"] = "LibXml2"
self.cpp_info.components["xml2lib"].names["cmake_find_package_multi"] = "LibXml2"

# FIXME: libxml2 package itself creates libxml2-config.cmake file

self.cpp_info.names["pkg_config"] = "libxml-2.0"
self.cpp_info.filenames["cmake_find_package"] = "libxml2"
self.cpp_info.filenames["cmake_find_package_multi"] = "libxml2"
if self.options.include_utils:
bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.env_info.PATH.append(bindir)
# FIXME: cmake creates LibXml2::xmllint imported target for the xmllint executable
6 changes: 4 additions & 2 deletions recipes/libxml2/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.1)
project(test_package)

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

find_package(LibXml2 REQUIRED)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} LibXml2::LibXml2)
2 changes: 1 addition & 1 deletion recipes/libxml2/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
generators = "cmake", "cmake_find_package"

def build(self):
cmake = CMake(self)
Expand Down

0 comments on commit 42191a9

Please sign in to comment.