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

libosmium: new recipe #23720

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions recipes/libosmium/all/conandata.yml
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"
130 changes: 130 additions & 0 deletions recipes/libosmium/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
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("gdalcpp/1.3.0")
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
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):
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", "osmium"), os.path.join(self.package_folder, "include", "osmium"))
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", ["gdalcpp::gdalcpp"])
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")
13 changes: 13 additions & 0 deletions recipes/libosmium/all/libosmium-official-vars.cmake
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)
9 changes: 9 additions & 0 deletions recipes/libosmium/all/test_package/CMakeLists.txt
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)
27 changes: 27 additions & 0 deletions recipes/libosmium/all/test_package/conanfile.py
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")
5 changes: 5 additions & 0 deletions recipes/libosmium/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <osmium/osm.hpp>

int main() {
osmium::OSMEntity entity(1, osmium::item_type::node);
}
3 changes: 3 additions & 0 deletions recipes/libosmium/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.20.0":
folder: all