Having CMake include_directories SYSTEM dirs prefi

2019-03-04 10:46发布

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")

results:

-isystem /root/opencv-2-4-9/opencv/modules/highgui/=/usr/include/

what I expect is:

-isystem=/usr/include/

标签: gcc cmake
2条回答
何必那么认真
2楼-- · 2019-03-04 11:02

Set it together in one command:

set_target_properties(<targetname> PROPERTIES COMPILE_FLAGS "-isystem=/usr/include/")
查看更多
可以哭但决不认输i
3楼-- · 2019-03-04 11:09

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.

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")

generates

-isystem =/usr/include/

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)
查看更多
登录 后发表回答