Skip to content

Commit

Permalink
mp-units 0.7.0 added
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed May 11, 2021
1 parent a729cc4 commit 01f81ab
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/mp-units/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.7.0":
url: https://github.com/mpusz/units/archive/v0.7.0.tar.gz
sha256: 7ff4bc3537e1bd09630fefae513796686a3f97e509283ad658e1ae81fe49de67
97 changes: 97 additions & 0 deletions recipes/mp-units/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from conans import ConanFile, tools
from conans.tools import Version, check_min_cppstd
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.33.0"

class MPUnitsConan(ConanFile):
name = "mp-units"
homepage = "https://github.com/mpusz/units"
description = "Physical Units library for C++"
topics = ("units", "dimensions", "quantities", "dimensional-analysis", "physical-quantities", "physical-units", "system-of-units", "cpp23", "cpp20", "library", "quantity-manipulation")
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
settings = "os", "arch", "compiler", "build_type"
options = {
"downcast_mode": ["off", "on", "auto"]
}
default_options = {
"downcast_mode": "on"
}
no_copy_source = True

@property
def _source_subfolder(self):
return "source_subfolder"

def requirements(self):
compiler = self.settings.compiler
self.requires("fmt/7.1.3")
self.requires("gsl-lite/0.38.0")
if compiler == "clang" and compiler.libcxx == "libc++":
self.requires("range-v3/0.11.0")

def validate(self):
compiler = self.settings.compiler
version = Version(self.settings.compiler.version)
if compiler == "gcc":
if version < "10.0":
raise ConanInvalidConfiguration("mp-units requires at least g++-10")
elif compiler == "clang":
if version < "12":
raise ConanInvalidConfiguration("mp-units requires at least clang++-12")
elif compiler == "Visual Studio":
if version < "16":
raise ConanInvalidConfiguration("mp-units requires at least Visual Studio 16.9")
else:
raise ConanInvalidConfiguration("Unsupported compiler")
if compiler.get_safe("cppstd"):
check_min_cppstd(self, "20")

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["UNITS_DOWNCAST_MODE"] = str(self.options.downcast_mode).upper()
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def package(self):
self.copy("LICENSE.md", dst="licenses", src=self._source_subfolder)
cmake = CMake(self)
cmake.configure(source_folder=os.path.join(self._source_subfolder, "src"))
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))

def package_id(self):
self.info.header_only()

def package_info(self):
compiler = self.settings.compiler

# core
self.cpp_info.components["core"].requires = ["gsl-lite::gsl-lite"]
if compiler == "Visual Studio":
self.cpp_info.components["core"].cxxflags = ["/utf-8"]
elif compiler == "clang" and compiler.libcxx == "libc++":
self.cpp_info.components["core"].requires.append("range-v3::range-v3")

# rest
self.cpp_info.components["core-io"].requires = ["core"]
self.cpp_info.components["core-fmt"].requires = ["core", "fmt::fmt"]
self.cpp_info.components["isq"].requires = ["core"]
self.cpp_info.components["isq-natural"].requires = ["isq"]
self.cpp_info.components["si"].requires = ["isq"]
self.cpp_info.components["si-cgs"].requires = ["si"]
self.cpp_info.components["si-fps"].requires = ["si"]
self.cpp_info.components["si-iau"].requires = ["si"]
self.cpp_info.components["si-imperial"].requires = ["si"]
self.cpp_info.components["si-international"].requires = ["si"]
self.cpp_info.components["si-typographic"].requires = ["si"]
self.cpp_info.components["si-uscs"].requires = ["si"]
self.cpp_info.components["isq-iec80000"].requires = ["si"]
self.cpp_info.components["systems"].requires = ["isq", "isq-natural", "si", "si-cgs", "si-fps", "si-iau", "si-imperial", "si-international", "si-typographic", "si-uscs", "isq-iec80000"]
10 changes: 10 additions & 0 deletions recipes/mp-units/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(mp-units CONFIG REQUIRED)

add_executable(test_package test_package.cpp)
target_link_libraries(test_package PRIVATE mp-units::mp-units)
target_compile_features(test_package PUBLIC cxx_std_20)
33 changes: 33 additions & 0 deletions recipes/mp-units/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from conans import ConanFile, tools
from conans.tools import Version
from conan.tools.cmake import CMakeToolchain, CMake, CMakeDeps
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"

# TODO remove when https://github.com/conan-io/conan/issues/7680 is solved (or VS2019 is updated to at least 16.9)
def _skip_check(self):
return self.settings.compiler == "Visual Studio" and Version(self.settings.compiler.version) <= "16"

def generate(self):
if self._skip_check():
return
tc = CMakeToolchain(self)
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def build(self):
if self._skip_check():
return
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if self._skip_check():
return
if not tools.cross_building(self.settings):
self.run("test_package", run_environment=True)
19 changes: 19 additions & 0 deletions recipes/mp-units/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <units/isq/si/length.h>
#include <units/isq/si/speed.h>
#include <units/isq/si/time.h>
#include <units/quantity_io.h>
#include <iostream>

using namespace units;

template<isq::Length Length, isq::Time Time>
constexpr auto avg_speed(Length d, Time t)
{
return d / t;
}

int main()
{
using namespace units::isq::si::references;
std::cout << "Average speed = " << avg_speed(240 * km, 2 * h) << '\n';
}
2 changes: 2 additions & 0 deletions recipes/mp-units/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"0.7.0":
folder: all
"0.6.0":
folder: 0.6.0

0 comments on commit 01f81ab

Please sign in to comment.