Skip to content
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

tpl: add a new recipe #20966

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions recipes/tpl/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.15)
project(tpl LANGUAGES C)

add_library(tpl src/tpl.c)
set_target_properties(tpl PROPERTIES
VERSION 0.0.0
SOVERSION 0
)

if(WIN32)
target_sources(tpl PRIVATE src/win/mmap.c)
install(FILES src/win/mman.h DESTINATION include/win)
if(BUILD_SHARED_LIBS)
target_compile_definitions(tpl PRIVATE TPL_EXPORTS)
else()
target_compile_definitions(tpl PUBLIC TPL_NOLIB)
endif()
endif()

install(TARGETS tpl
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
install(FILES src/tpl.h DESTINATION include)
4 changes: 4 additions & 0 deletions recipes/tpl/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"cci.20210302":
url: "https://github.com/troydhanson/tpl/archive/f8138ad393f4b1985c916029ab6d703e4e7a1c4c.tar.gz"
sha256: "736dcd98bc92178a9cfaeaf8d7f9a67aa49c5ee36b9f76286e055a8a97b640dd"
70 changes: 70 additions & 0 deletions recipes/tpl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake
from conan.tools.files import copy, get
from conan.tools.layout import basic_layout

required_conan_version = ">=1.54.0"


class PackageConan(ConanFile):
name = "tpl"
description = "A small binary serialization library for C"
license = "BSD-1-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://troydhanson.github.io/tpl/"
topics = ("serialization",)

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):
copy(self, "CMakeLists.txt", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

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.cppstd")
self.settings.rm_safe("compiler.libcxx")

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

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

def generate(self):
tc = CMakeToolchain(self)
tc.generate()

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

def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["tpl"]
if self.settings.os == "Windows" and not self.options.shared:
self.cpp_info.defines.append("TPL_NOLIB")
7 changes: 7 additions & 0 deletions recipes/tpl/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)

find_package(tpl REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE tpl::tpl)
26 changes: 26 additions & 0 deletions recipes/tpl/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 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")
47 changes: 47 additions & 0 deletions recipes/tpl/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// https://github.com/troydhanson/tpl/blob/f8138ad393f4b1985c916029ab6d703e4e7a1c4c/tests/test1.c
//
// Copyright (c) 2005-2013, Troy Hanson http://troydhanson.github.com/tpl/
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <stdio.h>
#include <stdlib.h>
#include "tpl.h"

int main() {
tpl_node *tn;
int i,j=-1;
void *addr;
size_t sz;

tn = tpl_map("i",&i);
i=1;
tpl_pack(tn,0);
tpl_dump(tn,TPL_MEM,&addr,&sz);
tpl_free(tn);

tn = tpl_map("i",&j);
tpl_load(tn,TPL_MEM,addr,sz);
tpl_unpack(tn,0);
printf("j is %d\n", j);
tpl_free(tn);
free(addr);
return(0);
}
3 changes: 3 additions & 0 deletions recipes/tpl/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20210302":
folder: all
Loading