diff --git a/recipes/libosmium/all/conandata.yml b/recipes/libosmium/all/conandata.yml new file mode 100644 index 0000000000000..26bf7eb783d20 --- /dev/null +++ b/recipes/libosmium/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "2.20.0": + url: "https://github.com/osmcode/libosmium/archive/v2.20.0.tar.gz" + sha256: "3d3e0873c6aaabb3b2ef4283896bebf233334891a7a49f4712af30ca6ed72477" diff --git a/recipes/libosmium/all/conanfile.py b/recipes/libosmium/all/conanfile.py new file mode 100644 index 0000000000000..24cbe2d89912a --- /dev/null +++ b/recipes/libosmium/all/conanfile.py @@ -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") + 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") diff --git a/recipes/libosmium/all/libosmium-official-vars.cmake b/recipes/libosmium/all/libosmium-official-vars.cmake new file mode 100644 index 0000000000000..249a7fd742a13 --- /dev/null +++ b/recipes/libosmium/all/libosmium-official-vars.cmake @@ -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) diff --git a/recipes/libosmium/all/test_package/CMakeLists.txt b/recipes/libosmium/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..3887f84cbc2ec --- /dev/null +++ b/recipes/libosmium/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/libosmium/all/test_package/conanfile.py b/recipes/libosmium/all/test_package/conanfile.py new file mode 100644 index 0000000000000..02eb5ce439fb4 --- /dev/null +++ b/recipes/libosmium/all/test_package/conanfile.py @@ -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") diff --git a/recipes/libosmium/all/test_package/test_package.cpp b/recipes/libosmium/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..d845c15a1d72a --- /dev/null +++ b/recipes/libosmium/all/test_package/test_package.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + osmium::OSMEntity entity(1, osmium::item_type::node); +} diff --git a/recipes/libosmium/config.yml b/recipes/libosmium/config.yml new file mode 100644 index 0000000000000..bb6ad1a3e3dc2 --- /dev/null +++ b/recipes/libosmium/config.yml @@ -0,0 +1,3 @@ +versions: + "2.20.0": + folder: all