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

h3: add version 4.1.0 #15406

Merged
merged 4 commits into from
Feb 1, 2023
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
13 changes: 13 additions & 0 deletions recipes/h3/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"4.1.0":
url: "https://github.com/uber/h3/archive/refs/tags/v4.1.0.tar.gz"
sha256: "ec99f1f5974846bde64f4513cf8d2ea1b8d172d2218ab41803bf6a63532272bc"
"3.7.2":
url: "https://github.com/uber/h3/archive/refs/tags/v3.7.2.tar.gz"
sha256: "803a7fbbeb01f1f65cae9398bda9579a0529e7bafffc6e0e0a6d81a71b305629"
Expand All @@ -17,11 +20,21 @@ sources:
patches:
"3.7.2":
- patch_file: "patches/fix-cmake-3.7.x.patch"
patch_description: "move project definition to head, set c99 flag"
patch_type: "portability"
"3.7.1":
- patch_file: "patches/fix-cmake-3.7.x.patch"
patch_description: "move project definition to head, set c99 flag"
patch_type: "portability"
"3.7.0":
- patch_file: "patches/fix-cmake-3.7.x.patch"
patch_description: "move project definition to head, set c99 flag"
patch_type: "portability"
"3.6.4":
- patch_file: "patches/fix-cmake-3.6.4.patch"
patch_description: "move project definition to head, set c99 flag"
patch_type: "portability"
"3.6.3":
- patch_file: "patches/fix-cmake-3.6.3.patch"
patch_description: "move project definition to head, set c99 flag"
patch_type: "portability"
30 changes: 20 additions & 10 deletions recipes/h3/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, get, rmdir
from conan.tools.scm import Version
import os

required_conan_version = ">=1.47.0"
required_conan_version = ">=1.53.0"


class H3Conan(ConanFile):
Expand Down Expand Up @@ -38,19 +39,28 @@ def config_options(self):

def configure(self):
if self.options.shared:
del self.options.fPIC
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

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

def _cmake_new_enough(self, required_version):
try:
import re
from io import StringIO
output = StringIO()
self.run("cmake --version", output=output)
m = re.search(r'cmake version (\d+\.\d+\.\d+)', output.getvalue())
return Version(m.group(1)) >= required_version
except:
return False

def build_requirements(self):
if Version(self.version) >= "4.1.0" and not self._cmake_new_enough("3.20"):
self.tool_requires("cmake/3.25.1")

def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)
Expand Down
4 changes: 4 additions & 0 deletions recipes/h3/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ find_package(h3 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE h3::h3)

if(h3_VERSION VERSION_GREATER_EQUAL "4.0.0")
target_compile_definitions(${PROJECT_NAME} PRIVATE "H3_VERSION_4_LATER")
endif()
36 changes: 36 additions & 0 deletions recipes/h3/all/test_package/test_package.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <inttypes.h>
#include <stdio.h>

#ifndef H3_VERSION_4_LATER

int main() {
// Get the H3 index of some location and print it.
GeoCoord location;
Expand Down Expand Up @@ -51,3 +53,37 @@ int main() {

return 0;
}

#else

int main() {
// Get the H3 index of some location and print it.
LatLng location;
location.lat = degsToRads(40.689167);
location.lng = degsToRads(-74.044444);
int resolution = 10;
H3Index indexed;
latLngToCell(&location, resolution, &indexed);
printf("The index is: %" PRIx64 "\n", indexed);

// Get the vertices of the H3 index.
CellBoundary boundary;
cellToBoundary(indexed, &boundary);
// Indexes can have different number of vertices under some cases,
// which is why boundary.numVerts is needed.
int v;
for (v = 0; v < boundary.numVerts; v++) {
printf("Boundary vertex #%d: %lf, %lf\n", v,
radsToDegs(boundary.verts[v].lat),
radsToDegs(boundary.verts[v].lng));
}

// Get the center coordinates.
LatLng center;
cellToLatLng(indexed, &center);
printf("Center coordinates: %lf, %lf\n", radsToDegs(center.lat), radsToDegs(center.lng));

return 0;
}

#endif
6 changes: 2 additions & 4 deletions recipes/h3/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ project(test_package LANGUAGES C)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(h3 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE h3::h3)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
1 change: 0 additions & 1 deletion recipes/h3/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: skip-file
from conans import ConanFile, CMake, tools
import os

Expand Down
2 changes: 2 additions & 0 deletions recipes/h3/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"4.1.0":
folder: all
"3.7.2":
folder: all
"3.7.1":
Expand Down