Skip to content

Commit

Permalink
modernize
Browse files Browse the repository at this point in the history
- CMakeDeps & PkgConfigDeps support
- fix pkgconfig name
- handle other major versions than Qt5 in package_info()
- explicit cpp_info.libs
- cache CMake configuration with functools.lru_cache
- use cmake_find_package_multi in test package
- relocatable shared lib on macOS
  • Loading branch information
SpaceIm committed May 1, 2022
1 parent 9e5913b commit e035e3a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 31 deletions.
2 changes: 1 addition & 1 deletion recipes/quazip/all/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(KEEP_RPATHS)

add_subdirectory("source_subfolder")
62 changes: 40 additions & 22 deletions recipes/quazip/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
from conans import ConanFile, CMake, tools
import functools
import os

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.43.0"


class QuaZIPConan(ConanFile):
name = "quazip"
description = "A simple C++ wrapper over Gilles Vollant's ZIP/UNZIP package\
that can be used to access ZIP archives."
description = (
"A simple C++ wrapper over Gilles Vollant's ZIP/UNZIP package "
"that can be used to access ZIP archives."
)
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/stachenov/quazip"
license = "LGPL-2.1-linking-exception"
topics = ("conan", "zip", "unzip", "compress")
exports_sources = ["CMakeLists.txt", "patches/*"]
generators = "cmake", "cmake_find_package"
topics = ("zip", "unzip", "compress")

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

exports_sources = "CMakeLists.txt"
generators = "cmake", "cmake_find_package"

@property
def _source_subfolder(self):
Expand All @@ -26,10 +37,6 @@ def _source_subfolder(self):
def _build_subfolder(self):
return "build_subfolder"

def requirements(self):
self.requires("zlib/1.2.12")
self.requires("qt/5.15.3")

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand All @@ -38,16 +45,19 @@ def configure(self):
if self.options.shared:
del self.options.fPIC

def requirements(self):
self.requires("zlib/1.2.12")
self.requires("qt/5.15.3")

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

@functools.lru_cache(1)
def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure()
return self._cmake
cmake = CMake(self)
cmake.configure()
return cmake

def build(self):
cmake = self._configure_cmake()
Expand All @@ -61,12 +71,20 @@ def package(self):
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.includedirs=[os.path.join('include', 'QuaZip-Qt5-{}'.format(self.version))]
quazip_major = tools.Version(self.version).major
qt_major = tools.Version(self.deps_cpp_info["qt"].version).major
self.cpp_info.set_property("cmake_file_name", f"QuaZip-Qt{qt_major}")
self.cpp_info.set_property("cmake_target_name", "QuaZip::QuaZip")
self.cpp_info.set_property("pkg_config_name", f"quazip{quazip_major}-qt{qt_major}")
suffix = "d" if self.settings.build_type == "Debug" else ""
self.cpp_info.libs = [f"quazip{quazip_major}-qt{qt_major}{suffix}"]
self.cpp_info.includedirs = [os.path.join("include", f"QuaZip-Qt{qt_major}-{self.version}")]
if not self.options.shared:
self.cpp_info.defines.append("QUAZIP_STATIC")

self.cpp_info.filenames["cmake_find_package"] = "QuaZip-Qt5"
self.cpp_info.filenames["cmake_find_package_multi"] = "QuaZip-Qt5"
# TODO: to remove in conan v2 once cmake_find_package_* & pkg_config generators removed
self.cpp_info.filenames["cmake_find_package"] = f"QuaZip-Qt{qt_major}"
self.cpp_info.filenames["cmake_find_package_multi"] = f"QuaZip-Qt{qt_major}"
self.cpp_info.names["cmake_find_package"] = "QuaZip"
self.cpp_info.names["cmake_find_package_multi"] = "QuaZip"
self.cpp_info.names["pkg_config"] = f"quazip{quazip_major}-qt{qt_major}"
8 changes: 4 additions & 4 deletions recipes/quazip/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ cmake_minimum_required(VERSION 3.1)
project(test_package)

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

add_executable(${PROJECT_NAME} test_package.cpp)
find_package(QuaZip-Qt${QT_VERSION_MAJOR} REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)

target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} QuaZip::QuaZip)
# Must compile with "-fPIC" since Qt was built with -reduce-relocations.
target_compile_options(${PROJECT_NAME} PRIVATE -fPIC)
9 changes: 5 additions & 4 deletions recipes/quazip/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@


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)
cmake.definitions["QT_VERSION_MAJOR"] = tools.Version(self.deps_cpp_info["qt"].version).major
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
zipFile_path = os.path.abspath(os.path.join(__file__, "..","zipFile.zip"))
if not tools.cross_building(self):
zipFile_path = os.path.join(self.source_folder, "zipFile.zip")
bin_path = os.path.join("bin", "test_package")
self.run(bin_path + " " + zipFile_path, run_environment=True)

0 comments on commit e035e3a

Please sign in to comment.