0

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/
Peter Petrik
  • 9,701
  • 5
  • 41
  • 65

2 Answers2

3

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

Set it together in one command:

set_target_properties(<targetname> PROPERTIES COMPILE_FLAGS "-isystem=/usr/include/")
Peter Petrik
  • 9,701
  • 5
  • 41
  • 65
  • Sure there are some alternative solutions. I have already developed some to have a successful build. For example; setting CMAKE_INCLUDE_SYSTEM_FLAG_C and CMAKE_INCLUDE_SYSTEM_FLAG_CXX to "-isystem=" also works. – Ibrahim_Demir Jun 19 '14 at 09:02
  • My question is can we do this with include_directories? Since CMAKE supports adding -isystem includes and --sysroot flag by CMAKE_SYSROOT, logically there should be support for adding paths with "=" prefix. Otherwise there is no use of CMAKE_SYSROOT, am I wrong? – Ibrahim_Demir Jun 19 '14 at 09:10