diff options
author | Giuliano Procida <gprocida@google.com> | 2024-05-10 07:27:23 +0100 |
---|---|---|
committer | Giuliano Procida <gprocida@google.com> | 2024-05-10 07:33:39 +0100 |
commit | de821f47d1e211ca6981436dece5fed6b0aa97d2 (patch) | |
tree | c92a78b1438171077d4fd100747c21cdf9164a25 | |
parent | ff9af131ee723f76c33297a17557d1cd07f8fcc4 (diff) | |
download | stg-de821f47d1e211ca6981436dece5fed6b0aa97d2.tar.gz |
CMake build: add check for Linux UAPI headers
The header `<linux/btf.h>` contains BTF node definitions.
PiperOrigin-RevId: 632388465
Change-Id: I51cd5937e35536e9224baebe8d658bd98791d36b
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | cmake/FindLinuxUAPI.cmake | 55 |
2 files changed, 56 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 38bb294..17fd062 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) find_package(LibElf REQUIRED) find_package(LibDw REQUIRED) find_package(LibXml2 REQUIRED) +find_package(LinuxUAPI REQUIRED) find_package(Protobuf REQUIRED) if(NOT Protobuf_PROTOC_EXECUTABLE) diff --git a/cmake/FindLinuxUAPI.cmake b/cmake/FindLinuxUAPI.cmake new file mode 100644 index 0000000..b662f3e --- /dev/null +++ b/cmake/FindLinuxUAPI.cmake @@ -0,0 +1,55 @@ +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +# Copyright 2024 Google LLC +# +# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. You may +# obtain a copy of the License at +# +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# Author: Giuliano Procida + +#[=======================================================================[.rst: +FindLinuxUAPI +------------- + +Finds the Linux UAPI headers. + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``LinuxUAPI_FOUND`` + True if the system has the Linux UAPI headers. +``LinuxUAPI_INCLUDE_DIR`` + The Linux UAPI include directory. +``LinuxUAPI_VERSION`` + The version of the Linux UAPI headers which were found. + +#]=======================================================================] + +find_path( + LinuxUAPI_INCLUDE_DIR + linux/version.h +) +mark_as_advanced(LinuxUAPI_INCLUDE_DIR) + +if(LinuxUAPI_INCLUDE_DIR) + file(READ "${LinuxUAPI_INCLUDE_DIR}/linux/version.h" _version_header) + string(REGEX REPLACE ".*#define LINUX_VERSION_MAJOR ([0-9]+).*#define LINUX_VERSION_PATCHLEVEL ([0-9]+).*#define LINUX_VERSION_SUBLEVEL ([0-9]+).*" "\\1.\\2.\\3" LinuxUAPI_VERSION "${_version_header}") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + LinuxUAPI + REQUIRED_VARS LinuxUAPI_INCLUDE_DIR + VERSION_VAR LinuxUAPI_VERSION +) |