Detect underlying platform/flavour in Cmake

voidMainReturn picture voidMainReturn · Nov 13, 2014 · Viewed 13.6k times · Source

Does anybody know any cmake variable or hook or something which can give me underlying platform name/flavour name on which it is getting executed ? e.g. Linux-CentOs Linux-Ubuntu Linux-SLES

I know cmake has "CMAKE_SYSTEM" variable but that doesn't help differentiating flavours of linux for e.g. Any help is appreciated.

edit : I just read that it can be done using lsb_release command ?

Answer

thiagowfx picture thiagowfx · Jan 11, 2017

The following snippet populates the LSB_RELEASE_ID_SHORT cmake variable with information about the underlying Linux system:

find_program(LSB_RELEASE_EXEC lsb_release)
execute_process(COMMAND ${LSB_RELEASE_EXEC} -is
    OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT
    OUTPUT_STRIP_TRAILING_WHITESPACE
)

On Ubuntu, for example, it yields Ubuntu.