本文介绍了交叉编译 - 检索目标CPU和版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cmake交叉编译VxWorks。当我运行cmake的第一次,我必须提供有关编译器,目标操作系统等的信息。



在交叉编译对话框有三个目标系统设置我设置:


  1. 操作系统

  2. 版本

  3. 处理器



虽然我可以使用 CMAKE_SYSTEM_NAME 检索第一个,但我无法获得版本和处理器。
两者都返回一个空字符串。



这里有一个例子:

  MESSAGE(CMAKE_SYSTEM_PROCESSOR:$ {CMAKE_SYSTEM_PROCESSOR})
MESSAGE(CMAKE_SYSTEM_VERSION:$ {CMAKE_SYSTEM_VERSION})

输出

  CMAKE_SYSTEM_PROCESSOR:
CMAKE_SYSTEM_VERSION:

我的Cmake版本是 2.8.10.2 ,目标操作系统是VxWorks事情 - 编译器是WindRiver GNU)。



如何获得我开始设置的版本和处理器?或者如果我交叉编译到cmake未知的操作系统,这是不可能的。



(Btw。编译工作正常)

解决方案

到目前为止这看起来是不可能的。



然而,有一个有效的解决方案,我想这是更好的方法:



之前:



我指定了交叉编译设置(编译器和目标系统,见问题), CMake列表中的特定部分(使用 if(VxWorks)检查以确保在使用其他系统时不会执行)。



现在(解决方案)



我写了一个工具链文件






  • 我必须写一些额外的文件:

    • 工具链文件

    • VxWorks的平台文件

    • 每个处理器(和处理器类型, Gnu Diab )的其他平台文件





b $ b


  • 现在,CMake列表更清晰

  • 分隔项目和目标设置

  • 单独的系统和处理器设置 - 容易以非常清晰的方式添加新的处理器,但保留系统设置

  • 我在工具链文件中写入一些设置,并且CMake加载相关的系统/处理器设置

  • ...


I'm cross-compiling for VxWorks using cmake. When I run cmake the first time I have to provide informations about compiler, target OS etc..

In the cross-compile dialogue there are three target system settings I set:

  1. Operating System
  2. Version
  3. Processor

(followed by compiler etc.)

While I can retrieve the first one using CMAKE_SYSTEM_NAME, i can't get the version and the processor.Both return an empty string.

Here's an example:

MESSAGE("CMAKE_SYSTEM_PROCESSOR:   ${CMAKE_SYSTEM_PROCESSOR}")
MESSAGE("CMAKE_SYSTEM_VERSION:   ${CMAKE_SYSTEM_VERSION}")

Output:

CMAKE_SYSTEM_PROCESSOR:
CMAKE_SYSTEM_VERSION:

My Cmake Version is 2.8.10.2 and target OS is VxWorks (if this matters - compiler are WindRiver GNU).

How can I get the version and processor I've set in the beginning? Or is this impossible if I cross-compile to an OS that's unknown to cmake?

(Btw. Compiling works fine)

解决方案

It seems this is not possible so far. I'm getting empty strings all the time.

However, there's a working solution, and i guess it's the better way:

Before:

I specified cross-compile settings (Compiler and target system, see question), then it runs over VxWorks specific parts in the CMake list (checked with if( VxWorks ) to ensure it's not executed when other systems are used).

Now (Solution):

I wrote a toolchain file and platform files for VxWorks and required processors.

Cons:

  • I have to write some extra files:
    • Toolchain file
    • Platform file for VxWorks
    • Further Platform files for each Processor (and processor type, Gnu and Diab)

Pros:

  • CMake list is much cleaner now
  • Separate Project and Target settings
  • Separate System and processor settings - easy to add new Processors in a very clear way but keep System settings
  • I write some settings in the toolchain file and CMake loads related system / processor settings
  • ...

这篇关于交叉编译 - 检索目标CPU和版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 17:08