I need to build on CentOS but not Fedora. I've seen a previous post but that only checks to see if it's Windows vs Linux vs Other platforms.
Asked
Active
Viewed 591 times
1 Answers
1
Does checking the contents of /etc/os-release
work?
https://www.freedesktop.org/software/systemd/man/os-release.html
You can just read in the file and it'll contain a line like NAME="Ubuntu"
.
Use file()
to parse it and grab the NAME
field.
file(STRINGS /etc/os-release distro REGEX "^NAME=")
string(REGEX REPLACE "NAME=\"(.*)\"" "\\1" distro "${distro}")
file(STRINGS /etc/os-release disversion REGEX "^VERSION_ID=")
string(REGEX REPLACE "VERSION_ID=\"(.*)\"" "\\1" disversion "${disversion}")
message("found ${distro}.${disversion}")
outputs
found Ubuntu.20.04
-
That works! this is the above code with the conditional: ```file(STRINGS /etc/os-release distro REGEX "^NAME=") string(REGEX REPLACE "NAME=\"(.*)\"" "\\1" distro "${distro}") if( ${distro} STREQUAL "CentOS Linux" ) ... BUILD INSTRUCTIONS ... endif()``` – ajoseps Mar 14 '19 at 18:08