From be246cae93712171e5379a45fa909a0cf47e52b2 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 23 Apr 2024 14:45:51 +0300 Subject: [PATCH 1/2] osrm: new recipe --- recipes/osrm/all/conan_deps.cmake | 58 ++++++ recipes/osrm/all/conandata.yml | 4 + recipes/osrm/all/conanfile.py | 191 ++++++++++++++++++ recipes/osrm/all/test_package/CMakeLists.txt | 8 + recipes/osrm/all/test_package/conanfile.py | 26 +++ .../osrm/all/test_package/test_package.cpp | 13 ++ recipes/osrm/config.yml | 3 + 7 files changed, 303 insertions(+) create mode 100644 recipes/osrm/all/conan_deps.cmake create mode 100644 recipes/osrm/all/conandata.yml create mode 100644 recipes/osrm/all/conanfile.py create mode 100644 recipes/osrm/all/test_package/CMakeLists.txt create mode 100644 recipes/osrm/all/test_package/conanfile.py create mode 100644 recipes/osrm/all/test_package/test_package.cpp create mode 100644 recipes/osrm/config.yml diff --git a/recipes/osrm/all/conan_deps.cmake b/recipes/osrm/all/conan_deps.cmake new file mode 100644 index 0000000000000..26b045165ef0d --- /dev/null +++ b/recipes/osrm/all/conan_deps.cmake @@ -0,0 +1,58 @@ +macro(custom_find_package name) + find_package(${name} ${ARGN} + # Allow only Conan packages + NO_DEFAULT_PATH + PATHS ${CMAKE_PREFIX_PATH} + ) + string(TOUPPER ${name} name_upper) + set(${name_upper}_FOUND TRUE) + set(${name_upper}_VERSION_STRING ${${name}_VERSION_STRING}) + set(${name_upper}_INCLUDE_DIRS ${${name}_INCLUDE_DIRS}) + set(${name_upper}_INCLUDE_DIR ${${name}_INCLUDE_DIR}) + set(${name_upper}_LIBRARIES ${${name}_LIBRARIES}) + set(${name_upper}_DEFINITIONS ${${name}_DEFINITIONS}) + unset(name_upper) +endmacro() + +custom_find_package(Boost REQUIRED) +custom_find_package(BZip2 REQUIRED) +custom_find_package(EXPAT REQUIRED) +custom_find_package(lua REQUIRED) +custom_find_package(TBB REQUIRED) +custom_find_package(Osmium REQUIRED) +link_libraries(libosmium::libosmium) + +set(Boost_CHRONO_LIBRARY Boost::chrono) +set(Boost_DATE_TIME_LIBRARY Boost::date_time) +set(Boost_FILESYSTEM_LIBRARY Boost::filesystem) +set(Boost_IOSTREAMS_LIBRARY Boost::iostreams) +set(Boost_REGEX_LIBRARY Boost::regex) +set(Boost_SYSTEM_LIBRARY Boost::system Boost::program_options) +set(Boost_THREAD_LIBRARY Boost::thread) +set(Boost_ZLIB_LIBRARY ZLIB::ZLIB) + +# unvendored deps +custom_find_package(microtar REQUIRED) +link_libraries(microtar::microtar) + +custom_find_package(mapbox-variant REQUIRED) +link_libraries(mapbox-variant::mapbox-variant) + +custom_find_package(mapbox-geometry REQUIRED) +link_libraries(mapbox-geometry::mapbox-geometry) + +custom_find_package(fmt REQUIRED) +link_libraries(fmt::fmt) + +custom_find_package(RapidJSON REQUIRED) +link_libraries(rapidjson) + +custom_find_package(FlatBuffers REQUIRED) +if(TARGET flatbuffers::flatbuffers_shared) + link_libraries(flatbuffers::flatbuffers_shared) +else() + link_libraries(flatbuffers::flatbuffers) +endif() + +custom_find_package(sol2 REQUIRED) +link_libraries(sol2::sol2) diff --git a/recipes/osrm/all/conandata.yml b/recipes/osrm/all/conandata.yml new file mode 100644 index 0000000000000..cbb0bf26accf2 --- /dev/null +++ b/recipes/osrm/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "5.27.1": + url: "https://github.com/Project-OSRM/osrm-backend/archive/refs/tags/v5.27.1.tar.gz" + sha256: "52391580e0f92663dd7b21cbcc7b9064d6704470e2601bf3ec5c5170b471629a" diff --git a/recipes/osrm/all/conanfile.py b/recipes/osrm/all/conanfile.py new file mode 100644 index 0000000000000..4eda0a22960f5 --- /dev/null +++ b/recipes/osrm/all/conanfile.py @@ -0,0 +1,191 @@ +import os + +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.env import VirtualBuildEnv +from conan.tools.files import copy, export_conandata_patches, get, replace_in_file, rmdir, save, \ + apply_conandata_patches, rename, rm +from conan.tools.scm import Version + +required_conan_version = ">=1.53.0" + + +class OsrmConan(ConanFile): + name = "osrm" + description = "Open Source Routing Machine: high performance routing engine designed to run on OpenStreetMap data." + license = "BSD-2-Clause" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://project-osrm.org/" + topics = ("routing", "routing-engine", "map-matching", "traveling-salesman", "isochrones", "osm", "openstreetmap") + + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "build_tools": [True, False], + "build_routed": [True, False], + "enable_assertions": [True, False], + "enable_lto": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + "build_tools": False, + "build_routed": False, + "enable_assertions": False, + "enable_lto": False, + } + options_description = { + "build_tools": "Build OSRM tools", + "build_routed": "Build osrm-routed HTTP server", + "enable_assertions": "Use assertions in release mode", + "enable_lto": "Use LTO if available", + } + + @property + def _min_cppstd(self): + return 17 + + @property + def _compilers_minimum_version(self): + return { + "gcc": "8", + "clang": "7", + "apple-clang": "12", + "Visual Studio": "16", + "msvc": "192", + } + + def export_sources(self): + export_conandata_patches(self) + copy(self, "conan_deps.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src")) + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + if self.settings.build_type == "Debug": + del self.options.enable_assertions + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + self.options["osmium"].pbf = True + self.options["osmium"].xml = True + self.options["osmium"].geos = False + self.options["osmium"].gdal = False + self.options["osmium"].proj = False + self.options["osmium"].lz4 = False + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + self.requires("boost/1.84.0", transitive_headers=True, transitive_libs=True) + self.requires("bzip2/1.0.8") + self.requires("expat/[>=2.6.2 <3]") + self.requires("libosmium/2.20.0") + self.requires("lua/5.4.6") + self.requires("onetbb/2021.12.0") + self.requires("zlib/1.3.1") + # unvendored deps + self.requires("flatbuffers/1.12.0", transitive_headers=True, transitive_libs=True) # newer versions are not compatible + self.requires("fmt/10.2.1") + self.requires("mapbox-geometry/2.0.3") + self.requires("mapbox-variant/1.2.0", transitive_headers=True) + self.requires("microtar/0.1.0") + self.requires("rapidjson/cci.20230929") + self.requires("sol2/3.3.1") + # TODO + # self.requires("mapbox-cheap-ruler/0") + # self.requires("vtzero/0") + + def validate(self): + if self.settings.compiler.cppstd: + check_min_cppstd(self, self._min_cppstd) + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and Version(self.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." + ) + + if not self.dependencies["libosmium"].options.pbf or not self.dependencies["libosmium"].options.xml: + raise ConanInvalidConfiguration("libosmium must be built with PBF and XML support") + + def build_requirements(self): + self.tool_requires("cmake/[>=3.18 <4]") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.cache_variables["CMAKE_PROJECT_OSRM_INCLUDE"] = "conan_deps.cmake" + tc.cache_variables["ENABLE_CONAN"] = False + tc.cache_variables["BUILD_TOOLS"] = self.options.build_tools + tc.cache_variables["BUILD_ROUTED"] = self.options.build_routed + tc.cache_variables["ENABLE_ASSERTIONS"] = self.options.get_safe("enable_assertions", False) + tc.cache_variables["ENABLE_LTO"] = self.options.enable_lto + tc.cache_variables["CMAKE_DISABLE_FIND_PACKAGE_Doxygen"] = True + tc.generate() + tc = CMakeDeps(self) + tc.generate() + tc = VirtualBuildEnv(self) + tc.generate(scope="build") + + def _patch_source(self): + apply_conandata_patches(self) + + # Disable subdirs + save(self, os.path.join(self.source_folder, "unit_tests", "CMakeLists.txt"), "") + save(self, os.path.join(self.source_folder, "src", "benchmarks", "CMakeLists.txt"), "") + + # Fix an irrelevant generator expression error during .pc file generation + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), + '"$"', '"${engine_lib}"') + + # Disable vendored deps + for subdir in self.source_path.joinpath("third_party").iterdir(): + if subdir.name not in ["vtzero", "microtar"] and not subdir.name.startswith("cheap-ruler"): + rmdir(self, subdir) + save(self, subdir.joinpath("CMakeLists.txt"), "") + replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), " $", "") + + def build(self): + self._patch_source() + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, "LICENSE.TXT", self.source_folder, os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() + rename(self, os.path.join(self.package_folder, "share"), + os.path.join(self.package_folder, "res")) + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + rm(self, "*.pdb", self.package_folder, recursive=True) + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "LibOSRM") + self.cpp_info.set_property("cmake_target_name", "LibOSRM::LibOSRM") + self.cpp_info.set_property("pkg_config_name", "libosrm") + + self.cpp_info.includedirs.append(os.path.join("include", "osrm")) + self.cpp_info.resdirs = ["res"] + self.cpp_info.libs = [ + "osrm", + "osrm_contract", + "osrm_customize", + "osrm_extract", + "osrm_guidance", + "osrm_partition", + "osrm_store", + "osrm_update", + ] + + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs.extend(["m", "pthread", "rt"]) diff --git a/recipes/osrm/all/test_package/CMakeLists.txt b/recipes/osrm/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..577b840186fe4 --- /dev/null +++ b/recipes/osrm/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(LibOSRM REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE LibOSRM::LibOSRM) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) diff --git a/recipes/osrm/all/test_package/conanfile.py b/recipes/osrm/all/test_package/conanfile.py new file mode 100644 index 0000000000000..ef5d7042163ec --- /dev/null +++ b/recipes/osrm/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +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/osrm/all/test_package/test_package.cpp b/recipes/osrm/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..3f42c76ba7a67 --- /dev/null +++ b/recipes/osrm/all/test_package/test_package.cpp @@ -0,0 +1,13 @@ +#include +#include +#include +#include +#include + +int main() +{ + using namespace osrm; + RouteParameters params; + params.coordinates.push_back({util::FloatLongitude{7.419758}, util::FloatLatitude{43.731142}}); + engine::api::ResultT result = json::Object(); +} diff --git a/recipes/osrm/config.yml b/recipes/osrm/config.yml new file mode 100644 index 0000000000000..253a31bc93236 --- /dev/null +++ b/recipes/osrm/config.yml @@ -0,0 +1,3 @@ +versions: + "5.27.1": + folder: all From a459f3e33dfb3a50f8022804688c69b2d3cb689c Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 16 Oct 2024 09:10:02 +0300 Subject: [PATCH 2/2] osrm: add missing includes, disable some -Werror failures --- recipes/osrm/all/conanfile.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/recipes/osrm/all/conanfile.py b/recipes/osrm/all/conanfile.py index 4eda0a22960f5..d550c4c9a03b5 100644 --- a/recipes/osrm/all/conanfile.py +++ b/recipes/osrm/all/conanfile.py @@ -1,4 +1,5 @@ import os +from pathlib import Path from conan import ConanFile from conan.errors import ConanInvalidConfiguration @@ -129,6 +130,14 @@ def generate(self): tc.cache_variables["ENABLE_ASSERTIONS"] = self.options.get_safe("enable_assertions", False) tc.cache_variables["ENABLE_LTO"] = self.options.enable_lto tc.cache_variables["CMAKE_DISABLE_FIND_PACKAGE_Doxygen"] = True + if self.settings.compiler in ["gcc", "clang", "apple-clang"]: + # TODO: should probably be fixed instead + # include/sol/stack_field.hpp:116:61: error: array subscript ‘const char [30][0]’ is partly outside array bounds of ‘const char [18]’ [-Werror=array-bounds=] + tc.extra_cxxflags.append("-Wno-array-bounds") + # Disable -Werror=deprecated-declarations due to std::is_pod in C++20 + tc.extra_cxxflags.append("-Wno-deprecated-declarations") + # include/updater/csv_file_parser.hpp:108:45: error: top-level comma expression in array subscript is deprecated [-Werror=comma-subscript] + tc.extra_cxxflags.append("-Wno-comma-subscript") tc.generate() tc = CMakeDeps(self) tc.generate() @@ -153,6 +162,17 @@ def _patch_source(self): save(self, subdir.joinpath("CMakeLists.txt"), "") replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"), " $", "") + # Add missing includes. + # TODO: submit upstream + path = Path(self.source_folder, "include", "util", "coordinate.hpp") + path.write_text("#include \n" + path.read_text()) + path = Path(self.source_folder, "src", "util", "opening_hours.cpp") + path.write_text("#include \n" + path.read_text()) + path = Path(self.source_folder, "include", "util", "query_heap.hpp") + path.write_text("#include \n" + path.read_text()) + path = Path(self.source_folder, "include", "extractor", "suffix_table.hpp") + path.write_text("#include \n" + path.read_text()) + def build(self): self._patch_source() cmake = CMake(self)