我正在为 VxWorks 编写交叉编译工具链文件。由于它是一个未知的系统,cmake a 也有写入平台文件(那些在../Modules/Platform
).
在我的旁边工具链到目前为止我已经编写了这些平台文件:
-
VxWorks.cmake(VxWorks操作系统设置)
-
VxWorks-gcc.cmake(WindRiver (Gnu) 编译器设置)
-
VxWorks-gcc-[CPU].cmake(CPU特定设置,是工具链文件中指定的处理器)
目前我的文件一切正常。
但一些默认平台文件包含一个包含保护/包括拦截器像这个:
if(__WINDOWS_GNU)
return()
endif()
set(__WINDOWS_GNU 1)
(from: Modules/Platform/Windows-GNU.cmake
)
所以我想知道:我也必须插入这样的防护装置吗?什么时候插入它们是个好主意?
CMake 模块可以相互包含,因此可以导致钻石问题 http://en.wikipedia.org/wiki/Diamond_problem。
如果你幸运的话,你需要双重工作来设置一些变量,但是如果
你将需要一些复杂的东西,事情可能会变得更糟。
Example:
FindB.cmake
find_package(A)
查找A.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
只需在模块开头使用防护(让变量描述路径以防止冲突)
FindB.cmake
if(FIND_B_CMAKE)
return()
endif()
set(FIND_B_CMAKE 1)
find_package(A)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)