Skip to content

Commit

Permalink
Merge pull request #1 from uilianries/port-zbar-conan2
Browse files Browse the repository at this point in the history
  • Loading branch information
jdoubleu authored May 9, 2023
2 parents 89ade7e + 3296490 commit f8088d0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 38 deletions.
68 changes: 30 additions & 38 deletions recipes/zbar/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from conan.tools.build import cross_building
from conan.tools.files import get, copy, rmdir, rm, collect_libs
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.env import Environment
from conan.tools.scm import Version
from conan.tools.layout import basic_layout

import os

required_conan_version = ">=1.53.0"
Expand Down Expand Up @@ -48,12 +51,6 @@ class ZbarConan(ConanFile):
"enable_pthread": True,
}

_autotools = None

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

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand All @@ -62,6 +59,9 @@ def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

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

def requirements(self):
if self.options.with_jpeg:
self.requires("libjpeg/9d")
Expand Down Expand Up @@ -90,54 +90,46 @@ def validate(self):
if self.options.with_xv: #TODO add when available
self.output.warn("There is no Xvideo package available on Conan (yet). This recipe will use the one present on the system (if available).")
if Version(self.version) >= "0.22" and cross_building(self):
raise ConanInvalidConfiguration("{} can't be built on cross building environment currently because autopoint(part of gettext) doesn't execute correctly.".format(self.name))
raise ConanInvalidConfiguration(f"{self.ref} can't be built on cross building environment currently because autopoint(part of gettext) doesn't execute correctly.")

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

def generate(self):
yes_no = lambda v: "yes" if v else "no"
tc = AutotoolsToolchain(self)
tc.configure_args.extend([
f"--enable-video={yes_no(self.options.with_video)}",
f"--with-imagemagick={yes_no(self.options.with_imagemagick)}",
f"--with-gtk={yes_no(self.options.with_gtk)}",
f"--with-qt={yes_no(self.options.with_qt)}",
f"--with-python={yes_no(self.options.with_python_bindings)}",
f"--with-x={yes_no(self.options.with_x)}",
f"--with-xshm={yes_no(self.options.with_xshm)}",
f"--with-xv={yes_no(self.options.with_xv)}",
f"--with-jpeg={yes_no(self.options.with_jpeg)}",
f"--enable-pthread={yes_no(self.options.enable_pthread)}",
])
tc.generate()
if self.settings.os == "Macos" and self.settings.arch == "armv8":
# ./libtool: eval: line 961: syntax error near unexpected token `|'
env = Environment()
env.define("NM", "nm")
env.vars(self).save_script("conanbuild_macos_nm")

def _configure_autotools(self):
if not self._autotools:
self._autotools = Autotools(self)
if Version(self.version) >= "0.22":
self._autotools.autoreconf(args=['--verbose'])
yes_no = lambda v: "yes" if v else "no"
args = [
"--enable-shared={}".format(yes_no(self.options.shared)),
"--enable-static={}".format(yes_no(not self.options.shared)),
"--enable-video={}".format(yes_no(self.options.with_video)),
"--with-imagemagick={}".format(yes_no(self.options.with_imagemagick)),
"--with-gtk={}".format(yes_no(self.options.with_gtk)),
"--with-qt={}".format(yes_no(self.options.with_qt)),
"--with-python={}".format(yes_no(self.options.with_python_bindings)),
"--with-x={}".format(yes_no(self.options.with_x)),
"--with-xshm={}".format(yes_no(self.options.with_xshm)),
"--with-xv={}".format(yes_no(self.options.with_xv)),
"--with-jpeg={}".format(yes_no(self.options.with_jpeg)),
"--enable-pthread={}".format(yes_no(self.options.enable_pthread)),
]
if self.settings.os == "Macos" and self.settings.arch == "armv8":
# ./libtool: eval: line 961: syntax error near unexpected token `|'
args.append("NM=nm")
self._autotools.configure(args=args)
return self._autotools

def build(self):
copy(self, "config.sub", src=self.source_folder, dst=os.path.join(self.source_folder, "config"))
copy(self, "config.guess", src=self.source_folder, dst=os.path.join(self.source_folder, "config"))

autotools = self._configure_autotools()
autotools = Autotools(self)
autotools.autoreconf()
autotools.configure()
autotools.make()

def package(self):
if Version(self.version) < "0.23":
copy(self, "LICENSE", src=self.source_folder, dst="licenses")
else:
copy(self, "LICENSE.md", src=self.source_folder, dst="licenses")
autotools = self._configure_autotools()
copy(self, "LICENSE*", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
autotools = Autotools(self)
autotools.install()
rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
Expand Down
8 changes: 8 additions & 0 deletions recipes/zbar/all/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/)
18 changes: 18 additions & 0 deletions recipes/zbar/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


class TestPackageV1Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

0 comments on commit f8088d0

Please sign in to comment.