-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
211 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"0.6.0": | ||
url: https://github.com/mpusz/units/archive/v0.6.0.tar.gz | ||
sha256: 7102d2c4460c87525d385b5f1488ac0ef9755b7f7984076bcc64d1506e1bdfd8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from conans import ConanFile, tools | ||
from conans.errors import ConanInvalidConfiguration | ||
from conans.tools import Version, check_min_cppstd | ||
import os | ||
|
||
|
||
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" | ||
requires = ( | ||
"fmt/7.0.3", | ||
"ms-gsl/3.1.0" | ||
) | ||
generators = "cmake" | ||
no_copy_source = True | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
|
||
@property | ||
def _build_subfolder(self): | ||
return "build_subfolder" | ||
|
||
def _validate_compiler_settings(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 == "Visual Studio": | ||
if version < "16": | ||
raise ConanInvalidConfiguration("mp-units requires at least MSVC 16.7") | ||
else: | ||
raise ConanInvalidConfiguration("mp-units is supported only by gcc and Visual Studio so far") | ||
if compiler.get_safe("cppstd"): | ||
check_min_cppstd(self, "20") | ||
|
||
def configure(self): | ||
self._validate_compiler_settings() | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version]) | ||
extracted_dir = "units-" + self.version | ||
os.rename(extracted_dir, self._source_subfolder) | ||
|
||
def package(self): | ||
self.copy(pattern="*", dst="include", src=os.path.join(self._source_subfolder, "src", "include")) | ||
self.copy("LICENSE.md", dst="licenses", src=self._source_subfolder) | ||
|
||
def package_id(self): | ||
self.info.header_only() | ||
|
||
def package_info(self): | ||
compiler = self.settings.compiler | ||
version = Version(self.settings.compiler.version) | ||
if compiler == "gcc": | ||
self.cpp_info.cxxflags = [ | ||
"-Wno-non-template-friend" | ||
] | ||
elif compiler == "Visual Studio": | ||
self.cpp_info.cxxflags = [ | ||
"/utf-8" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(test_package CXX) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE CONAN_PKG::mp-units) | ||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from conans import ConanFile, CMake, tools | ||
from conans.tools import Version | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake" | ||
|
||
# TODO remove when https://github.com/conan-io/conan/issues/7680 is solved (or VS2019 is updated to at least 16.7) | ||
def _skip_check(self): | ||
return self.settings.compiler == "Visual Studio" and Version(self.settings.compiler.version) <= "16" | ||
|
||
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(os.path.join("bin", "test_package"), run_environment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <units/physical/si/derived/speed.h> | ||
#include <iostream> | ||
|
||
int main() | ||
{ | ||
using namespace units::physical::si::literals; | ||
std::cout << "Speed = " << 240._q_km / 2_q_h << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
sources: | ||
"0.6.0": | ||
url: https://github.com/mpusz/units/archive/v0.6.0.tar.gz | ||
sha256: 7102d2c4460c87525d385b5f1488ac0ef9755b7f7984076bcc64d1506e1bdfd8 | ||
"0.7.0": | ||
url: https://github.com/mpusz/units/archive/v0.7.0.tar.gz | ||
sha256: 7ff4bc3537e1bd09630fefae513796686a3f97e509283ad658e1ae81fe49de67 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(test_package CXX) | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_package | ||
LANGUAGES CXX | ||
) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
find_package(mp-units CONFIG REQUIRED) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE CONAN_PKG::mp-units) | ||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
#include <units/physical/si/derived/speed.h> | ||
#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::physical::si::literals; | ||
std::cout << "Speed = " << 240._q_km / 2_q_h << '\n'; | ||
using namespace units::isq::si::references; | ||
std::cout << "Average speed = " << avg_speed(240 * km, 2 * h) << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
versions: | ||
"0.6.0": | ||
"0.7.0": | ||
folder: all | ||
"0.6.0": | ||
folder: 0.6.0 |