Improve documentation of CMAKE_FIND_ROOT_PATH modes and CMAKE_SYSROOT with regards to find commands
As a user of CMake, I find the documentation surrounding the usage of the following variables very confusing in the context of the various find_*()
functions such as find_package()
and find_path()
:
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
CMAKE_FIND_ROOT_PATH_MODE_PACKAGE
CMAKE_SYSROOT
CMAKE_FIND_ROOT_PATH
For example, when setting CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
TO ONLY
or NEVER
, is CMAKE_SYSROOT
used in either case?
Below is the original text of this issue. I originally misunderstood this issue to be a behavioral problem with find_path()
but according to @brad.king this is behaving as expect. In this case, the behavior needs better detail, perhaps some examples, and more clarity based on behavior of the code as of version 3.9 of CMake.
Original Text:
When I invoke
find_package(ZLIB MODULE)
using the NDK's shipped android.toolchain.cmake file, it still finds includes underCMAKE_SYSROOT
even thoughCMAKE_FIND_ROOT_PATH_MODE_INCLUDE
is set toONLY
. The toolchain also setsCMAKE_FIND_ROOT_PATH
, but I override this in the directory above where the find_package is invoked:# After each library (in each add_subdirectory() below) is built, a find_package() is # performed. This prefix path controls where those libraries are found at. set( CMAKE_PREFIX_PATH ${ZIOSK_THIRD_PARTY_INSTALL} ) if( ANDROID ) # Override this on Android because it tries to muck with the root paths # to force searches to find things under NDK, which we don't want for our # own searches occurring within third party. set( CMAKE_FIND_ROOT_PATH ${ZIOSK_THIRD_PARTY_INSTALL} ) endif()
The first
find_package()
I call for zlib ends up finding it under://Path to a file. ZLIB_INCLUDE_DIR:PATH=E:/android/ndk_72/sysroot/usr/include
After I build zlib and run find_package again, it doesn't find it because this variable is already set. I suspect this is because the toolchain file's
CMAKE_SYSROOT
is set, but I thought thatCMAKE_FIND_ROOT_PATH_MODE_INCLUDE
set toONLY
is supposed to prevent that.Version: Using CMake 3.9 with a minimum required set to 3.6