我可以在 CMakeLists 中使用在工具链文件中定义的 CMAKE_SYSTEM_PROCESSOR 吗? [英] Can I use CMAKE_SYSTEM_PROCESSOR, defined in a toolchain file, in CMakeLists?
问题描述
我想将 Raspberry Pi 作为交叉编译目标添加到使用 CMake 的 C++ 项目中.按照对这个问题的公认回答,我已经成功设置了环境.
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.
该项目已经有许多构建目标,所有这些目标都以非常丑陋的方式定义在主 CMakeLists.txt 中(这是一个旧项目).在此文件中,根据 CMAKE_SYSTEM_PROCESSOR 变量设置了一些编译器标志,例如:
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 ()
根据指南,我应该在我的 Raspberry 工具链文件中设置它.我已经添加了 SET(CMAKE_SYSTEM_PROCESSOR arm)
,但是我无法从 CMakeLists 访问它,因为它在那里变成了一个空字符串.我对其他变量没有这个问题,比如 CMAKE_SYSTEM_NAME.使用 message()
,我可以看到它在工具链文件中仍然可用,但之后变为空.
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.
有没有办法在 CMakeLists.txt 中使用 CMAKE_SYSTEM_PROCESSOR?或者,它是故意只在工具链文件中可用吗?
Is there any way to use CMAKE_SYSTEM_PROCESSOR in CMakeLists.txt? Or, is it available only in the toolchain file intentionally?
我使用的是 CMake 2.8.12.2.
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屋!