Skip to content

Commit

Permalink
yajl: initial onboarding (v2.1.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
gegles committed Apr 30, 2023
1 parent 52bf677 commit 3198fb7
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/yajl/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"2.1.0":
url: "https://github.com/lloyd/yajl/archive/refs/tags/2.1.0.tar.gz"
sha256: "3fb73364a5a30efe615046d07e6db9d09fd2b41c763c5f7d3bfb121cd5c5ac5a"
88 changes: 88 additions & 0 deletions recipes/yajl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 8 additions & 0 deletions recipes/yajl/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions recipes/yajl/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
19 changes: 19 additions & 0 deletions recipes/yajl/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 8 additions & 0 deletions recipes/yajl/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.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/)
19 changes: 19 additions & 0 deletions recipes/yajl/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions recipes/yajl/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.1.0":
folder: all

0 comments on commit 3198fb7

Please sign in to comment.