-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
libosmium: new recipe #23720
Open
valgur
wants to merge
5
commits into
conan-io:master
Choose a base branch
from
valgur:new/libosmium
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+191
−0
Open
libosmium: new recipe #23720
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
11e9fb1
libosmium: new recipe
valgur 5c9397c
libosmium: use a version range for zlib
valgur 887e2e2
libosmium: unvendor gdalcpp
valgur 2526ef8
libosmium: drop Conan v1 support
valgur 7be9ad4
libosmium: simplify test_package, use only the core headers
valgur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: | ||
"2.20.0": | ||
url: "https://github.com/osmcode/libosmium/archive/v2.20.0.tar.gz" | ||
sha256: "3d3e0873c6aaabb3b2ef4283896bebf233334891a7a49f4712af30ca6ed72477" |
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,136 @@ | ||
import os | ||
|
||
from conan import ConanFile | ||
from conan.tools.build import check_min_cppstd | ||
from conan.tools.cmake import cmake_layout | ||
from conan.tools.files import copy, get | ||
from conan.tools.microsoft import is_msvc | ||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
class LibosmiumConan(ConanFile): | ||
name = "libosmium" | ||
description = "A fast and flexible C++ library for working with OpenStreetMap data" | ||
license = "BSL-1.0" | ||
homepage = "https://osmcode.org/libosmium/" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
topics = ("openstreetmap", "osm", "basemap", "gis", "geography", "header-only") | ||
|
||
package_type = "header-library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"pbf": [True, False], | ||
"xml": [True, False], | ||
"geos": [True, False], | ||
"gdal": [True, False], | ||
"proj": [True, False], | ||
"lz4": [True, False], | ||
} | ||
default_options = { | ||
"pbf": True, | ||
"xml": True, | ||
"geos": True, | ||
"gdal": False, | ||
"proj": True, | ||
"lz4": True, | ||
} | ||
options_description = { | ||
# https://github.com/osmcode/libosmium/blob/v2.20.0/cmake/FindOsmium.cmake#L30-L37 | ||
"pbf": "include libraries needed for PBF input and output", | ||
"xml": "include libraries needed for XML input and output", | ||
"geos": "include if you want to use any of the GEOS functions", | ||
"gdal": "include if you want to use any of the OGR functions", | ||
"proj": "include if you want to use any of the Proj.4 functions", | ||
"lz4": "include support for LZ4 compression of PBF files", | ||
} | ||
|
||
def export_sources(self): | ||
copy(self, "libosmium-official-vars.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src")) | ||
|
||
def layout(self): | ||
cmake_layout(self, src_folder="src") | ||
|
||
def requirements(self): | ||
if self.options.pbf: | ||
self.requires("protozero/1.7.1") | ||
if self.options.xml: | ||
self.requires("expat/[>=2.6.2 <3]") | ||
self.requires("bzip2/1.0.8") | ||
if self.options.pbf or self.options.xml: | ||
self.requires("zlib/[>=1.2.11 <2]") | ||
if self.options.geos: | ||
self.requires("geos/3.12.0") | ||
if self.options.gdal: | ||
self.requires("gdal/3.8.3") | ||
if self.options.proj: | ||
self.requires("proj/9.3.1") | ||
if self.options.lz4: | ||
self.requires("lz4/1.9.4") | ||
|
||
def package_id(self): | ||
self.info.clear() | ||
|
||
def validate(self): | ||
if self.settings.compiler.get_safe("cppstd"): | ||
check_min_cppstd(self, 11) | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
@property | ||
def _modules_rel_dir(self): | ||
return os.path.join("lib", "cmake", "libosmium") | ||
|
||
@property | ||
def _module_rel_path(self): | ||
return os.path.join(self._modules_rel_dir, "libosmium-official-vars.cmake") | ||
|
||
def package(self): | ||
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) | ||
copy(self, "*", os.path.join(self.source_folder, "include"), os.path.join(self.package_folder, "include")) | ||
copy(self, "libosmium-official-vars.cmake", self.source_folder, os.path.join(self.package_folder, self._modules_rel_dir)) | ||
|
||
def package_info(self): | ||
# https://github.com/osmcode/libosmium/blob/master/cmake/FindOsmium.cmake | ||
self.cpp_info.set_property("cmake_find_mode", "both") | ||
self.cpp_info.set_property("cmake_file_name", "Osmium") | ||
|
||
self.cpp_info.builddirs.append(os.path.join("lib", "cmake", "libosmium")) | ||
self.cpp_info.set_property("cmake_build_modules", [self._module_rel_path]) | ||
|
||
def _add_component(name, reqs, threads=False): | ||
component = self.cpp_info.components[name] | ||
component.bindirs = [] | ||
component.libdirs = [] | ||
component.requires = reqs | ||
if threads and self.settings.os in ["Linux", "FreeBSD"]: | ||
component.system_libs.append("pthread") | ||
component.defines = ["_LARGEFILE_SOURCE", "_FILE_OFFSET_BITS=64"] | ||
if is_msvc(self): | ||
# https://github.com/osmcode/libosmium/blob/v2.20.0/cmake/FindOsmium.cmake#L316-L337 | ||
component.cxxflags.extend(["-wd4996", "-wd4068", "-wd4715", "-wd4351", "-wd4503"]) | ||
component.defines.extend(["NOMINMAX", "WIN32_LEAN_AND_MEAN", "_CRT_SECURE_NO_WARNINGS"]) | ||
|
||
if self.options.pbf: | ||
_add_component("pbf", ["protozero::protozero", "zlib::zlib"], threads=True) | ||
if self.options.lz4: | ||
self.cpp_info.components["pbf"].requires.append("lz4") | ||
if self.options.xml: | ||
_add_component("xml", ["expat::expat", "bzip2::bzip2", "zlib::zlib"], threads=True) | ||
if self.options.pbf and self.options.xml: | ||
_add_component("io", ["pbf", "xml"]) | ||
if self.options.geos: | ||
_add_component("geos", ["geos::geos"]) | ||
if self.options.gdal: | ||
_add_component("gdal", ["gdal::gdal"]) | ||
if self.options.proj: | ||
_add_component("proj", ["proj::proj"]) | ||
if self.options.lz4: | ||
_add_component("lz4", ["lz4::lz4"]) | ||
self.cpp_info.components["io"].defines.append("OSMIUM_WITH_LZ4") | ||
|
||
# TODO: to remove in conan v2 once cmake_find_package_* generators removed | ||
self.cpp_info.filenames["cmake_find_package"] = "Osmium" | ||
self.cpp_info.filenames["cmake_find_package_multi"] = "Osmium" | ||
self.cpp_info.build_modules["cmake_find_package"] = [self._module_rel_path] | ||
self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_rel_path] |
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,13 @@ | ||
# https://github.com/osmcode/libosmium/blob/v2.20.0/cmake/FindOsmium.cmake | ||
|
||
set(OSMIUM_FOUND TRUE) | ||
set(OSMIUM_INCLUDE_DIRS ${${CMAKE_FIND_PACKAGE_NAME}_INCLUDE_DIR}) | ||
set(OSMIUM_LIBRARIES ${${CMAKE_FIND_PACKAGE_NAME}_LIBRARIES}) | ||
set(OSMIUM_VERSION ${${CMAKE_FIND_PACKAGE_NAME}_VERSION}) | ||
|
||
# OSMIUM_XML_LIBRARIES - Libraries needed for XML I/O. | ||
set(OSMIUM_XML_LIBRARIES libosmium::xml) | ||
# OSMIUM_PBF_LIBRARIES - Libraries needed for PBF I/O. | ||
set(OSMIUM_PBF_LIBRARIES libosmium::pbf) | ||
# OSMIUM_IO_LIBRARIES - Libraries needed for XML or PBF I/O. | ||
set(OSMIUM_IO_LIBRARIES libosmium::io) |
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.15) | ||
project(test_package LANGUAGES CXX) | ||
|
||
find_package(Osmium REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${OSMIUM_INCLUDE_DIRS}) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE ${OSMIUM_LIBRARIES}) | ||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) |
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,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.bindir, "test_package") | ||
self.run(bin_path, env="conanrun") |
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,13 @@ | ||
#include <osmium/io/any_input.hpp> | ||
|
||
#include <iostream> | ||
|
||
int main() { | ||
try { | ||
const osmium::io::File input_file{"missing_file.pbf"}; | ||
osmium::io::Reader reader{input_file}; | ||
} catch (const std::exception& e) { | ||
std::cerr << e.what() << '\n'; | ||
return 0; | ||
} | ||
} |
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,3 @@ | ||
versions: | ||
"2.20.0": | ||
folder: all |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea with passing a missing file, very on topic with the simplification of the test packages :)