Skip to content

Instantly share code, notes, and snippets.

@likema
Last active October 13, 2023 09:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save likema/f5c04dad837d2f5068ae7a8860c180e7 to your computer and use it in GitHub Desktop.
Save likema/f5c04dad837d2f5068ae7a8860c180e7 to your computer and use it in GitHub Desktop.
CMake macro to detect glibc version by filename.
# - Check glibc version
# CHECK_GLIBC_VERSION()
#
# Once done this will define
#
# GLIBC_VERSION - glibc version
#
MACRO (CHECK_GLIBC_VERSION)
EXECUTE_PROCESS (
COMMAND ${CMAKE_C_COMPILER} -print-file-name=libc.so.6
OUTPUT_VARIABLE GLIBC
OUTPUT_STRIP_TRAILING_WHITESPACE)
GET_FILENAME_COMPONENT (GLIBC ${GLIBC} REALPATH)
GET_FILENAME_COMPONENT (GLIBC_VERSION ${GLIBC} NAME)
STRING (REPLACE "libc-" "" GLIBC_VERSION ${GLIBC_VERSION})
STRING (REPLACE ".so" "" GLIBC_VERSION ${GLIBC_VERSION})
IF (NOT GLIBC_VERSION MATCHES "^[0-9.]+$")
MESSAGE (FATAL_ERROR "Unknown glibc version: ${GLIBC_VERSION}")
ENDIF (NOT GLIBC_VERSION MATCHES "^[0-9.]+$")
ENDMACRO (CHECK_GLIBC_VERSION)
@likema
Copy link
Author

likema commented Apr 25, 2019

Check glibc version if it is composed of 0, ..., 9 and .

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