Skip to content
Open
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
73 changes: 49 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ option(ENABLE_NODE_BINDINGS "Build NodeJs bindings" OFF)
option(ENABLE_PYTHON_BINDINGS "Build Python bindings" OFF)
option(ENABLE_SANITIZER "Use memory sanitizer for Debug build" OFF)

if(BUILD_AS_SUBPROJECT)
set(OSRM_BUILD_AUXILIARY_TARGETS_DEFAULT OFF)
else()
set(OSRM_BUILD_AUXILIARY_TARGETS_DEFAULT ON)
endif()

option(OSRM_BUILD_TESTING "Build OSRM test targets" ${OSRM_BUILD_AUXILIARY_TARGETS_DEFAULT})
option(OSRM_BUILD_BENCHMARKS "Build OSRM benchmark targets" ${OSRM_BUILD_AUXILIARY_TARGETS_DEFAULT})

# Dependencies are provided by vcpkg in manifest mode (see vcpkg.json).
# The vcpkg toolchain file is wired up via CMakePresets.json or by passing
# -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake.
Expand Down Expand Up @@ -346,8 +355,15 @@ if(OSRM_HAS_STD_FORMAT)
endif()

find_package(LibArchive REQUIRED)
add_dependency_includes(${LibArchive_INCLUDE_DIRS})
if(TARGET LibArchive::LibArchive)
get_target_property(_libarchive_includes LibArchive::LibArchive INTERFACE_INCLUDE_DIRECTORIES)
if(_libarchive_includes)
add_dependency_includes(${_libarchive_includes})
endif()
endif()

# Header-only libraries from vcpkg. Each provides a CMake CONFIG package.
# Header-only libraries consumed through CMake package configs.
find_package(fmt CONFIG REQUIRED)
# fmt is consumed header-only so OSRM targets don't need to link libfmt.
# Without this, LTO builds emit undefined references to fmt::v12::vformat,
Expand All @@ -357,13 +373,31 @@ add_compile_definitions(FMT_HEADER_ONLY)
find_package(RapidJSON CONFIG REQUIRED)
find_package(sol2 CONFIG REQUIRED)
find_package(flatbuffers CONFIG REQUIRED)
# TBB is linked later, but discover it here so the include-harvesting loop
# below can see TBB::tbb for OBJECT libraries that were already created.
find_package(TBB CONFIG REQUIRED)
# Always link the release build of TBB, even in Debug/Coverage configurations.
# vcpkg's debug TBB enables internal debug assertions (e.g. intrusive_list
# invariants) that trip during osrm-extract's test-data generation on
# ubuntu-24.04 under gcc-13. The master branch never hit this because it
# linked the system's release-only TBB. Do the same here.
foreach(_tbb_target TBB::tbb TBB::tbbmalloc TBB::tbbmalloc_proxy)
if(TARGET ${_tbb_target})
set_target_properties(${_tbb_target} PROPERTIES
MAP_IMPORTED_CONFIG_DEBUG Release
MAP_IMPORTED_CONFIG_MINSIZEREL Release
MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release)
endif()
endforeach()

# Generate flatbuffers C++ headers from .fbs schemas at build time.
# This removes the need to commit pre-generated headers and pin the
# flatbuffers version — any compatible flatc will regenerate them.
# BuildFlatBuffers.cmake is shipped alongside flatbuffers-config.cmake
# but not on CMAKE_MODULE_PATH, so locate it via the package's own dir.
include("${flatbuffers_DIR}/BuildFlatBuffers.cmake")
# Some package configs define this helper command themselves instead of placing
# BuildFlatBuffers.cmake next to the generated config file.
if(NOT COMMAND flatbuffers_generate_headers)
include("${flatbuffers_DIR}/BuildFlatBuffers.cmake")
endif()
set(FLATBUFFERS_SCHEMAS
${CMAKE_CURRENT_SOURCE_DIR}/include/engine/api/flatbuffers/fbresult.fbs
${CMAKE_CURRENT_SOURCE_DIR}/include/engine/api/flatbuffers/route.fbs
Expand Down Expand Up @@ -401,12 +435,13 @@ include_directories(SYSTEM ${VTZERO_INCLUDE_DIR})
# target and push them into the directory-level include_directories, which
# DOES apply retroactively to earlier targets. Consumers (unit tests, etc.)
# inherit the same search paths via the directory.
set(_osrm_vcpkg_header_targets
set(_osrm_dependency_header_targets
fmt::fmt-header-only fmt::fmt
sol2::sol2
rapidjson RapidJSON::RapidJSON
flatbuffers::flatbuffers)
foreach(_dep IN LISTS _osrm_vcpkg_header_targets)
flatbuffers::flatbuffers flatbuffers::libflatbuffers
TBB::tbb)
Comment on lines +442 to +443
foreach(_dep IN LISTS _osrm_dependency_header_targets)
if(TARGET ${_dep})
get_target_property(_inc ${_dep} INTERFACE_INCLUDE_DIRECTORIES)
if(_inc)
Expand All @@ -426,20 +461,6 @@ endif()
# All dependencies below come from vcpkg (vcpkg.json). The vcpkg toolchain
# file exposes them via standard CMake find_package() / imported targets.
find_package(Boost 1.83 REQUIRED CONFIG COMPONENTS ${BOOST_COMPONENTS})
find_package(TBB CONFIG REQUIRED)
# Always link the release build of TBB, even in Debug/Coverage configurations.
# vcpkg's debug TBB enables internal debug assertions (e.g. intrusive_list
# invariants) that trip during osrm-extract's test-data generation on
# ubuntu-24.04 under gcc-13. The master branch never hit this because it
# linked the system's release-only TBB. Do the same here.
foreach(_tbb_target TBB::tbb TBB::tbbmalloc TBB::tbbmalloc_proxy)
if(TARGET ${_tbb_target})
set_target_properties(${_tbb_target} PROPERTIES
MAP_IMPORTED_CONFIG_DEBUG Release
MAP_IMPORTED_CONFIG_MINSIZEREL Release
MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release)
endif()
endforeach()
find_package(EXPAT REQUIRED)
find_package(BZip2 REQUIRED)
find_package(Lua 5.4 REQUIRED)
Expand Down Expand Up @@ -749,9 +770,13 @@ else()
endif()


# Modular build system: each directory registered here provides its own CMakeLists.txt
add_subdirectory(unit_tests)
add_subdirectory(src/benchmarks)
if(OSRM_BUILD_TESTING)
add_subdirectory(unit_tests)
endif()

if(OSRM_BUILD_BENCHMARKS)
add_subdirectory(src/benchmarks)
endif()

if (ENABLE_NODE_BINDINGS)
add_subdirectory(src/nodejs)
Expand Down
Loading