-
-
Save LeSpocky/3f810f681a829c3f28165942471cd037 to your computer and use it in GitHub Desktop.
CMake macro to detect glibc version by filename.
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
#[=======================================================================[.rst: | |
glibc | |
----- | |
Check glibc version. | |
Result variables | |
^^^^^^^^^^^^^^^^ | |
``GLIBC_VERSION`` | |
glibc version. | |
``GLIBC_VERSION_MAJOR`` | |
glibc major version. | |
``GLIBC_VERSION_MINOR`` | |
glibc minor version. | |
#]=======================================================================] | |
macro(CHECK_GLIBC_VERSION) | |
find_path(_glibc_include_dir NAMES features.h) | |
file(STRINGS "${_glibc_include_dir}/features.h" _glibc_major_line | |
REGEX "^#define[ \t]+__GLIBC__[ \t]+[0-9]+$") | |
string(REGEX REPLACE "#define[ \t]+__GLIBC__[ \t]+([0-9]+)" "\\1" | |
GLIBC_VERSION_MAJOR "${_glibc_major_line}") | |
unset(_glibc_major_line) | |
file(STRINGS "${_glibc_include_dir}/features.h" _glibc_minor_line | |
REGEX "^#define[ \t]+__GLIBC_MINOR__[ \t]+[0-9]+$") | |
string(REGEX REPLACE "#define[ \t]+__GLIBC_MINOR__[ \t]+([0-9]+)" "\\1" | |
GLIBC_VERSION_MINOR "${_glibc_minor_line}") | |
unset(_glibc_minor_line) | |
unset(_glibc_include_dir CACHE) | |
set(GLIBC_VERSION "${GLIBC_VERSION_MAJOR}.${GLIBC_VERSION_MINOR}") | |
if(NOT GLIBC_VERSION MATCHES "^[0-9.]+$") | |
message(FATAL_ERROR "Unknown glibc version: ${GLIBC_VERSION}") | |
endif() | |
endmacro() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment