1

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.

ajoseps
  • 1,871
  • 1
  • 16
  • 29

1 Answers1

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
xgdgsc
  • 1,367
  • 13
  • 38
fdk1342
  • 3,274
  • 1
  • 16
  • 17
  • 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