我可以在CMakeLists中使用在工具链文件中定义的CMAKE_SYSTEM_PROCESSOR吗? [英] Can I use CMAKE_SYSTEM_PROCESSOR, defined in a toolchain file, in CMakeLists?

查看:414
本文介绍了我可以在CMakeLists中使用在工具链文件中定义的CMAKE_SYSTEM_PROCESSOR吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Raspberry Pi作为交叉编译目标添加到使用CMake的C ++项目中.在对问题的可接受答案之后,我已经成功设置了环境./p>

该项目已经有许多构建目标,所有这些构建目标都以非常难看的方式在主CMakeLists.txt中定义(这是一个旧项目).在此文件中,根据CMAKE_SYSTEM_PROCESSOR变量设置了一些编译器标志,例如:

 如果($ {CMAKE_SYSTEM_PROCESSOR}个匹配"^ arm")# 做一点事万一 () 

根据指南,我应该在Raspberry工具链文件中进行设置.我添加了 SET(CMAKE_SYSTEM_PROCESSOR臂),但是我无法从CMakeLists中访问它,因为它在那里变成了空字符串.我对其他变量(例如CMAKE_SYSTEM_NAME)没有此问题.使用 message(),我可以看到它在工具链文件中仍然可用,但此后变为空.

有什么方法可以在CMakeLists.txt中使用CMAKE_SYSTEM_PROCESSOR?还是有意仅在工具链文件中使用它?

我正在使用CMake 2.8.12.2.

解决方案

看来这毕竟是一个缓存问题-在一个干净的目录中构建可以解决该问题.虽然我仍然想知道它是怎么变成一个空字符串...

I'd like to add Raspberry Pi as a cross compilation target to a C++ project which uses CMake. Following the accepted answer to this question, I've set up the environment successfully.

The project has many build targets already, all of them defined in the main CMakeLists.txt in a quite ugly way (it's an old project). In this file, there are some compiler flags set, depending on the CMAKE_SYSTEM_PROCESSOR variable, for example:

if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
    # do something
endif ()

According to the guide, I should set this in my Raspberry toolchain file. I've added SET(CMAKE_SYSTEM_PROCESSOR arm), but I can't access this from the CMakeLists, because this becomes an empty string there. I don't have this problem with the other variables, like CMAKE_SYSTEM_NAME. Using message(), I can see that it is still available in the toolchain file, but becomes empty after that.

Is there any way to use CMAKE_SYSTEM_PROCESSOR in CMakeLists.txt? Or, is it available only in the toolchain file intentionally?

I'm using CMake 2.8.12.2.

解决方案

It seems this was a caching issue after all - building in a clean directory fixed the problem. Though I still wonder how did it become an empty string...

这篇关于我可以在CMakeLists中使用在工具链文件中定义的CMAKE_SYSTEM_PROCESSOR吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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