Skip to content

fix: build failures on CMake 4.x and OpenCL headers >= 3.0.16#1209

Open
rginon314 wants to merge 2 commits intoOpenKinect:masterfrom
rginon314:fix/modern-toolchain-build
Open

fix: build failures on CMake 4.x and OpenCL headers >= 3.0.16#1209
rginon314 wants to merge 2 commits intoOpenKinect:masterfrom
rginon314:fix/modern-toolchain-build

Conversation

@rginon314
Copy link
Copy Markdown

Build Failures on Modern Toolchains (CMake ≥ 4.0 + OpenCL ≥ 3.0.16)

Summary

Building libfreenect2 from source fails with two independent errors when using
CMake 4.x and a recent OpenCL ICD loader (opencl-icd-loader ≥ 3.0.16 / Khronos
vendor headers that include cl_ext.h ≥ 3.0.16).


Environment

Component Version
OS Manjaro Linux (rolling, Arch-based)
CMake 4.2.3
GCC 15.2.1
OpenCL headers via opencl-headers (cl_ext.h defining CL_ICDL_VERSION)
libusb 1.0.x
libfreenect2 commit fd64c5d (current HEAD of master)

Error 1 — cmake_minimum_required version too old (CMake ≥ 4.0)

Symptom

CMake Error at CMakeLists.txt:1 (CMAKE_MINIMUM_REQUIRED):
  Compatibility with CMake < 3.5 has been removed from CMake.
  Update the VERSION argument <min> value.

Root cause

Three CMakeLists.txt files declare cmake_minimum_required(VERSION 2.8.12.1),
which CMake 4.0+ explicitly rejects.

Affected files:

  • CMakeLists.txt
  • examples/CMakeLists.txt
  • tools/streamer_recorder/CMakeLists.txt

Fix

# Before
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12.1)

# After
cmake_minimum_required(VERSION 3.5)

Error 2 — CL_ICDL_VERSION macro collision (OpenCL headers ≥ 3.0.16)

Symptom

src/opencl_depth_packet_processor.cpp:254:15:
  error: expected unqualified-id before numeric constant
    const int CL_ICDL_VERSION = 2;

(Same error in src/opencl_kde_depth_packet_processor.cpp.)

Root cause

cl_ext.h (Khronos OpenCL headers ≥ 3.0.16) now defines:

#define CL_ICDL_VERSION  2

This macro expands the variable name in the local declaration
const int CL_ICDL_VERSION = 2;, turning it into const int 2 = 2;, which
is a hard compile error.

Affected files:

  • src/opencl_depth_packet_processor.cpp (line ~254)
  • src/opencl_kde_depth_packet_processor.cpp (line ~262)

Fix

Undefine the macro immediately before the local variable declaration:

// Before
const int CL_ICDL_VERSION = 2;

// After
#ifdef CL_ICDL_VERSION
#undef CL_ICDL_VERSION
#endif
const int CL_ICDL_VERSION = 2;

Steps to reproduce

git clone https://github.com/OpenKinect/libfreenect2
cd libfreenect2
mkdir build && cd build
cmake ..         # → Error 1 (CMake 4.x)
# After manually bumping cmake_minimum_required to 3.5:
make -j$(nproc)  # → Error 2 (CL_ICDL_VERSION)

Patch

See the accompanying pull request for a minimal two-commit fix.

CMake 4.0 removed compatibility with versions < 3.5, causing a hard
error when configuring the build. Update all three CMakeLists.txt files
from VERSION 2.8.12.1 to VERSION 3.5.

Fixes build on CMake >= 4.0 (e.g. CMake 4.2.x).
OpenCL headers >= 3.0.16 (cl_ext.h) define CL_ICDL_VERSION as a
preprocessor macro with value 2. This conflicts with the local variable
declaration 'const int CL_ICDL_VERSION = 2;' in both OpenCL processor
files, causing a compile error:

  error: expected unqualified-id before numeric constant

Add a conditional #undef before the local declaration to resolve the
macro collision on modern OpenCL header versions.

Affected files:
- src/opencl_depth_packet_processor.cpp
- src/opencl_kde_depth_packet_processor.cpp
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.

1 participant