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

osrm: new recipe #23734

Open
wants to merge 2 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
58 changes: 58 additions & 0 deletions recipes/osrm/all/conan_deps.cmake
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions recipes/osrm/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
211 changes: 211 additions & 0 deletions recipes/osrm/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import os
from pathlib import Path

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
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()
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"),
'"$<TARGET_LINKER_FILE:${engine_lib}>"', '"${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"), " $<TARGET_OBJECTS:MICROTAR>", "")

# Add missing includes.
# TODO: submit upstream
path = Path(self.source_folder, "include", "util", "coordinate.hpp")
path.write_text("#include <cstdint>\n" + path.read_text())
path = Path(self.source_folder, "src", "util", "opening_hours.cpp")
path.write_text("#include <cstdint>\n" + path.read_text())
path = Path(self.source_folder, "include", "util", "query_heap.hpp")
path.write_text("#include <cstdint>\n" + path.read_text())
path = Path(self.source_folder, "include", "extractor", "suffix_table.hpp")
path.write_text("#include <vector>\n" + path.read_text())

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"])
8 changes: 8 additions & 0 deletions recipes/osrm/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions recipes/osrm/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
13 changes: 13 additions & 0 deletions recipes/osrm/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <osrm/coordinate.hpp>
#include <osrm/engine_config.hpp>
#include <osrm/json_container.hpp>
#include <osrm/osrm.hpp>
#include <osrm/route_parameters.hpp>

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();
}
3 changes: 3 additions & 0 deletions recipes/osrm/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"5.27.1":
folder: all