2 Commits

Author SHA1 Message Date
Julien Olivain
b69fc85e66 support/misc/Buildroot-Initialize.cmake: make include optional
Buildroot commit [1] introduced a new Buildroot-Initialize.cmake file,
to mimic the upstream Linux-Initialize.cmake.

However, this upstream file was introduced in commit [2], which was
introduced in CMake 3.27.

When compiling a cmake package on a host with a cmake older than
version 3.27 (for example, the Buildroot Docker reference image has
cmake 3.25), the configuration fails with the error:

    CMake Error at /buildroot/output/host/share/buildroot/Platform/Buildroot-Initialize.cmake:1 (include):
      include could not find requested file:

        Platform/Linux-Initialize
    Call Stack (most recent call first):
      /usr/share/cmake-3.25/Modules/CMakeSystemSpecificInitialize.cmake:21 (include)
      CMakeLists.txt:20 (project)

CMake version < 3.27 is setting its LINUX predefine elsewhere (see
commit log of [1]), so this commit fixes the issue by simply making
the include optional. This will guarante thee cmake predefines will
be present in all the cases.

Fixes:
[1]

[1] ef9f0a07ed
[2] cc737ae829

Signed-off-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
2026-02-05 08:14:47 +01:00
Julien Olivain
ef9f0a07ed package/pkg-cmake.mk: add Platform/Buildroot-Initialize.cmake
Since commit [1] (core/pkg-cmake: provide our own platform
description), Buildroot is setting its own CMake platform
description. This description applies minor changes on top of
the CMake Linux platform, see [2] and [3]. The CMake system specific
script tries to include an initialization script, if present.
See [4].

Since in commit [1] we set the CMAKE_SYSTEM_NAME to "Buildroot"
(rather than "Linux"), CMake will search for a
"Platform/Buildroot-Initialize.cmake" which does not exist, and
continue normally, since the include is optional.

The "Platform/Linux-Initialize.cmake" file is the one setting the
LINUX [6] and UNIX [7] variables, which are expected to be true on
a linux compatible system. In Buildroot, it is currently not
included, so those variables are unset.

If a CMake package in Buildroot has a construct such as:

    if(LINUX)
        # ...do things...
    else()
        message(FATAL_ERROR "System not supported")
    endif()

It will fail at configuration time.

This situation happened when trying to add the btop++ package
in Buildroot. See [8].

Since the initial intent of commit [1] was to make the Buildroot
CMake system inherit from Linux plus some fixups, this commit simply
adds a Buildroot-Initialize.cmake file that includes the
Linux-Initialize.cmake one from CMake. This will have the effect
to properly define the LINUX and UNIX variables.

[1] c69b14fe2f
[2] https://gitlab.com/buildroot.org/buildroot/-/blob/2025.11/support/misc/Buildroot.cmake#L1-4
[3] https://cmake.org/cmake/help/v4.2/variable/CMAKE_SYSTEM_NAME.html
[4] https://gitlab.kitware.com/cmake/cmake/-/blob/v4.2.1/Modules/CMakeSystemSpecificInitialize.cmake#L35
[5] https://gitlab.kitware.com/cmake/cmake/-/blob/v4.2.1/Modules/Platform/Linux-Initialize.cmake
[6] https://cmake.org/cmake/help/v4.2/variable/LINUX.html
[7] https://cmake.org/cmake/help/v4.2/variable/UNIX.html
[8] https://github.com/aristocratos/btop/blob/v1.4.6/CMakeLists.txt#L76

Reported-by: Gilles Talis <gilles.talis@gmail.com>
Signed-off-by: Julien Olivain <ju.o@free.fr>
Tested-by: Gilles Talis <gilles.talis@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
2026-02-04 10:12:44 +01:00