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 7 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
26 changes: 26 additions & 0 deletions recipes/battery-embed/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
sources:
"1.2.8":
url: "https://github.com/batterycenter/embed/archive/refs/tags/v1.2.8.tar.gz"
sha256: "ee9a7fe04c0d6e6f244bc635003ef0d0cda386fa46ce1dd3b5ad470425a6fb52"
"1.1.1":
url: "https://github.com/batterycenter/embed/archive/refs/tags/v1.1.1.tar.gz"
sha256: "373e33a6959715607e63280b6d6cbd34b9d0db3a93aa909d9b5dc7d830046c7e"
patches:
"1.2.8":
- patch_file: "patches/1.2.8-0001-disable-examples.patch"
patch_description: "disable building examples"
patch_type: "conan"
patch_source: "https://github.com/batterycenter/embed/issues/2"
- patch_file: "patches/1.2.8-0002-include-cstdint.patch"
patch_description: "include cstdint for gcc 13 later"
patch_type: "portability"
patch_source: "https://github.com/batterycenter/embed/pull/1"
"1.1.1":
- patch_file: "patches/1.1.1-0001-disable-examples.patch"
patch_description: "disable building examples"
patch_type: "conan"
patch_source: "https://github.com/batterycenter/embed/issues/2"
- patch_file: "patches/1.1.1-0002-include-cstdint.patch"
patch_description: "include cstdint for gcc 13 later"
patch_type: "portability"
patch_source: "https://github.com/batterycenter/embed/pull/1"
72 changes: 72 additions & 0 deletions recipes/battery-embed/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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.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):
export_conandata_patches(self)
toge marked this conversation as resolved.
Show resolved Hide resolved

def validate(self):
if Version(self.version) >= "1.2.0" and self.settings.compiler == "apple-clang":
raise ConanInvalidConfiguration(f"{self.ref} does not support apple-clang due to lack of jthread and stop_token.")

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

def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
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_build_modules", [os.path.join("lib", "cmake", "battery-embed", "CMakeLists.txt")])

if Version(self.version) >= "1.2.0" and self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("pthread")
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7249988..1996e2b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.21)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
-project(embed)
+# project(embed)

# Options
-option(BUILD_EXAMPLES "Build examples" ${PROJECT_IS_TOP_LEVEL})
+option(BUILD_EXAMPLES "Build examples" OFF)

# Remember the binary dir for later
set(EMBED_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/embed CACHE INTERNAL "binary directory of the battery::embed library" FORCE)
12 changes: 12 additions & 0 deletions recipes/battery-embed/all/patches/1.1.1-0002-include-cstdint.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7249988..1996e2b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,7 @@ set(EMBED_HEADER_FILE [=[
#include <string_view>
#include <stdexcept>
#include <sstream>
+#include <cstdint>

#ifndef __cpp_constexpr_dynamic_alloc
# error "battery::embed requires C++20"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 623bf14..bda7ede 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.21)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
-project(embed)
+# project(embed)

# Options
-option(BUILD_EXAMPLES "Build examples" ${PROJECT_IS_TOP_LEVEL})
+option(BUILD_EXAMPLES "Build examples" OFF)

# Remember the binary dir for later
set(EMBED_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/embed CACHE INTERNAL "binary directory of the battery::embed library" FORCE)
12 changes: 12 additions & 0 deletions recipes/battery-embed/all/patches/1.2.8-0002-include-cstdint.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 623bf14..8dab2d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -153,6 +153,7 @@ set(EMBED_HEADER_FILE [=[
#include <stdexcept>
#include <sstream>
#include <functional>
+#include <cstdint>

#ifndef __cpp_constexpr_dynamic_alloc
# error "battery::embed requires C++20"
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::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;
}
5 changes: 5 additions & 0 deletions recipes/battery-embed/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
versions:
"1.2.8":
folder: all
"1.1.1":
folder: all
Loading