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

add mbits-semver/0.1.1 #14785

Merged
merged 7 commits into from
Dec 26, 2022
Merged
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
4 changes: 4 additions & 0 deletions recipes/mbits-semver/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
0.1.1:
url: "https://github.com/mbits-libs/semver/archive/v0.1.1.tar.gz"
sha256: "edfa9b04bdffd8efbdea31c9cfd7064801483d8cab0b2de5734018bdb318cf18"
103 changes: 103 additions & 0 deletions recipes/mbits-semver/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import check_min_vs, is_msvc
from conan.tools.files import export_conandata_patches, get, copy, rmdir
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
import os


required_conan_version = ">=1.53.0"


class MBitsSemverConan(ConanFile):
name = "mbits-semver"
description = "Semantic Version type for C++17"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/mbits-libs/semver"
topics = ("semver", "semantic-versioning")
settings = "os", "compiler", "build_type", "arch"
options = {"fPIC": [True, False]}
default_options = {"fPIC": True}

@property
def _min_cppstd(self):
return 17

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

def export_sources(self):
export_conandata_patches(self)

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

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

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
check_min_vs(self, 192)
if not is_msvc(self):
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 source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["SEMVER_TESTING"] = False
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(
self,
pattern="LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder,
)
cmake = CMake(self)
cmake.install()

rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.libs = ["semver"]

self.cpp_info.set_property("cmake_file_name", "mbits-semver")
self.cpp_info.set_property("cmake_target_name", "mbits::semver")

self.cpp_info.filenames["cmake_find_package"] = "mbits-semver"
self.cpp_info.filenames["cmake_find_package_multi"] = "mbits-semver"
self.cpp_info.names["cmake_find_package"] = "mbits"
self.cpp_info.names["cmake_find_package_multi"] = "mbits"
self.cpp_info.components["semver"].set_property(
"cmake_target_name", "mbits::semver"
)
self.cpp_info.components["semver"].libs = ["semver"]
8 changes: 8 additions & 0 deletions recipes/mbits-semver/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

find_package(mbits-semver REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE mbits::semver)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
27 changes: 27 additions & 0 deletions recipes/mbits-semver/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


# It will become the standard on Conan 2.x
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(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
29 changes: 29 additions & 0 deletions recipes/mbits-semver/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <cstdio>
#include <semver/version.hh>
#include <string>

int main() {
auto const ver_data = std::string{"1.3.0-beta.5+something.mixed.5"};
semver::project_version beta5{ver_data};

auto const ver_data_rc = std::string{"1.3.0-rc"};
semver::project_version rc{ver_data_rc};

char const *verdict = semver::version.compatible_with(beta5) ? "" : "in";
printf("Compiled-in version %s is %scompatible with runtime version %s\n",
semver::version.to_string().c_str(), verdict,
beta5.to_string().c_str());

verdict = semver::version.compatible_with(semver::get_version()) ? "" : "in";
printf("Compiled-in version %s is %scompatible with runtime version %s\n",
semver::version.to_string().c_str(), verdict,
semver::get_version().to_string().c_str());

verdict = beta5.compatible_with(rc) ? "" : "in";
printf("Compiled-in version %s is %scompatible with runtime version %s\n",
beta5.to_string().c_str(), verdict, rc.to_string().c_str());

verdict = rc.compatible_with(beta5) ? "" : "in";
printf("Compiled-in version %s is %scompatible with runtime version %s\n",
rc.to_string().c_str(), verdict, beta5.to_string().c_str());
}
8 changes: 8 additions & 0 deletions recipes/mbits-semver/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
19 changes: 19 additions & 0 deletions recipes/mbits-semver/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


# legacy validation with Conan 1.x
class TestPackageV1Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
3 changes: 3 additions & 0 deletions recipes/mbits-semver/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
0.1.1:
folder: all