Skip to content

Commit

Permalink
libplist: Add new recipe (#26091)
Browse files Browse the repository at this point in the history
* Add libplist 2.6.0

* Cleanups, add missing m system lib

* Cleanup

* Cleanups

* unused

* Add C++ component

* Cleanup
  • Loading branch information
AbrilRBS authored Dec 3, 2024
1 parent cceee56 commit 45cea81
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/libplist/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"2.6.0":
url: "https://github.com/libimobiledevice/libplist/releases/download/2.6.0/libplist-2.6.0.tar.bz2"
sha256: "67be9ee3169366589c92dc7c22809b90f51911dd9de22520c39c9a64fb047c9c"
95 changes: 95 additions & 0 deletions recipes/libplist/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.build import cross_building
from conan.tools.env import VirtualRunEnv
from conan.tools.files import copy, get, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
import os

required_conan_version = ">=2.1"

class PackageConan(ConanFile):
name = "libplist"
description = "A small portable C library to handle Apple Property List files in binary, XML, JSON, or OpenStep format."
license = "LGPL-2.1"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/libimobiledevice/libplist"
topics = ("plist", "apple", "property list", "binary", "xml", "json", "openstep")

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

implements = ["auto_shared_fpic"]
languages = ["C", "C++"]

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

def validate(self):
if self.settings.compiler == "msvc":
raise ConanInvalidConfiguration("libplist does not support MSVC - use MinGW instead")

def build_requirements(self):
self.tool_requires("libtool/2.4.7")
if self.settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")

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

def generate(self):
if not cross_building(self):
VirtualRunEnv(self).generate(scope="build")
tc = AutotoolsToolchain(self)

tc.configure_args.extend([
# No need for python bindings
"--without-cython",
])
tc.generate()

def build(self):
autotools = Autotools(self)
autotools.configure()
autotools.make()

def package(self):
copy(self, "COPYING.LESSER", self.source_folder, os.path.join(self.package_folder, "licenses"))
autotools = Autotools(self)
autotools.install()

rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))

fix_apple_shared_install_name(self)

def package_info(self):
self.cpp_info.components["plist"].libs = ["plist-2.0"]
self.cpp_info.components["plist"].set_property("pkg_config_name", "plist-2.0")
self.cpp_info.components["plist"].set_property("cmake_target_name", "libplist::libplist")

self.cpp_info.components["plist++"].libs = ["plist++-2.0"]
self.cpp_info.components["plist++"].requires = ["plist"]
self.cpp_info.components["plist++"].set_property("pkg_config_name", "plist++-2.0")
self.cpp_info.components["plist++"].set_property("cmake_target_name", "libplist::libplist++")

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["plist"].system_libs.extend(["m", "pthread"])
self.cpp_info.components["plist++"].system_libs.extend(["m", "pthread"])

if not self.options.shared:
self.cpp_info.components["plist"].defines.append("LIBPLIST_STATIC")
self.cpp_info.components["plist++"].defines.append("LIBPLIST_STATIC")
10 changes: 10 additions & 0 deletions recipes/libplist/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C CXX)

find_package(libplist REQUIRED CONFIG)

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

add_executable(${PROJECT_NAME}++ test_package.cpp)
target_link_libraries(${PROJECT_NAME}++ PRIVATE libplist::libplist++)
28 changes: 28 additions & 0 deletions recipes/libplist/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

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

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")

bin_path_cxx = os.path.join(self.cpp.build.bindir, "test_package++")
self.run(bin_path_cxx, env="conanrun")
10 changes: 10 additions & 0 deletions recipes/libplist/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdlib.h>
#include <stdio.h>
#include <plist/plist.h>


int main(void) {
printf("plist version: %s\n", libplist_version());

return EXIT_SUCCESS;
}
11 changes: 11 additions & 0 deletions recipes/libplist/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdlib.h>
#include <stdio.h>
#include <plist/plist++.h>


int main(void) {
auto node = new PList::Boolean(true);
printf("node value: %d\n", node->GetValue());

return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/libplist/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.6.0":
folder: all

0 comments on commit 45cea81

Please sign in to comment.