Skip to content

Instantly share code, notes, and snippets.

@kurotych
Last active November 18, 2022 06:33
Show Gist options
  • Save kurotych/0bb94e906fc116f14a5f5060b2e6ef93 to your computer and use it in GitHub Desktop.
Save kurotych/0bb94e906fc116f14a5f5060b2e6ef93 to your computer and use it in GitHub Desktop.
How to check linux kernel version in cmake
execute_process(COMMAND uname -r OUTPUT_VARIABLE UNAME_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)
message(-- " Kernel version: " ${UNAME_RESULT})
string(REGEX MATCH "[0-9]+.[0-9]+" LINUX_KERNEL_VERSION ${UNAME_RESULT})
if (LINUX_KERNEL_VERSION VERSION_LESS 3.8)
message(FATAL_ERROR "Linux kernel version should be greater than 3.8")
endif()
@Bassem-Ramzy
Copy link

Very good usage of REGEX.
I faced an exception in the comparison:
When kernel version is 5.13, which is greater than 5.6, this LESS comparison is TRUE, seems it compares strings "5.1_somthing_" with "5.6". It's better to use LINUX_KERNEL_VERSION instead, .e.g.

if(LINUX_KERNEL_VERSION VERSION_LESS 3.8)

@kurotych
Copy link
Author

kurotych commented Feb 7, 2022

Hello @Bassem-Ramzy thanks for the hint! The gist was edited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment