Skip to content

linux/CMakeLists.txt: support offline/sandboxed builds via OBJECTBOX_PREBUILT_DIR #808

Description

@o-murphy

Is there an existing issue?

Use case

objectbox_flutter_libs downloads libobjectbox.so at CMake configure time via
FetchContent_Populate. This makes it impossible to build in any network-isolated
environment — Flatpak/Flathub sandboxes, NixOS, Gentoo, Guix, and any distro build
system that restricts network access during the build.

The usual cmake workaround — setting FETCHCONTENT_SOURCE_DIR_OBJECTBOX-DOWNLOAD
has no effect here. FetchContent_Populate (the pre-3.14 deprecated API) internally
spawns a cmake subbuild: a separate cmake process. Cache variables set in the
parent do not propagate to that subbuild. This is a documented cmake limitation.

Proposed solution

Check a cmake variable OBJECTBOX_PREBUILT_DIR before calling FetchContent_Populate.
If the variable points to an already-extracted archive, skip the download entirely:

if(DEFINED OBJECTBOX_PREBUILT_DIR AND EXISTS "${OBJECTBOX_PREBUILT_DIR}/lib/libobjectbox.so")
    set(objectbox-download_SOURCE_DIR "${OBJECTBOX_PREBUILT_DIR}")
else()
    FetchContent_GetProperties(objectbox-download)
    if(NOT objectbox-download_POPULATED)
        FetchContent_Populate(objectbox-download)
    endif()
endif()

Distro packagers would pass:

-DOBJECTBOX_PREBUILT_DIR=/path/to/extracted/objectbox-c

Describe alternatives you've considered

Current workaround

We maintain a local patch in the Flatpak manifest for
ebalistyka-app that checks a hardcoded
relative path. It works but is fragile and app-specific.

Additional context

This patch proposes no breaking changes

Flathub has growing Flutter adoption. Every Flutter app using objectbox needs this
patch to pass Flathub CI (which runs flatpak-builder --sandbox with no network).
A one-line upstream fix lets all downstream packagers drop their local patches.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions