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

battery-embed: add recipe #22698

Merged
merged 23 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
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.15":
url: "https://github.com/batterycenter/embed/archive/refs/tags/v1.2.15.tar.gz"
sha256: "d49aebb59099e6d8fa0bd3a0214e6027ef19de85c56cf2cd2365b4221f963cf8"
75 changes: 75 additions & 0 deletions recipes/battery-embed/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.files import copy, get, export_conandata_patches, apply_conandata_patches
toge marked this conversation as resolved.
Show resolved Hide resolved
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)
export_conandata_patches(self)
toge marked this conversation as resolved.
Show resolved Hide resolved

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
danimtb marked this conversation as resolved.
Show resolved Hide resolved

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

def build(self):
apply_conandata_patches(self)
toge marked this conversation as resolved.
Show resolved Hide resolved
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 = []
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

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")
10 changes: 10 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,10 @@
#include <cstdlib>
#include <iostream>
#include <cstdint>

#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.15":
folder: all
Loading