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

samarium: migrate to Conan v2, drop old version #25396

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
28 changes: 2 additions & 26 deletions recipes/samarium/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
sources:
"1.0.0":
sha256: 943de75803f492f78c5d55fe43be298fbb66156cc22946a3c6cc6b0634efc2e2
url: https://github.com/strangeQuark1041/samarium/archive/refs/tags/v1.0.0.tar.gz
"1.0.1":
sha256: 3748ad1095805338d0d54ca7b60a155520188970946b247d56cc9b5eeb397358
url: https://github.com/strangeQuark1041/samarium/archive/refs/tags/v1.0.1.tar.gz
patches:
"1.0.0":
- patch_file: "patches/1.0.0-updated-cmake.patch"
patch_description: "Use find_package for CMakeDeps"
patch_type: "conan"
sha256: "2be2eadc468fe676f547793fc7ec48bc38ce6f1daa47a497cd2535aaa493fa9a"

- patch_file: "patches/1.0.0-Grid.hpp-include-vector.patch"
patch_description: "add missing #include <vector>"
patch_type: "portability"
sha256: "0326eb790fc55630efe138bc9b359754d2de23c4aa37179faa04821f83efa9c3"

- patch_file: "patches/1.0.0-RandomGenerator.hpp-link.patch"
patch_description: "Fix static function linking"
patch_type: "portability"
sha256: "218318c017500ab4c6360dafaf0523736295ddac323c04aaad5fc8a31867b4f0"

- patch_file: "patches/1.0.0-RandomGenerator.cpp-link.patch"
patch_description: "Fix static function linking"
patch_type: "portability"
sha256: "f5d0cc6a108bb3f5f22a88c29f5eda1ddf73c25720e894e7ac3c67396e687087"
url: "https://github.com/jjbel/samarium/archive/refs/tags/v1.0.1.tar.gz"
sha256: "3748ad1095805338d0d54ca7b60a155520188970946b247d56cc9b5eeb397358"
119 changes: 75 additions & 44 deletions recipes/samarium/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,115 @@
from os import path
import os

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.files import patch, copy, get
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, cmake_layout, CMakeToolchain, CMakeDeps
from conan.tools.files import copy, get, save, replace_in_file
from conan.tools.scm import Version

required_conan_version = ">=1.47.0"


class SamariumConan(ConanFile):
name = "samarium"
description = "2-D physics simulation library"
homepage = "https://strangequark1041.github.io/samarium/"
homepage = "https://jjbel.github.io/samarium/"
url = "https://github.com/conan-io/conan-center-index/"
license = "MIT"
topics = ("cpp20", "physics", "2d", "simulation")
generators = "CMakeDeps", "CMakeToolchain"
requires = "fmt/9.0.0", "sfml/2.5.1", "range-v3/0.12.0", "stb/cci.20210910", "tl-expected/20190710"

settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [
True, False]}
default_options = {"shared": False, "fPIC": True}
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

@property
def _min_cppstd(self):
return 20

@property
def _compilers_minimum_version(self):
return {
"gcc": "11.0",
"Visual Studio": "16",
"gcc": "11",
"clang": "13",
"apple-clang": "13",
"msvc": "192",
"Visual Studio": "16",
}

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

def configure(self):
if self.options.shared:
del self.options.fPIC

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def validate(self):
if self.version == "1.0.0" and self.settings.os == "Macos":
raise ConanInvalidConfiguration("Macos not supported for v1.0.0")
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
# samarium relies on stb_image_write.h being instantiated in SFML with STB_IMAGE_WRITE_IMPLEMENTATION,
# but it is not built with --whole-archive, so some symbols expected by samarium are not found.
# Adding STB_IMAGE_WRITE_IMPLEMENTATION in samarium would lead to issues on apple-clang and MSVC due to multiple definitions.
self.options["sfml"].shared = False
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

def layout(self):
cmake_layout(self, src_folder="src")

