Do(交叉编译)平台文件需要包含guard吗? [英] Do (Cross-compile) platform files require an include guard?

查看:215
本文介绍了Do(交叉编译)平台文件需要包含guard吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为VxWorks编写一个交叉编译工具链文件。因为它是一个未知的系统,cmake a也有写平台文件( ../ Modules / Platform )。



除了我的工具链文件我已经写了这些平台文件到目前为止:




  • VxWorks.cmake (VxWorks操作系统设置)

  • VxWorks-gcc.cmake (WindRiver(Gnu)编译器设置)

  • VxWorks-gcc- [CPU] .cmake (CPU特定设置,是工具链文件中指定的处理器)



一切都与我的文件一样正常。



但是一些默认的平台文件包含一个包含guard / 如下:

  if(__ WINDOWS_GNU)
return()
endif()
set(__ WINDOWS_GNU 1)

c $ c> Modules / Platform / Windows-GNU.cmake )



所以我想知道:插入这样的警卫吗?

CMake模块可以包含对方,所以它可以导致钻石问题
如果你很幸运,你有两个工作用于设置一些变量,但如果
你需要一些复杂的东西,事情可能会变得更糟。



示例:



FindB.cmake



  find_package(A)

FindA.cmake >

  find_package(B)


$ b b

CMakeLists.txt

  cmake_minimum_required(VERSION 2.8)

list(APPEND CMAKE_MODULE_PATH $ {CMAKE_CURRENT_LIST_DIR})

find_package(A)#include FindA.cmake,其中包括FindB.cmake
#,其中包括FindA.cmake ....



pre> - C编译器标识是Clang 4.2.0
- CXX编译器标识是Clang 4.2.0
- 检查工作C编译器: usr / bin / cc
- 检查工作C编译器:/ usr / bin / cc - works
- 检测C编译器ABI信息
- 检测C编译器ABI信息 - 完成
- 检查CXX编译器是否正常工作:/ usr / bin / c ++
- 检查CXX编译器是否正常工作:/ usr / bin / c ++ - works
- 检测CXX编译器ABI信息
- 检测CXX编译器ABI信息 - 完成
分段错误:11






只需在模块开头使用guard(让变量描述路径防止冲突)



FindB.cmake

  if(FIND_B_CMAKE)
return()
endif()
(FIND_B_CMAKE 1)

find_package(A)


I'm writing a Cross-compiling Toolchain file for VxWorks. Since it's an unknown system to cmake a also have write platform files (those in ../Modules/Platform).

Beside my toolchain file I have written these platform files so far:

  • VxWorks.cmake (VxWorks OS settings)
  • VxWorks-gcc.cmake (WindRiver (Gnu) compiler settings)
  • VxWorks-gcc-[CPU].cmake (CPU specific settings, is the processor as specified in the toolchain file)

Everything works fine with my files at the moment.

But some of the default platform files contain a include guard / include blocker like this one:

if(__WINDOWS_GNU)
  return()
endif()
set(__WINDOWS_GNU 1)

(from: Modules/Platform/Windows-GNU.cmake)

So i'm wondering: Do I have to insert such a guard too? And when it's a good idea to insert them?

解决方案

CMake modules can include each other, so it can lead to diamond problem. If you are lucky, you've got double work for setting some variables, but if you will need some complex stuff, things may get worse.

Example:

FindB.cmake

find_package(A)

FindA.cmake

find_package(B)

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

find_package(A) # include FindA.cmake, which include FindB.cmake
    # which include FindA.cmake ....

Now run cmake .

-- The C compiler identification is Clang 4.2.0
-- The CXX compiler identification is Clang 4.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
Segmentation fault: 11


Just use guards at beginning of the module (let variable describe path to prevent collision)

FindB.cmake

if(FIND_B_CMAKE)
  return()
endif()
set(FIND_B_CMAKE 1)

find_package(A)

这篇关于Do(交叉编译)平台文件需要包含guard吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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