本文介绍了检测Cmake中的基础平台/风味的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道任何cmake变量或钩子或可以为我提供执行其基础平台名称/风味名称的信息吗?例如Linux中心Linux-UbuntuLinux-SLES

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-CentOsLinux-UbuntuLinux-SLES

我知道cmake具有"CMAKE_SYSTEM"变量,但是对于例如区分linux的风格没有帮助.感谢您的帮助.

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

我刚刚读到它可以使用lsb_release命令来完成?

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

推荐答案

以下代码段用有关基础Linux系统的信息填充LSB_RELEASE_ID_SHORT cmake变量:

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
)

例如,在Ubuntu上,它产生Ubuntu.

On Ubuntu, for example, it yields Ubuntu.

这篇关于检测Cmake中的基础平台/风味的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 15:35