From f4ac88dd03d779c420e582ef0da8bfa2e9ada5eb Mon Sep 17 00:00:00 2001 From: toge Date: Wed, 21 Aug 2024 20:45:01 +0900 Subject: [PATCH] (#22698) battery-embed: add recipe * battery-embed: add recipe * change package_type * remove cmake_find_mode * link pthread, require newer cmake on test_package * drop support apple-clang * add 1.1.1 for macOS * update 1.2.12 * update 1.2.12, remove all patches * revert target_link_libraries * (trial) include unodered_map for apple-clang * append builddirs * update 1.2.14, remove pthread link * fix filename * update 1.2.15, undef B_PRODUCTION_MODE * remove patch files unused * remove export_coinandata_patches Co-authored-by: Martin Valgur * remove apply_conandata_patches Co-authored-by: Martin Valgur * remove unused import Co-authored-by: Martin Valgur * update 1.2.19 * Update recipes/battery-embed/all/conanfile.py --------- Co-authored-by: Martin Valgur Co-authored-by: Daniel --- recipes/battery-embed/all/conandata.yml | 4 + recipes/battery-embed/all/conanfile.py | 74 +++++++++++++++++++ recipes/battery-embed/all/embed.cmake | 4 + .../all/test_package/CMakeLists.txt | 10 +++ .../all/test_package/conanfile.py | 29 ++++++++ .../all/test_package/test_package.cpp | 8 ++ recipes/battery-embed/config.yml | 3 + 7 files changed, 132 insertions(+) create mode 100644 recipes/battery-embed/all/conandata.yml create mode 100644 recipes/battery-embed/all/conanfile.py create mode 100644 recipes/battery-embed/all/embed.cmake create mode 100644 recipes/battery-embed/all/test_package/CMakeLists.txt create mode 100644 recipes/battery-embed/all/test_package/conanfile.py create mode 100644 recipes/battery-embed/all/test_package/test_package.cpp create mode 100644 recipes/battery-embed/config.yml diff --git a/recipes/battery-embed/all/conandata.yml b/recipes/battery-embed/all/conandata.yml new file mode 100644 index 0000000000000..b94490b90ffc3 --- /dev/null +++ b/recipes/battery-embed/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "1.2.19": + url: "https://github.com/batterycenter/embed/archive/refs/tags/v1.2.19.tar.gz" + sha256: "d472655b6eec215cd7cd20411f3596f22f597ea6a82fbbc5a5d7271e102b610e" diff --git a/recipes/battery-embed/all/conanfile.py b/recipes/battery-embed/all/conanfile.py new file mode 100644 index 0000000000000..42b1dc0f23c98 --- /dev/null +++ b/recipes/battery-embed/all/conanfile.py @@ -0,0 +1,74 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.files import copy, get +from conan.tools.cmake import cmake_layout +from conan.tools.scm import Version +import os + +required_conan_version = ">=1.53.0" + +class BatteryEmbedConan(ConanFile): + name = "battery-embed" + description = "A CMake/C++20 library to embed resource files at compile time" + license = "Apache-2.0" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/batterycenter/embed" + topics = ("embed") + package_type = "build-scripts" + settings = "os", "arch", "compiler", "build_type" + + @property + def _min_cppstd(self): + return 20 + + @property + def _compilers_minimum_version(self): + return { + "gcc": "11", + "clang": "12", + "apple-clang": "13", + "Visual Studio": "16", + "msvc": "192", + } + + def export_sources(self): + copy(self, "embed.cmake", src=self.recipe_folder, dst=self.export_sources_folder) + + def layout(self): + cmake_layout(self, src_folder="src") + + def validate(self): + if self.settings.compiler.cppstd: + check_min_cppstd(self, self._min_cppstd) + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and Version(self.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." + ) + + def package_id(self): + del self.info.settings.arch + del self.info.settings.compiler + del self.info.settings.build_type + del self.info.settings.os + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def build(self): + copy(self, "embed.cmake", os.path.join(self.source_folder, os.pardir), self.recipe_folder) + + def package(self): + copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) + copy(self, "embed.cmake", self.recipe_folder, os.path.join(self.package_folder, "lib", "cmake")) + copy(self, "CMakeLists.txt", self.source_folder, os.path.join(self.package_folder, "lib", "cmake", "battery-embed")) + + def package_info(self): + self.cpp_info.libdirs = [] + self.cpp_info.bindirs = [] + self.cpp_info.includedirs = [] + + self.cpp_info.set_property("cmake_target_name", "battery::embed") + self.cpp_info.builddirs.append(os.path.join("lib", "cmake")) + self.cpp_info.set_property("cmake_build_modules", [os.path.join("lib", "cmake", "embed.cmake")]) diff --git a/recipes/battery-embed/all/embed.cmake b/recipes/battery-embed/all/embed.cmake new file mode 100644 index 0000000000000..59fe1f00e55a0 --- /dev/null +++ b/recipes/battery-embed/all/embed.cmake @@ -0,0 +1,4 @@ +# cmake proxy module +cmake_minimum_required(VERSION 3.21) + +add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/battery-embed battery-embed-build) diff --git a/recipes/battery-embed/all/test_package/CMakeLists.txt b/recipes/battery-embed/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..c4ee8021bda84 --- /dev/null +++ b/recipes/battery-embed/all/test_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(battery-embed REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE battery::embed) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) + +b_embed(${PROJECT_NAME} test_package.cpp) diff --git a/recipes/battery-embed/all/test_package/conanfile.py b/recipes/battery-embed/all/test_package/conanfile.py new file mode 100644 index 0000000000000..065416112515f --- /dev/null +++ b/recipes/battery-embed/all/test_package/conanfile.py @@ -0,0 +1,29 @@ +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_requirements(self): + self.tool_requires("cmake/[>=3.21 <4]") + + 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/battery-embed/all/test_package/test_package.cpp b/recipes/battery-embed/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..feb15d322e7f2 --- /dev/null +++ b/recipes/battery-embed/all/test_package/test_package.cpp @@ -0,0 +1,8 @@ +#include + +#include "battery/embed.hpp" + +int main(void) { + std::cout << b::embed<"test_package.cpp">() << std::endl; + return EXIT_SUCCESS; +} diff --git a/recipes/battery-embed/config.yml b/recipes/battery-embed/config.yml new file mode 100644 index 0000000000000..a18e338f675d9 --- /dev/null +++ b/recipes/battery-embed/config.yml @@ -0,0 +1,3 @@ +versions: + "1.2.19": + folder: all