From 2a4ac6dcb423217772f6e35981e0b1bb8d009dd2 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 7 Nov 2023 00:19:39 +0200 Subject: [PATCH 1/7] tpl: add recipe --- recipes/tpl/all/conandata.yml | 5 ++ recipes/tpl/all/conanfile.py | 93 +++++++++++++++++++++ recipes/tpl/all/test_package/CMakeLists.txt | 7 ++ recipes/tpl/all/test_package/conanfile.py | 26 ++++++ recipes/tpl/all/test_package/test_package.c | 47 +++++++++++ recipes/tpl/config.yml | 3 + 6 files changed, 181 insertions(+) create mode 100644 recipes/tpl/all/conandata.yml create mode 100644 recipes/tpl/all/conanfile.py create mode 100644 recipes/tpl/all/test_package/CMakeLists.txt create mode 100644 recipes/tpl/all/test_package/conanfile.py create mode 100644 recipes/tpl/all/test_package/test_package.c create mode 100644 recipes/tpl/config.yml diff --git a/recipes/tpl/all/conandata.yml b/recipes/tpl/all/conandata.yml new file mode 100644 index 0000000000000..c65962c15db90 --- /dev/null +++ b/recipes/tpl/all/conandata.yml @@ -0,0 +1,5 @@ +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..b5b591f58b877 --- /dev/null +++ b/recipes/tpl/all/conanfile.py @@ -0,0 +1,93 @@ +import os + +from conan import ConanFile +from conan.tools.apple import fix_apple_shared_install_name +from conan.tools.env import Environment, VirtualBuildEnv +from conan.tools.files import apply_conandata_patches, copy, get, rm +from conan.tools.gnu import Autotools, AutotoolsToolchain +from conan.tools.layout import basic_layout +from conan.tools.microsoft import is_msvc, unix_path + +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, + } + + @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 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") + if is_msvc(self): + self.tool_requires("automake/1.16.5") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + env = VirtualBuildEnv(self) + env.generate() + tc = AutotoolsToolchain(self) + tc.generate() + + if is_msvc(self): + env = Environment() + automake_conf = self.dependencies.build["automake"].conf_info + compile_wrapper = unix_path(self, automake_conf.get("user.automake:compile-wrapper", check_type=str)) + ar_wrapper = unix_path(self, automake_conf.get("user.automake:lib-wrapper", check_type=str)) + env.define("CC", f"{compile_wrapper} cl -nologo") + env.define("LD", "link -nologo") + env.define("AR", f'{ar_wrapper} "lib -nologo"') + env.vars(self).save_script("conanbuild_msvc") + + def build(self): + apply_conandata_patches(self) + autotools = Autotools(self) + autotools.autoreconf() + autotools.configure() + autotools.make() + + def package(self): + copy(self, "LICENSE", 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")) + fix_apple_shared_install_name(self) + + def package_info(self): + self.cpp_info.libs = ["tpl"] 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 From c37adc71239e8f0d52f490160c66ddb08e18ee78 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 7 Nov 2023 10:14:12 +0200 Subject: [PATCH 2/7] tpl: replace the autotools build scripts with a simple CMakeLists.txt --- recipes/tpl/all/CMakeLists.txt | 21 +++++++++++++++ recipes/tpl/all/conanfile.py | 47 ++++++++-------------------------- 2 files changed, 32 insertions(+), 36 deletions(-) create mode 100644 recipes/tpl/all/CMakeLists.txt diff --git a/recipes/tpl/all/CMakeLists.txt b/recipes/tpl/all/CMakeLists.txt new file mode 100644 index 0000000000000..6b29e12854c87 --- /dev/null +++ b/recipes/tpl/all/CMakeLists.txt @@ -0,0 +1,21 @@ +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) + set_target_properties(tpl PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) + target_sources(tpl PRIVATE src/win/mmap.c) + install(FILES src/win/mman.h DESTINATION include/win) +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/conanfile.py b/recipes/tpl/all/conanfile.py index b5b591f58b877..6557ce992eecc 100644 --- a/recipes/tpl/all/conanfile.py +++ b/recipes/tpl/all/conanfile.py @@ -1,12 +1,9 @@ import os from conan import ConanFile -from conan.tools.apple import fix_apple_shared_install_name -from conan.tools.env import Environment, VirtualBuildEnv -from conan.tools.files import apply_conandata_patches, copy, get, rm -from conan.tools.gnu import Autotools, AutotoolsToolchain +from conan.tools.cmake import CMakeToolchain, CMake +from conan.tools.files import copy, get from conan.tools.layout import basic_layout -from conan.tools.microsoft import is_msvc, unix_path required_conan_version = ">=1.54.0" @@ -30,6 +27,9 @@ class PackageConan(ConanFile): "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) @@ -47,47 +47,22 @@ def configure(self): def layout(self): basic_layout(self, src_folder="src") - 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") - if is_msvc(self): - self.tool_requires("automake/1.16.5") - def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) def generate(self): - env = VirtualBuildEnv(self) - env.generate() - tc = AutotoolsToolchain(self) + tc = CMakeToolchain(self) tc.generate() - if is_msvc(self): - env = Environment() - automake_conf = self.dependencies.build["automake"].conf_info - compile_wrapper = unix_path(self, automake_conf.get("user.automake:compile-wrapper", check_type=str)) - ar_wrapper = unix_path(self, automake_conf.get("user.automake:lib-wrapper", check_type=str)) - env.define("CC", f"{compile_wrapper} cl -nologo") - env.define("LD", "link -nologo") - env.define("AR", f'{ar_wrapper} "lib -nologo"') - env.vars(self).save_script("conanbuild_msvc") - def build(self): - apply_conandata_patches(self) - autotools = Autotools(self) - autotools.autoreconf() - autotools.configure() - autotools.make() + cmake = CMake(self) + cmake.configure() + cmake.build() def package(self): copy(self, "LICENSE", 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")) - fix_apple_shared_install_name(self) + cmake = CMake(self) + cmake.install() def package_info(self): self.cpp_info.libs = ["tpl"] From 6f9ed793e3e5f1a6e72dddf12b75bf29c58f6938 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 7 Nov 2023 10:16:44 +0200 Subject: [PATCH 3/7] tpl: fix linter error --- recipes/tpl/all/conandata.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/recipes/tpl/all/conandata.yml b/recipes/tpl/all/conandata.yml index c65962c15db90..1d4730dd059e0 100644 --- a/recipes/tpl/all/conandata.yml +++ b/recipes/tpl/all/conandata.yml @@ -2,4 +2,3 @@ sources: "cci.20210302": url: "https://github.com/troydhanson/tpl/archive/f8138ad393f4b1985c916029ab6d703e4e7a1c4c.tar.gz" sha256: "736dcd98bc92178a9cfaeaf8d7f9a67aa49c5ee36b9f76286e055a8a97b640dd" - From 241c1a4296955b453606e996dbcbcb0530339938 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 23 Nov 2023 11:36:41 +0200 Subject: [PATCH 4/7] tpl: fix exporting of symbols for DLLs --- recipes/tpl/all/CMakeLists.txt | 5 +++++ recipes/tpl/all/conanfile.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/recipes/tpl/all/CMakeLists.txt b/recipes/tpl/all/CMakeLists.txt index 6b29e12854c87..e190ee56533f2 100644 --- a/recipes/tpl/all/CMakeLists.txt +++ b/recipes/tpl/all/CMakeLists.txt @@ -11,6 +11,11 @@ if(WIN32) set_target_properties(tpl PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) 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 diff --git a/recipes/tpl/all/conanfile.py b/recipes/tpl/all/conanfile.py index 6557ce992eecc..c6de20abc1b3c 100644 --- a/recipes/tpl/all/conanfile.py +++ b/recipes/tpl/all/conanfile.py @@ -66,3 +66,5 @@ def package(self): 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") From 63dc8b8194c304cc5dfead4e3b289c2763db8211 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 8 Aug 2024 00:47:10 +0300 Subject: [PATCH 5/7] tpl: drop WINDOWS_EXPORT_ALL_SYMBOLS --- recipes/tpl/all/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/recipes/tpl/all/CMakeLists.txt b/recipes/tpl/all/CMakeLists.txt index e190ee56533f2..e64edb314afd5 100644 --- a/recipes/tpl/all/CMakeLists.txt +++ b/recipes/tpl/all/CMakeLists.txt @@ -8,7 +8,6 @@ set_target_properties(tpl PROPERTIES ) if(WIN32) - set_target_properties(tpl PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) target_sources(tpl PRIVATE src/win/mmap.c) install(FILES src/win/mman.h DESTINATION include/win) if(BUILD_SHARED_LIBS) From dc4fd3bf4c3bf625c385bde304db4c89de16b88e Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 8 Aug 2024 00:48:11 +0300 Subject: [PATCH 6/7] tpl: use the newer cci. version format --- recipes/tpl/all/conandata.yml | 2 +- recipes/tpl/config.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/recipes/tpl/all/conandata.yml b/recipes/tpl/all/conandata.yml index 1d4730dd059e0..df250eb262263 100644 --- a/recipes/tpl/all/conandata.yml +++ b/recipes/tpl/all/conandata.yml @@ -1,4 +1,4 @@ sources: - "cci.20210302": + "1.6.1.cci.20210302": url: "https://github.com/troydhanson/tpl/archive/f8138ad393f4b1985c916029ab6d703e4e7a1c4c.tar.gz" sha256: "736dcd98bc92178a9cfaeaf8d7f9a67aa49c5ee36b9f76286e055a8a97b640dd" diff --git a/recipes/tpl/config.yml b/recipes/tpl/config.yml index a4bd9fea5a7a4..671d1a05ecb9c 100644 --- a/recipes/tpl/config.yml +++ b/recipes/tpl/config.yml @@ -1,3 +1,3 @@ versions: - "cci.20210302": + "1.6.1.cci.20210302": folder: all From ff0aa3eedcdc8b2586076345d6137c9195ca84ca Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 10 Sep 2024 14:59:44 +0300 Subject: [PATCH 7/7] tpl: revert cci. versioning scheme Co-authored-by: Daniel --- recipes/tpl/all/conandata.yml | 2 +- recipes/tpl/config.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/recipes/tpl/all/conandata.yml b/recipes/tpl/all/conandata.yml index df250eb262263..1d4730dd059e0 100644 --- a/recipes/tpl/all/conandata.yml +++ b/recipes/tpl/all/conandata.yml @@ -1,4 +1,4 @@ sources: - "1.6.1.cci.20210302": + "cci.20210302": url: "https://github.com/troydhanson/tpl/archive/f8138ad393f4b1985c916029ab6d703e4e7a1c4c.tar.gz" sha256: "736dcd98bc92178a9cfaeaf8d7f9a67aa49c5ee36b9f76286e055a8a97b640dd" diff --git a/recipes/tpl/config.yml b/recipes/tpl/config.yml index 671d1a05ecb9c..a4bd9fea5a7a4 100644 --- a/recipes/tpl/config.yml +++ b/recipes/tpl/config.yml @@ -1,3 +1,3 @@ versions: - "1.6.1.cci.20210302": + "cci.20210302": folder: all