compiler = str(self.settings.compiler)
if compiler not in self._compilers_minimum_version:
self.output.warn(
"Unknown compiler, assuming it supports at least C++20")
return
def requirements(self):
# Undefined symbols for architecture arm64: "void fmt::v10::detail::vformat_to..." when using sm::print
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added these comments for future traceability

self.requires("fmt/10.2.1", transitive_headers=True, transitive_libs=True)
# Undefined symbols for architecture arm64: "sf::Keyboard::isKeyPressed(sf::Keyboard::Key)"
# when using inlined is_key_pressed function
self.requires("sfml/2.6.1", transitive_headers=True, transitive_libs=True)
self.requires("range-v3/cci.20240905", transitive_headers=True)
self.requires("stb/cci.20230920")
self.requires("tl-expected/20190710", transitive_headers=True)

version = Version(self.settings.compiler.version)
if version < self._compilers_minimum_version[compiler]:
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.name} requires a compiler that supports at least C++20")
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def layout(self):
cmake_layout(self, src_folder="src")
if self.dependencies["sfml"].options.shared:
raise ConanInvalidConfiguration("SFML dependency must be built as a static library")

def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
def source(self):
get(self, **self.conan_data["sources"][str(self.version)], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["RUN_CONAN"] = False
tc.cache_variables["BUILD_UNIT_TESTS"] = False
tc.cache_variables["BUILD_EXAMPLES"] = False
tc.cache_variables["BUILD_DOCS"] = False
tc.cache_variables["BUILD_DOCS_TARGET"] = False
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
# Force-disable all tests
save(self, os.path.join(self.source_folder, "test", "CMakeLists.txt"), "")
# Disable SSE4.1 for non-x86 architectures
if self.settings.arch not in ["x86", "x86_64"]:
replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"),
"-msse4.1;-mpclmul;", "")

def build(self):
for patch_ in self.conan_data.get("patches", {}).get(self.version, []):
patch(self, **patch_)

self._patch_sources()
cmake = CMake(self)
cmake.configure(build_script_folder="src")
cmake.configure()
cmake.build()

def package(self):
copy(self, "LICENSE.md", src=self.folders.source_folder,
dst=path.join(self.package_folder, "licenses"))

copy(self, "LICENSE.md", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

Expand Down
12 changes: 0 additions & 12 deletions recipes/samarium/all/patches/1.0.0-Grid.hpp-include-vector.patch

This file was deleted.

22 changes: 0 additions & 22 deletions recipes/samarium/all/patches/1.0.0-RandomGenerator.cpp-link.patch

This file was deleted.

34 changes: 0 additions & 34 deletions recipes/samarium/all/patches/1.0.0-RandomGenerator.hpp-link.patch

This file was deleted.

39 changes: 0 additions & 39 deletions recipes/samarium/all/patches/1.0.0-updated-cmake.patch

This file was deleted.

4 changes: 2 additions & 2 deletions recipes/samarium/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def build(self):

def test(self):
if not cross_building(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, run_environment=True)
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
12 changes: 9 additions & 3 deletions recipes/samarium/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#include "samarium/samarium.hpp"

#include <iostream>
int main()
{
const auto im = sm::Image{sm::dimsFHD};
fmt::print(fmt::emphasis::bold, "\nSuccessful installation!\n");
fmt::print(fmt::emphasis::bold, "Welcome to {}\n", sm::version);
std::cout << "Version: " << sm::version.major << '.' << sm::version.minor << '.' << sm::version.patch << std::endl;
std::cout << "Image size: " << im.size() << std::endl;
const auto as_sfml = sm::sfml(sm::Vector2_t{1.0, 2.0});
sm::print("A Vector2:", sm::Vector2{.x = 5, .y = -3});
// sm::print("A Color: ", sm::Color{.r = 5, .g = 200, .b = 255});
// sm::print("Is space pressed?", sm::Keyboard::is_key_pressed(sm::Keyboard::Key::Space));
return 0;

}
2 changes: 0 additions & 2 deletions recipes/samarium/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
versions:
"1.0.0":
folder: all
"1.0.1":
folder: all