diff --git a/recipes/tpl/all/CMakeLists.txt b/recipes/tpl/all/CMakeLists.txt new file mode 100644 index 0000000000000..e64edb314afd5 --- /dev/null +++ b/recipes/tpl/all/CMakeLists.txt @@ -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) diff --git a/recipes/tpl/all/conandata.yml b/recipes/tpl/all/conandata.yml new file mode 100644 index 0000000000000..1d4730dd059e0 --- /dev/null +++ b/recipes/tpl/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "cci.20210302": + url: "https://github.com/troydhanson/tpl/archive/f8138ad393f4b1985c916029ab6d703e4e7a1c4c.tar.gz" + sha256: "736dcd98bc92178a9cfaeaf8d7f9a67aa49c5ee36b9f76286e055a8a97b640dd" diff --git a/recipes/tpl/all/conanfile.py b/recipes/tpl/all/conanfile.py new file mode 100644 index 0000000000000..c6de20abc1b3c --- /dev/null +++ b/recipes/tpl/all/conanfile.py @@ -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") diff --git a/recipes/tpl/all/test_package/CMakeLists.txt b/recipes/tpl/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..3c45a6297bb71 --- /dev/null +++ b/recipes/tpl/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/tpl/all/test_package/conanfile.py b/recipes/tpl/all/test_package/conanfile.py new file mode 100644 index 0000000000000..3a91c9439218e --- /dev/null +++ b/recipes/tpl/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 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") diff --git a/recipes/tpl/all/test_package/test_package.c b/recipes/tpl/all/test_package/test_package.c new file mode 100644 index 0000000000000..23f438ef7f269 --- /dev/null +++ b/recipes/tpl/all/test_package/test_package.c @@ -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 +#include +#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); +} diff --git a/recipes/tpl/config.yml b/recipes/tpl/config.yml new file mode 100644 index 0000000000000..a4bd9fea5a7a4 --- /dev/null +++ b/recipes/tpl/config.yml @@ -0,0 +1,3 @@ +versions: + "cci.20210302": + folder: all