From 3198fb76f2940e350b0ba06eab471116830f53db Mon Sep 17 00:00:00 2001 From: Guillaume Egles <gegles@us.ibm.com> Date: Thu, 27 Apr 2023 10:01:01 -0700 Subject: [PATCH] yajl: initial onboarding (v2.1.0) --- recipes/yajl/all/conandata.yml | 4 + recipes/yajl/all/conanfile.py | 88 +++++++++++++++++++ recipes/yajl/all/test_package/CMakeLists.txt | 8 ++ recipes/yajl/all/test_package/conanfile.py | 26 ++++++ recipes/yajl/all/test_package/test_package.c | 19 ++++ .../yajl/all/test_v1_package/CMakeLists.txt | 8 ++ recipes/yajl/all/test_v1_package/conanfile.py | 19 ++++ recipes/yajl/config.yml | 3 + 8 files changed, 175 insertions(+) create mode 100644 recipes/yajl/all/conandata.yml create mode 100644 recipes/yajl/all/conanfile.py create mode 100644 recipes/yajl/all/test_package/CMakeLists.txt create mode 100644 recipes/yajl/all/test_package/conanfile.py create mode 100644 recipes/yajl/all/test_package/test_package.c create mode 100644 recipes/yajl/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/yajl/all/test_v1_package/conanfile.py create mode 100644 recipes/yajl/config.yml diff --git a/recipes/yajl/all/conandata.yml b/recipes/yajl/all/conandata.yml new file mode 100644 index 00000000000000..21b18ea006ef3d --- /dev/null +++ b/recipes/yajl/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "2.1.0": + url: "https://github.com/lloyd/yajl/archive/refs/tags/2.1.0.tar.gz" + sha256: "3fb73364a5a30efe615046d07e6db9d09fd2b41c763c5f7d3bfb121cd5c5ac5a" diff --git a/recipes/yajl/all/conanfile.py b/recipes/yajl/all/conanfile.py new file mode 100644 index 00000000000000..f1addb8f44dd2c --- /dev/null +++ b/recipes/yajl/all/conanfile.py @@ -0,0 +1,88 @@ +from conan import ConanFile +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir, rm, rename +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +import os + +required_conan_version = ">=1.53.0" + + +class YAJLConan(ConanFile): + name = "yajl" + description = "A fast streaming JSON parsing library in C" + license = "ISC" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/lloyd/yajl" + topics = ("json", "encoding", "decoding", "manipulation") + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + + def export_sources(self): + export_conandata_patches(self) + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + self.settings.rm_safe("compiler.libcxx") + self.settings.rm_safe("compiler.cppstd") + + def layout(self): + cmake_layout(self, src_folder="src") + + def source(self): + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.generate() + + def build(self): + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, pattern="COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) + cmake.install() + + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "share")) + rm(self, "*.la", os.path.join(self.package_folder, "lib")) + rm(self, "*.pdb", os.path.join(self.package_folder, "lib")) + rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) + + # We need to move the dll from lib to bin in order for it to be found later + if self.settings.os == "Windows": + rename(self, os.path.join(self.package_folder, "lib", "yajl.dll"), os.path.join(self.package_folder, "bin", "yajl.dll")) + + def package_info(self): + self.cpp_info.libs = ["yajl"] + + self.cpp_info.set_property("cmake_file_name", "yajl") + self.cpp_info.set_property("cmake_target_name", "yajl::yajl") + self.cpp_info.set_property("pkg_config_name", "yajl") + + if self.options.shared: + self.cpp_info.libs = ["yajl"] + else: + self.cpp_info.libs = ["yajl_s"] + + # TODO: to remove in conan v2 once cmake_find_package_* generators removed + self.cpp_info.filenames["cmake_find_package"] = "YAJL" + self.cpp_info.filenames["cmake_find_package_multi"] = "yajl" + self.cpp_info.names["cmake_find_package"] = "YAJL" + self.cpp_info.names["cmake_find_package_multi"] = "yajl" diff --git a/recipes/yajl/all/test_package/CMakeLists.txt b/recipes/yajl/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..c1ab399f3fa7cc --- /dev/null +++ b/recipes/yajl/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) + +project(test_package C) + +find_package(yajl REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE yajl::yajl) diff --git a/recipes/yajl/all/test_package/conanfile.py b/recipes/yajl/all/test_package/conanfile.py new file mode 100644 index 00000000000000..ef5d7042163ecc --- /dev/null +++ b/recipes/yajl/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +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", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) + + 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") diff --git a/recipes/yajl/all/test_package/test_package.c b/recipes/yajl/all/test_package/test_package.c new file mode 100644 index 00000000000000..9a2af8a9d49967 --- /dev/null +++ b/recipes/yajl/all/test_package/test_package.c @@ -0,0 +1,19 @@ +#include <yajl/yajl_gen.h> +#include <yajl/yajl_version.h> +#include <stdio.h> +#include <stdlib.h> + +#define CHK(x) if (x != yajl_gen_status_ok) return 1; + +int main(void) { + printf("Welcome to YAJL v%d.%d.%d!", YAJL_MAJOR, YAJL_MINOR, YAJL_MICRO); + yajl_gen yg; + yajl_gen_status s; + + yg = yajl_gen_alloc(NULL); + CHK(yajl_gen_map_open(yg)); + CHK(yajl_gen_map_close(yg)); + s = yajl_gen_map_close(yg); + + return yajl_gen_generation_complete == s ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/recipes/yajl/all/test_v1_package/CMakeLists.txt b/recipes/yajl/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..91630d79f4abb3 --- /dev/null +++ b/recipes/yajl/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +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/) diff --git a/recipes/yajl/all/test_v1_package/conanfile.py b/recipes/yajl/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..c492184eec19c2 --- /dev/null +++ b/recipes/yajl/all/test_v1_package/conanfile.py @@ -0,0 +1,19 @@ +from conans import ConanFile, CMake +from conan.tools.build import cross_building +import os + + +# legacy validation with Conan 1.x +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) diff --git a/recipes/yajl/config.yml b/recipes/yajl/config.yml new file mode 100644 index 00000000000000..dfff490f9a9b60 --- /dev/null +++ b/recipes/yajl/config.yml @@ -0,0 +1,3 @@ +versions: + "2.1.0": + folder: all