-
-
Save likema/f5c04dad837d2f5068ae7a8860c180e7 to your computer and use it in GitHub Desktop.
# - 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) |
This will fail if the base file is libc.so.6
... which it often is.
This will fail if the base file is
libc.so.6
... which it often is.
What do you mean?
What do you mean?
I mean, that the filename doesn't include the glibc version - and this module assumes that it does and tries to parse the name to get the version.
Any suggestions ?
Well, one thing which often works - not sure whether it always works - is run libc.so.6
. Yes, it's typically executable - and prints version information.
It seems STRING (REPLACE "libc-" "" GLIBC_VERSION ${GLIBC_VERSION})
causes the problem.
I resolved this by removing the dash character like STRING (REPLACE "libc" "" GLIBC_VERSION ${GLIBC_VERSION})
.
I'm not sure whether this is acceptable for all versions of GLIBC.
It seems
STRING (REPLACE "libc-" "" GLIBC_VERSION ${GLIBC_VERSION})
causes the problem. I resolved this by removing the dash character likeSTRING (REPLACE "libc" "" GLIBC_VERSION ${GLIBC_VERSION})
. I'm not sure whether this is acceptable for all versions of GLIBC.
Which distribution is your OS ? Ubuntu or Redhat ?
Can you show me ?
realpath `gcc -print-file-name=libc.so.6`
Well, one thing which often works - not sure whether it always works - is run
libc.so.6
. Yes, it's typically executable - and prints version information.
It does not work for cross compiler, such as aarch64
Maybe you can implement CMake macro like
objdump -T `gcc -print-file-name=libc.so.6` \
| grep -o 'GLIBC_[0-9]\+\(\.[0-9]\+\)*' \
| sort -ruV \
| head -1
Well, one thing which often works - not sure whether it always works - is run
libc.so.6
. Yes, it's typically executable - and prints version information.It does not work for cross compiler, such as aarch64
Maybe you can implement CMake macro like
objdump -T `gcc -print-file-name=libc.so.6` \ | grep -o 'GLIBC_[0-9]\+\(\.[0-9]\+\)*' \ | sort -ruV \ | head -1
realpath `gcc -print-file-name=libc.so.6`
/usr/lib/x86_64-linux-gnu/libc.so.6
Or adding one more line would be fine, like this.
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 "libc" "" GLIBC_VERSION ${GLIBC_VERSION}) # added
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)
Even added this line, it seems that only the major version of glibc
can be extracted
MACRO (CHECK_GLIBC_VERSION)
message("Checking 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)
EXECUTE_PROCESS (
COMMAND ${GLIBC}
OUTPUT_VARIABLE GLIBC_OUTPUT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
STRING (REGEX MATCH "release version ([0-9]+\\.[0-9]+)" GLIBC_VERSION ${GLIBC_OUTPUT})
STRING (REPLACE "release version " "" 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)
Check glibc version if it is composed of
0
, ...,9
and.