使CMake include_directories SYSTEM dirs前缀带有等号(=)
有没有办法让CMake include_directories
包含带有等号( =
)字符的系统目录前缀?这样,我就可以为gcc关联的目录添加前缀 -isysroot
进行交叉编译。
Is there a way to have CMake include_directories
include the system directory prefix with equals(=
) character? So that I can have gcc prefix the associated dirs with -isysroot
flag for the cross compilation.
当我尝试使用等号( =
)前缀包含路径时,假定相对路径和当前源前缀路径:
When I try to include the path with equals(=
) prefix, assumes relative path and prefixes with current source path:
include_directories(AFTER SYSTEM "=/usr/include")
结果:
-isystem /root/opencv-2-4-9/opencv/modules/highgui/=/usr/include/
我期望什么是:
-isystem=/usr/include/
我检查了CMake的源代码(均为2.8.12.2和3.0.0);在非Windows系统中,CMake似乎将当前源目录添加了所有不是以 /开头的路径。
I checked the source code of CMake (both 2.8.12.2 and 3.0.0); It seems CMake adds current source directory all paths which are not starting with '/' in non windows systems.
只有生成器表达式是例外。如果path以 $<开头,则它会在生成器表达式求值后跳过为该路径加上前缀并且不为该前缀加上前缀。因此
Only exception is generator expressions. If path starts with "$<", then it skips prefixing the path and does not prefix it after evaluation of the generator expression. Therefore
include_directories(AFTER SYSTEM "$<1:=>/usr/include")
生成
-isystem =/usr/include/
这似乎至少对CMake 3.0.0有效。当然,您应该为gcc设置CMAKE_SYSROOT以使用正确的路径作为前缀。
This seems to be working at least for CMake 3.0.0. Ofcourse you should set CMAKE_SYSROOT for gcc to prefix with proper path.
set(CMAKE_SYSROOT /usr/arm-linux-gnueabi)