New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New modernized recipes for zlib and bzip2 #6474
Changes from all commits
058cb1f
beb9ab4
af53122
6c8eb21
d114fab
2a533f0
e700c5e
a428c69
594f74e
e84b92a
90bad33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,8 +1,10 @@ | ||||||
import os | ||||||
import textwrap | ||||||
from conans import ConanFile, CMake, tools | ||||||
from conans import ConanFile, tools | ||||||
from conan.tools.cmake import CMake, CMakeToolchain | ||||||
from conan.tools.layout import cmake_layout | ||||||
|
||||||
required_conan_version = ">=1.33.0" | ||||||
required_conan_version = ">=1.38.0" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First, we need to update the CI. I think we are running 1.37.2 |
||||||
|
||||||
|
||||||
class Bzip2Conan(ConanFile): | ||||||
|
@@ -11,7 +13,7 @@ class Bzip2Conan(ConanFile): | |||||
homepage = "http://www.bzip.org" | ||||||
license = "bzip2-1.0.8" | ||||||
description = "bzip2 is a free and open-source file compression program that uses the Burrows Wheeler algorithm." | ||||||
topics = ("conan", "bzip2", "data-compressor", "file-compression") | ||||||
topics = ("bzip2", "data-compressor", "file-compression") | ||||||
|
||||||
settings = "os", "compiler", "arch", "build_type" | ||||||
options = { | ||||||
|
@@ -26,12 +28,6 @@ class Bzip2Conan(ConanFile): | |||||
} | ||||||
|
||||||
exports_sources = ["CMakeLists.txt", "patches/**"] | ||||||
generators = "cmake" | ||||||
_cmake = None | ||||||
|
||||||
@property | ||||||
def _source_subfolder(self): | ||||||
return "source_subfolder" | ||||||
|
||||||
def config_options(self): | ||||||
if self.settings.os == "Windows": | ||||||
|
@@ -45,27 +41,32 @@ def configure(self): | |||||
del self.settings.compiler.cppstd | ||||||
|
||||||
def source(self): | ||||||
tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) | ||||||
|
||||||
def _configure_cmake(self): | ||||||
if self._cmake: | ||||||
return self._cmake | ||||||
self._cmake = CMake(self) | ||||||
self._cmake.definitions["BZ2_VERSION_STRING"] = self.version | ||||||
self._cmake.definitions["BZ2_VERSION_MAJOR"] = tools.Version(self.version).major | ||||||
self._cmake.definitions["BZ2_BUILD_EXE"] = self.options.build_executable | ||||||
self._cmake.configure() | ||||||
return self._cmake | ||||||
tools.get(**self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) | ||||||
# FIXME: this is failing after the export export to "src" in local folder | ||||||
try: | ||||||
os.rename("CMakeLists.txt", "src/CMakeLists.txt") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Is it capable of moving files ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but only when the target directory is already created. |
||||||
except: | ||||||
pass | ||||||
|
||||||
def layout(self): | ||||||
cmake_layout(self) | ||||||
|
||||||
def generate(self): | ||||||
cmake_toolchain = CMakeToolchain(self) | ||||||
cmake_toolchain.variables["BZ2_VERSION_STRING"] = self.version | ||||||
cmake_toolchain.variables["BZ2_VERSION_MAJOR"] = tools.Version(self.version).major | ||||||
cmake_toolchain.variables["BZ2_BUILD_EXE"] = self.options.build_executable | ||||||
cmake_toolchain.generate() | ||||||
|
||||||
def build(self): | ||||||
for patch in self.conan_data.get("patches", {}).get(self.version, []): | ||||||
tools.patch(**patch) | ||||||
cmake = self._configure_cmake() | ||||||
tools.files.apply_conandata_patches(self) | ||||||
cmake = CMake(self) | ||||||
cmake.configure() | ||||||
cmake.build() | ||||||
|
||||||
def package(self): | ||||||
self.copy("LICENSE", dst="licenses", src=self._source_subfolder) | ||||||
cmake = self._configure_cmake() | ||||||
self.copy("LICENSE", dst="licenses") | ||||||
cmake = CMake(self) | ||||||
cmake.install() | ||||||
self._create_cmake_module_variables( | ||||||
os.path.join(self.package_folder, self._module_subfolder, self._module_file) | ||||||
|
@@ -100,13 +101,8 @@ def _module_file(self): | |||||
return "conan-official-{}-variables.cmake".format(self.name) | ||||||
|
||||||
def package_info(self): | ||||||
self.cpp_info.names["cmake_find_package"] = "BZip2" | ||||||
self.cpp_info.names["cmake_find_package_multi"] = "BZip2" | ||||||
self.cpp_info.builddirs.append(self._module_subfolder) | ||||||
self.cpp_info.build_modules["cmake_find_package"] = [os.path.join(self._module_subfolder, self._module_file)] | ||||||
self.cpp_info.libs = ["bz2"] | ||||||
|
||||||
if self.options.build_executable: | ||||||
bin_path = os.path.join(self.package_folder, "bin") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got appending the path implicit somehow? If yes, through what? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We expect the consumers to use the |
||||||
self.output.info("Appending PATH environment variable: {}".format(bin_path)) | ||||||
self.env_info.PATH.append(bin_path) | ||||||
self.cpp_info.set_property("cmake_file_name", "BZip2") | ||||||
self.cpp_info.set_property("cmake_target_name", "BZip2") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
import os | ||
from conans import ConanFile, CMake, tools | ||
from conans import ConanFile, tools | ||
from conan.tools.cmake import CMake | ||
from conan.tools.layout import cmake_layout | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "arch", "build_type" | ||
generators = "cmake", "cmake_find_package" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def configure(self): | ||
del self.settings.compiler.libcxx | ||
|
||
def layout(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems to be unused (e.g. never called), it is needed? if so, why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reading about feature, I don't get why is it needed for test package?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not "needed" but nice to use always the same layout, more clear, and easy to explore the build files in case you need. |
||
cmake_layout(self) | ||
|
||
def test(self): | ||
if not tools.cross_building(self.settings): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run("%s --help" % bin_path, run_environment=True) | ||
cmd = os.path.join(self.cpp.build.bindirs[0], "test_package") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if it's safe, e.g. if bindirs is an empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a bindir of the current package. As you are declaring the layout(), you know there is always a bindir. Actually were always a bindir unless you remove it from the cppinfo. |
||
self.run("%s --help" % cmd, env=["conanrunenv"]) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import os | ||
from conans import ConanFile, tools, CMake | ||
from conans import ConanFile, tools | ||
from conan.tools.cmake import CMake | ||
from conan.tools.layout import cmake_layout | ||
from conans.errors import ConanException | ||
|
||
|
||
|
@@ -14,17 +16,9 @@ class ZlibConan(ConanFile): | |
settings = "os", "arch", "compiler", "build_type" | ||
options = {"shared": [True, False], "fPIC": [True, False], "minizip": [True, False, "deprecated"]} | ||
default_options = {"shared": False, "fPIC": True, "minizip": "deprecated"} | ||
exports_sources = ["CMakeLists.txt", "CMakeLists_minizip.txt", "patches/**"] | ||
generators = "cmake" | ||
topics = ("conan", "zlib", "compression") | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
|
||
@property | ||
def _build_subfolder(self): | ||
return "build_subfolder" | ||
exports_sources = ["patches/**"] | ||
generators = "CMakeToolchain", "CMakeDeps" | ||
topics = ("zlib", "compression") | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
|
@@ -44,13 +38,14 @@ def package_id(self): | |
del self.info.options.minizip | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) | ||
tools.get(**self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) | ||
|
||
def _patch_sources(self): | ||
for patch in self.conan_data["patches"][self.version]: | ||
tools.patch(**patch) | ||
with tools.chdir(".."): # FIXME: This need to go to parent folder is not very nice. | ||
for patch in self.conan_data["patches"][self.version]: | ||
tools.patch(**patch, base_path=self.source_folder) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See conan-io/conan#9361 |
||
|
||
with tools.chdir(self._source_subfolder): | ||
with tools.chdir(self.source_folder): | ||
# https://github.com/madler/zlib/issues/268 | ||
tools.replace_in_file('gzguts.h', | ||
'#if defined(_WIN32) || defined(__CYGWIN__)', | ||
|
@@ -60,19 +55,22 @@ def _patch_sources(self): | |
if not is_apple_clang12: | ||
for filename in ['zconf.h', 'zconf.h.cmakein', 'zconf.h.in']: | ||
tools.replace_in_file(filename, | ||
'#ifdef HAVE_UNISTD_H ' | ||
'/* may be set to #if 1 by ./configure */', | ||
'#if defined(HAVE_UNISTD_H) && (1-HAVE_UNISTD_H-1 != 0)') | ||
'#ifdef HAVE_UNISTD_H ' | ||
'/* may be set to #if 1 by ./configure */', | ||
'#if defined(HAVE_UNISTD_H) && (1-HAVE_UNISTD_H-1 != 0)') | ||
tools.replace_in_file(filename, | ||
'#ifdef HAVE_STDARG_H ' | ||
'/* may be set to #if 1 by ./configure */', | ||
'#if defined(HAVE_STDARG_H) && (1-HAVE_STDARG_H-1 != 0)') | ||
'#ifdef HAVE_STDARG_H ' | ||
'/* may be set to #if 1 by ./configure */', | ||
'#if defined(HAVE_STDARG_H) && (1-HAVE_STDARG_H-1 != 0)') | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
self._patch_sources() | ||
make_target = "zlib" if self.options.shared else "zlibstatic" | ||
cmake = CMake(self) | ||
cmake.configure(build_folder=self._build_subfolder) | ||
cmake.configure() | ||
cmake.build(target=make_target) | ||
|
||
def _rename_libraries(self): | ||
|
@@ -97,33 +95,33 @@ def _rename_libraries(self): | |
tools.rename(current_lib, os.path.join(lib_path, "zlib.lib")) | ||
|
||
def _extract_license(self): | ||
with tools.chdir(os.path.join(self.source_folder, self._source_subfolder)): | ||
with tools.chdir(self.source_folder): | ||
tmp = tools.load("zlib.h") | ||
license_contents = tmp[2:tmp.find("*/", 1)] | ||
tools.save("LICENSE", license_contents) | ||
|
||
def package(self): | ||
self._extract_license() | ||
self.copy("LICENSE", src=self._source_subfolder, dst="licenses") | ||
self.copy("LICENSE", dst="licenses") | ||
|
||
# Copy headers | ||
for header in ["*zlib.h", "*zconf.h"]: | ||
self.copy(pattern=header, dst="include", src=self._source_subfolder, keep_path=False) | ||
self.copy(pattern=header, dst="include", src=self._build_subfolder, keep_path=False) | ||
self.copy(pattern=header, dst="include", keep_path=False) | ||
self.copy(pattern=header, dst="include", keep_path=False) | ||
|
||
# Copying static and dynamic libs | ||
if self.options.shared: | ||
self.copy(pattern="*.dylib*", dst="lib", src=self._build_subfolder, keep_path=False, symlinks=True) | ||
self.copy(pattern="*.so*", dst="lib", src=self._build_subfolder, keep_path=False, symlinks=True) | ||
self.copy(pattern="*.dll", dst="bin", src=self._build_subfolder, keep_path=False) | ||
self.copy(pattern="*.dll.a", dst="lib", src=self._build_subfolder, keep_path=False) | ||
self.copy(pattern="*.dylib*", dst="lib", keep_path=False, symlinks=True) | ||
self.copy(pattern="*.so*", dst="lib", keep_path=False, symlinks=True) | ||
self.copy(pattern="*.dll", dst="bin", keep_path=False) | ||
self.copy(pattern="*.dll.a", dst="lib", keep_path=False) | ||
else: | ||
self.copy(pattern="*.a", dst="lib", src=self._build_subfolder, keep_path=False) | ||
self.copy(pattern="*.lib", dst="lib", src=self._build_subfolder, keep_path=False) | ||
self.copy(pattern="*.a", dst="lib", keep_path=False) | ||
self.copy(pattern="*.lib", dst="lib", keep_path=False) | ||
|
||
self._rename_libraries() | ||
|
||
def package_info(self): | ||
self.cpp_info.libs.append("zlib" if self.settings.os == "Windows" and not self.settings.os.subsystem else "z") | ||
self.cpp_info.names["cmake_find_package"] = "ZLIB" | ||
self.cpp_info.names["cmake_find_package_multi"] = "ZLIB" | ||
self.cpp_info.set_property("cmake_file_name", "ZLIB") | ||
self.cpp_info.set_property("cmake_target_name", "ZLIB") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
project(test_package C) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
find_package(ZLIB REQUIRED) | ||
|
||
add_executable(test_zlib test.c) | ||
target_link_libraries(test_zlib CONAN_PKG::zlib) | ||
target_link_libraries(test_zlib ZLIB::ZLIB) | ||
set_target_properties(test_zlib PROPERTIES OUTPUT_NAME "test") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we start to try to replace all the
tools.xxx
also? (in general all the conans imports)