Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

cmake using find_package() cross compiling

I am using CMake with a custom toolchain that I built using yocto. I have a problem though, the toolchain has sysroot for the target machine and one for the build machine.

CMake keeps finding the libraries in the build system sysroot only.

For example I am using:

find_package(libxml2)

But it always keeps finding libxml2 in the build system sysroot instead of the target sysroot. How can I tell it to only look in the target sysroot?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How can I tell it to look in the target sysroot only?

There is a family of CMake variables CMAKE_FIND_ROOT_PATH_MODE_*, which adjusts search strategy for different CMake commands:

  • BOTH value means that both target and host (build) paths are searched. This is also a default behavior, when a variable is not set.

  • ONLY value means that only target is searched.

  • NEVER value means, that only host is searched.

List of variables:

Generally, concrete find_package() call may be affected by all of these variables. In case of searching libraries, it is usually suffificient to set only 3 of them:

# Search libraries only under *target* paths.
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

Variables CMAKE_FIND_ROOT_PATH_MODE_* are normally set in toolchain files.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...