1

I cross compile a third-party lib use cmake, I create a toolchain.make like this

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

SET(CMAKE_C_COMPILER  aarch64-poky-linux-gcc)

SET(CMAKE_CXX_COMPILER  aarch64-poky-linux-g++)

SET(CMAKE_FIND_ROOT_PATH /home/sundq/workspace/mengbin/tmp/Conexant_2Mic/build/tmp/sysroots/aud8516-slc) 

SET(CMAKE_SYSROOT /home/sundq/workspace/mengbin/tmp/Conexant_2Mic/build/tmp/sysroots/aud8516-slc)
SET(CMAKE_SYSROOT_COMPILE "${CMAKE_SYSROOT}")
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

The question is: Why cmake finds gstreamer-2.0 header file in the host system path /usr/include/gstreamer-2.0 first, not in the sysroot path ${CMAKE_SYSROOT}/usr/include/gstreamer-2.0. I mean I have set SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY), the ONLY value mean find header file just in target directories, not in host directories, but it seems that this param CMAKE_FIND_ROOT_PATH_MODE_INCLUDE does not works!!!

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
sundq
  • 735
  • 2
  • 9
  • 28
  • It depends on the way, how your 3d-party library performes the search. If it uses `findGstreamer.cmake` script which detects include path by means of `find_path`, it should follow *CMAKE_FIND_ROOT_PATH_MODE_INCLUDE* variable. But if it uses `FindPkgConfig` module, your settings doesn't affect on it. Try to set *CMAKE_PREFIX_PATH* variable to `${CMAKE_SYSROOT}/usr`. BTW, *CMAKE_SYSROOT* path is *automatically* treated as one of *CMAKE_FIND_ROOT_PATH* paths, no need to add it explicitly. – Tsyvarev Sep 23 '17 at 10:40
  • add **CMAKE_PREFIX_PATH** will affect **CMAKE_FIND_ROOT_PATH_MODE_PROGRAM**?, cmake find program in host directories or target directories? – sundq Sep 24 '17 at 03:02
  • As far as I understand, *CMAKE_FIND_ROOT_PATH* affects on interpretation of *CMAKE_PREFIX_PATH* in CMake commands like `find_library` or `find_path`. But module `FindPkgConfig.cmake` uses *CMAKE_PREFIX_PATH* variable directly, and doesn't check *CMAKE_FIND_ROOT_PATH* one. – Tsyvarev Sep 24 '17 at 07:42
  • I think should not just set **CMAKE_PREFIX_PATH**, you can reference this question https://stackoverflow.com/questions/9221236/pkg-config-fails-to-find-package-under-sysroot-directory – sundq Sep 25 '17 at 03:35

0 Answers0