Skip to content

Build/CMake: cmake_minimum_required(VERSION 3.23) blocks Ubuntu 22.04 / RHEL 8 / ROS 2 Humble (CMake 3.20–3.22) #156

Backlog

Description

@clockblocker

Part of #138
Popularity: 2/7 corpus consumers (fanuc-libs, moqx)

Problem

reflect-cpp's top-level CMakeLists.txt unconditionally declares cmake_minimum_required(VERSION 3.23), which fails configuration on widely deployed LTS Linux environments — Ubuntu 22.04 LTS / ROS 2 Humble ship CMake 3.22.1, and RHEL/CentOS 8 ship CMake 3.20. Downstream consumers supporting those platforms must either vendor a CMake downgrade patch (reflectcpp.patch) or force a higher CMake floor and bootstrap CMake from PyPI in their install scripts.

Observed Downstream Workarounds

FANUC-CORPORATION/fanuc_driver (da5db3f6)

  • fanuc_libs/dependencies/reflectcpp.patch#L1-L10: patches reflect-cpp's CMakeLists.txt solely to downgrade the minimum CMake version from 3.23 to 3.22:
    diff --git a/CMakeLists.txt b/CMakeLists.txt
    index d9f92f0..5f8e98c 100644
    --- a/CMakeLists.txt
    +++ b/CMakeLists.txt
    @@ -1,4 +1,4 @@
    -cmake_minimum_required(VERSION 3.23)
    +cmake_minimum_required(VERSION 3.22)
    
     option(REFLECTCPP_BUILD_SHARED "Build shared library" ${BUILD_SHARED_LIBS})
     option(REFLECTCPP_INSTALL "Install reflect cpp" OFF)
  • fanuc_libs/CMakeLists.txt#L6 and #L47-L53 (plus fanuc_libs/dependencies/apply_patch.bash#L1-L5): routes the local submodule through FetchContent_Declare with PATCH_COMMAND so the patch can be applied without dirtying the git submodule checkout:
    # Build the reflectcpp library
    FetchContent_Declare(
        reflect-cpp
        GIT_REPOSITORY ${CMAKE_SOURCE_DIR}/dependencies/reflect-cpp
        GIT_TAG 2a0fdeabe35bdab0e07e05d4f869ca88bd6d2b8c
        PATCH_COMMAND bash ${CMAKE_SOURCE_DIR}/dependencies/apply_patch.bash ${CMAKE_SOURCE_DIR}/dependencies/reflectcpp.patch
    )
  • .github/workflows/ci.yaml#L50-L53: as a knock-on consequence of FetchContent cloning from the local submodule directory inside Docker CI (industrial_ci), CI must disable Git's safe-directory ownership check globally:
    # Bypass "dubious ownership" error during fetch content of reflect-cpp.
    # https://github.blog/open-source/git/highlights-from-git-2-36/#stricter-repository-ownership-checks
    - shell: bash
      run: git config --global --add safe.directory '*'

openmoq/moqx (60bab7f13925acbaf578670223e660d71e891547)

moqx bumps its project-wide CMake floor to 3.23 solely because of reflect-cpp, and maintains a dedicated ensure_recent_cmake() helper in its system dependency installer to bootstrap CMake 3.x from PyPI on LTS Linux distros (Ubuntu 22.04 ships CMake 3.22; RHEL/CentOS 8 ship CMake 3.20):

  • CMakeLists.txt#L1:
    cmake_minimum_required(VERSION 3.23)  # reflect-cpp requires >= 3.23
  • BUILD.md#L11-L14:

    scripts/install-system-deps.sh fetches a current CMake from PyPI when the distro's is older (e.g. Ubuntu 22.04 ships 3.22, but reflect-cpp needs 3.23).

  • scripts/install-system-deps.sh#L108-L132 & scripts/install-system-deps.sh#L160:
    # reflect-cpp (a moqx dependency) needs CMake >= 3.23, newer than the 3.22 that
    # e.g. Ubuntu 22.04 ships. Install a current CMake from PyPI when the distro's is
    # too old, rather than requiring users to add a third-party apt repo.
    ensure_recent_cmake() {
        local have min=3.23
        ...
        $SUDO timeout 600 pip3 install --upgrade 'cmake<4' --break-system-packages 2>/dev/null           || $SUDO timeout 600 pip3 install --upgrade 'cmake<4'
    }
    ...
        ensure_recent_cmake   # RHEL/CentOS 8 ship cmake 3.20 (< 3.23)

Root Cause in reflect-cpp

CMakeLists.txt#L1 requires CMake 3.23 exclusively for target_sources(reflectcpp PUBLIC FILE_SET reflectcpp_headers TYPE HEADERS ...) inside the optional if (REFLECTCPP_INSTALL) block (CMakeLists.txt#L553-L565). Embedded FetchContent/CPM/add_subdirectory consumers with REFLECTCPP_INSTALL=OFF do not execute any CMake 3.23 feature at all, yet CMake 3.20–3.22 aborts immediately on line 1.

Suggested Direction / Fix

  • Lower cmake_minimum_required to 3.20 (or 3.21/3.22, depending on PROJECT_IS_TOP_LEVEL usage).
  • In the if (REFLECTCPP_INSTALL) block, either gate FILE_SET on if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.23) with an install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) fallback for older CMake 3.x, or use install(DIRECTORY ...) unconditionally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    known-downstream-workarounds

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions