Probe various candidates for system release info

Not all Linux distributions is LSB-compliant, notably RHEL 6, so we
should make an effort to check various known other files in order to
identify the distribution.
This commit is contained in:
Roland Kaufmann 2013-02-15 13:53:13 +01:00
parent be26e078d2
commit be7ad261d5

View File

@ -3,21 +3,48 @@
function (system_info)
message (STATUS "CMake version: ${CMAKE_VERSION}")
if (CMAKE_SYSTEM MATCHES "Linux")
read_lsb (ID INTO DISTRIB_ID)
read_lsb (RELEASE INTO DISTRIB_RELEASE)
read_lsb (CODENAME INTO DISTRIB_CODENAME)
message (STATUS "Linux distribution: ${DISTRIB_ID} \"${DISTRIB_CODENAME}\" ${DISTRIB_RELEASE}")
distro_name (DISTRO_NAME)
message (STATUS "Linux distribution: ${DISTRO_NAME}")
else (CMAKE_SYSTEM MATCHES "Linux")
message (STATUS "Operating system: ${CMAKE_SYSTEM}")
endif (CMAKE_SYSTEM MATCHES "Linux")
endfunction (system_info)
# read property from LSB information
function (read_lsb suffix INTO varname)
file (STRINGS /etc/lsb-release _distrib
REGEX "^DISTRIB_${suffix}="
# probe various system files that may be found
function (distro_name varname)
file (GLOB has_os_release /etc/os-release)
file (GLOB has_lsb_release /etc/lsb-release)
file (GLOB has_sys_release /etc/system-release)
# start with /etc/os-release,
# see <http://0pointer.de/blog/projects/os-release.html>
if (NOT has_os_release STREQUAL "")
read_release (PRETTY_NAME FROM /etc/os-release INTO _descr)
# previous "standard", used on older Ubuntu and Debian
elseif (NOT has_lsb_release STREQUAL "")
read_release (DISTRIB_DESCRIPTION FROM /etc/lsb-release INTO _descr)
# RHEL/CentOS etc. has just a text-file
elseif (NOT has_sys_release STREQUAL "")
file (READ /etc/system-release _descr)
else (NOT has_lsb_release STREQUAL "")
# no yet known release file found
set (_descr "unknown")
endif (NOT has_os_release STREQUAL "")
# return from function (into appropriate variable)
string (STRIP "${_descr}" _descr)
set (${varname} "${_descr}" PARENT_SCOPE)
endfunction (distro_name varname)
# read property from the newer /etc/os-release
function (read_release valuename FROM filename INTO varname)
file (STRINGS ${filename} _distrib
REGEX "^${valuename}="
)
string (REGEX REPLACE
"^DISTRIB_${suffix}=\(.*\)" "\\1" ${varname} ${_distrib})
"^${valuename}=\"?\(.*\)" "\\1" ${varname} ${_distrib}
)
# remove trailing quote that got globbed by the wildcard (greedy match)
string (REGEX REPLACE
"\"$" "" ${varname} "${${varname}}"
)
set (${varname} "${${varname}}" PARENT_SCOPE)
endfunction (read_lsb suffix INTO varname)
endfunction (read_release valuename FROM filename INTO varname)