Last active
November 18, 2022 06:33
-
-
Save kurotych/0bb94e906fc116f14a5f5060b2e6ef93 to your computer and use it in GitHub Desktop.
How to check linux kernel version in cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 useLINUX_KERNEL_VERSION
instead, .e.g.