Skip to content

fix(cmake): osrm backend fetch content patch#7528

Open
ctriley wants to merge 1 commit intoProject-OSRM:masterfrom
mobility-solutions-inc:ctriley/osrm-backend-fetchcontent
Open

fix(cmake): osrm backend fetch content patch#7528
ctriley wants to merge 1 commit intoProject-OSRM:masterfrom
mobility-solutions-inc:ctriley/osrm-backend-fetchcontent

Conversation

@ctriley
Copy link
Copy Markdown

@ctriley ctriley commented May 6, 2026

Summary

Improve OSRM's CMake behavior when it is consumed as a subproject through
add_subdirectory() or FetchContent.

This keeps the default standalone OSRM build behavior intact, while making the
library easier to embed in larger CMake projects that already provide
dependencies through standard package config files or imported targets.

Motivation

OSRM now primarily expects dependencies to come from vcpkg manifest mode, but
CMake superprojects often provide the same dependencies through other package
managers or pre-existing imported targets. In those builds, a few assumptions in
the current CMake setup make embedding OSRM harder than necessary:

  • tests and benchmarks are always added to the subproject target graph;
  • some dependency include directories are only read from legacy variables;
  • some package configs expose include paths through imported targets instead;
  • some FlatBuffers package configs define flatbuffers_generate_headers
    directly rather than placing BuildFlatBuffers.cmake next to the config file.

These are not OSRM source-level issues. They are CMake integration issues that
show up when OSRM is used as a library inside a larger build.

Changes

  • Add OSRM_BUILD_TESTING and OSRM_BUILD_BENCHMARKS.

    • Defaults remain ON for standalone OSRM builds.
    • Defaults are OFF when OSRM is included as a subproject.
    • Superprojects can explicitly enable either option if they want OSRM tests or
      benchmark targets.
  • Make dependency include harvesting provider-neutral.

    • Rename the internal header-target list away from vcpkg-specific wording.
    • Continue supporting the existing vcpkg targets.
    • Also collect include dirs from flatbuffers::libflatbuffers and TBB::tbb.
  • Add LibArchive imported-target include propagation.

    • If LibArchive::LibArchive exposes include directories, add them to
      OSRM's dependency include list.
  • Guard FlatBuffers helper inclusion.

    • Only include ${flatbuffers_DIR}/BuildFlatBuffers.cmake when
      flatbuffers_generate_headers is not already defined.

Why This Is Safe

For normal standalone OSRM builds, tests and benchmarks still default to being
included. Existing vcpkg-based builds continue to use the same package config
flow and the same imported targets.

For subproject builds, this reduces target graph pollution and avoids requiring
parent projects to patch OSRM just to prevent tests or benchmarks from being
configured. The include-directory changes are additive and only use properties
from targets that already exist.

Validation

  • Verified the patch applies cleanly to v26.5.0.
  • Verified git diff --check passes.
  • Verified the change in a superproject build that consumes OSRM through
    FetchContent while dependencies are supplied by package config/imported
    targets.

@ctriley ctriley changed the title osrm backend fetch content patch fix(cmake): osrm backend fetch content patch May 6, 2026
@ctriley ctriley changed the title fix(cmake): osrm backend fetch content patch fix(cmake)!: osrm backend fetch content patch May 6, 2026
@ctriley ctriley changed the title fix(cmake)!: osrm backend fetch content patch fix(cmake): osrm backend fetch content patch May 6, 2026
@DennisOSRM DennisOSRM requested a review from Copilot May 7, 2026 06:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves OSRM’s CMake behavior when consumed as a subproject (via add_subdirectory() / FetchContent), aiming to keep standalone builds unchanged while reducing integration friction in superprojects that provide dependencies via package configs/imported targets.

Changes:

  • Add OSRM_BUILD_TESTING and OSRM_BUILD_BENCHMARKS, defaulting to OFF for subproject builds and ON for standalone builds.
  • Make dependency include-directory harvesting more provider-neutral (renaming internal variables and adding additional imported targets).
  • Guard inclusion of FlatBuffers’ BuildFlatBuffers.cmake based on whether flatbuffers_generate_headers is already defined.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CMakeLists.txt
Comment on lines +426 to +427
flatbuffers::flatbuffers flatbuffers::libflatbuffers
TBB::tbb)
@DennisOSRM
Copy link
Copy Markdown
Collaborator

The comment from our electric overlord seems to have a point. please have a look at the order of inclusion and discovery of tbb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants