Skip to content

Commit

Permalink
(#22698) battery-embed: add recipe
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* remove apply_conandata_patches

Co-authored-by: Martin Valgur <[email protected]>

* remove unused import

Co-authored-by: Martin Valgur <[email protected]>

* update 1.2.19

* Update recipes/battery-embed/all/conanfile.py

---------

Co-authored-by: Martin Valgur <[email protected]>
Co-authored-by: Daniel <[email protected]>
  • Loading branch information
3 people authored Aug 21, 2024
1 parent 461310a commit f4ac88d
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/battery-embed/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.2.19":
url: "https://github.com/batterycenter/embed/archive/refs/tags/v1.2.19.tar.gz"
sha256: "d472655b6eec215cd7cd20411f3596f22f597ea6a82fbbc5a5d7271e102b610e"
74 changes: 74 additions & 0 deletions recipes/battery-embed/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")])
4 changes: 4 additions & 0 deletions recipes/battery-embed/all/embed.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# cmake proxy module
cmake_minimum_required(VERSION 3.21)

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/battery-embed battery-embed-build)
10 changes: 10 additions & 0 deletions recipes/battery-embed/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
29 changes: 29 additions & 0 deletions recipes/battery-embed/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
8 changes: 8 additions & 0 deletions recipes/battery-embed/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <iostream>

#include "battery/embed.hpp"

int main(void) {
std::cout << b::embed<"test_package.cpp">() << std::endl;
return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/battery-embed/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.2.19":
folder: all

0 comments on commit f4ac88d

Please sign in to comment.