CMake测试处理器功能 [英] CMake test for processor feature

查看:225
本文介绍了CMake测试处理器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可能的CMake运行测试像一个可能运行与配置脚本。特别是我想测试我编译的系统是否支持rdtscp指令。

I am wondering if it is possible for CMake to run tests like one might run with a configure script. Specifically I want to test if the system I am compiling on has support for the rdtscp instruction.

我使用Linux,如果我使用配置脚本,我可以这样做:

I am using Linux and if I were using a configure script I could do something like:

cat /proc/cpuinfo | head -n 19 | tail -1 | grep -c rdtscp

这将给我 0 如果rdtscp功能不存在或 1 如果是。然后我可以使用这个来确定是否#define RDTSCP。我想知道是否可能做类似于CMake的东西,即使它不是完全可移植(我只在Linux下运行我不使用Visual Studio等)。

which would give me 0 if the rdtscp feature was not present or a 1 if it were. I could then use this to determine whether to #define RDTSCP. I'm wondering if it's possible to do something similar with CMake even if it's not completely portable (I'm only running under Linux I'm not using Visual Studio, etc.).

推荐答案

execute_process(COMMAND cat /proc/cpuinfo
    COMMAND head -n 19
    COMMAND tail -1
    COMMAND grep -c rdtscp
    OUTPUT_VARIABLE OUT)

这篇关于CMake测试处理器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