Skip to content

Commit aa931ab

Browse files
committed
use latest conan file
get rid of user dependency of std::chrono::time_zone when linking against chron-cpp
1 parent ce6a59a commit aa931ab

3 files changed

Lines changed: 35 additions & 19 deletions

File tree

conanfile.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
from conan import ConanFile
22
from conan.tools.build import check_min_cppstd
3+
from conan.tools.scm import Version
34
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
4-
from conan.tools.files import (
5-
apply_conandata_patches,
6-
copy,
7-
export_conandata_patches,
8-
get,
9-
rm,
10-
rmdir,
11-
)
5+
from conan.tools.files import copy, get, rm, rmdir
6+
from conan.errors import ConanInvalidConfiguration
7+
128
import os
139

1410

@@ -26,7 +22,7 @@ class ChronCppConan(ConanFile):
2622
license = "Unlicense"
2723
url = "https://github.com/conan-io/conan-center-index"
2824
homepage = "https://github.com/BestITUserEUW/chron-cpp"
29-
topics = "chron"
25+
topics = ("chron",)
3026
package_type = "library"
3127
settings = "os", "arch", "compiler", "build_type"
3228
options = {
@@ -40,26 +36,33 @@ class ChronCppConan(ConanFile):
4036
# In case having config_options() or configure() method, the logic should be moved to the specific methods.
4137
implements = ["auto_shared_fpic"]
4238

43-
# no exports_sources attribute, but export_sources(self) method instead
44-
def export_sources(self):
45-
export_conandata_patches(self)
46-
4739
def configure(self):
4840
if self.options.shared:
4941
self.options.rm_safe("fPIC")
5042

5143
def layout(self):
52-
cmake_layout(self)
44+
cmake_layout(self, src_folder=".")
5345

5446
def validate(self):
55-
check_min_cppstd(self, 20)
47+
if self.settings.compiler.get_safe("cppstd"):
48+
check_min_cppstd(self, self._min_cppstd)
49+
50+
minimum_version = self._compilers_minimum_version.get(
51+
str(self.settings.compiler), False
52+
)
53+
if (
54+
minimum_version
55+
and Version(self.settings.compiler.version) < minimum_version
56+
):
57+
raise ConanInvalidConfiguration(
58+
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
59+
)
5660

5761
def build_requirements(self):
5862
self.tool_requires("cmake/[>=3.24]")
5963

6064
def source(self):
6165
get(self, **self.conan_data["sources"][self.version], strip_root=True)
62-
apply_conandata_patches(self)
6366

6467
def generate(self):
6568
deps = CMakeDeps(self)
@@ -94,3 +97,16 @@ def package_info(self):
9497
self.cpp_info.libs = ["chron-cpp"]
9598
self.cpp_info.set_property("cmake_file_name", "chron-cpp")
9699
self.cpp_info.set_property("cmake_target_name", "oryx::chron-cpp")
100+
101+
@property
102+
def _compilers_minimum_version(self):
103+
return {
104+
"gcc": "13",
105+
"clang": "16",
106+
"apple-clang": "15",
107+
"msvc": "192",
108+
}
109+
110+
@property
111+
def _min_cppstd(self):
112+
return "20"

include/oryx/chron/clock.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ORYX_CHRON_API TzClock {
3737

3838
private:
3939
mutable std::mutex mtx_{};
40-
const std::chrono::time_zone* timezone_{};
40+
const void* timezone_{};
4141
};
4242

4343
static_assert(traits::Clock<LocalClock>);

src/clock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ auto TzClock::TrySetTimezone(std::string_view name) -> bool {
4646
if (!new_zone) return false;
4747

4848
std::lock_guard lock(mtx_);
49-
timezone_ = new_zone;
49+
timezone_ = static_cast<const void *>(new_zone);
5050
return true;
5151
}
5252

5353
auto TzClock::UtcOffset(TimePoint now) const -> seconds {
5454
// If we don't have a timezone set we use utc
5555
std::lock_guard lock(mtx_);
5656
if (timezone_)
57-
return timezone_->get_info(now).offset;
57+
return reinterpret_cast<const time_zone *>(timezone_)->get_info(now).offset;
5858
else
5959
return 0s;
6060
}

0 commit comments

Comments
 (0)