Cmake find_library and CMAKE_FIND_ROOT_PATH

In the documentation for the cmake function, find_librarywe have

The CMake variable CMAKE_FIND_ROOT_PATH indicates one or more directories to be added to all other search directories. This effectively "restores" the entire search in these places. paths that are descendants of CMAKE_STAGING_PREFIX are excluded from this re-rooting because this variable is always a path on the host system. By default, CMAKE_FIND_ROOT_PATH is empty.

The CMAKE_SYSROOT variable can also be used to specify exactly one to use as a prefix. Setting CMAKE_SYSROOT has other consequences. See the documentation for this variable for more details.

These variables are especially useful when cross-compiling points to the root directory of the target environment and CMake will look there too. By default, the directories listed in Search CMAKE_FIND_ROOT_PATH are executed first, then the directory CMAKE_SYSROOT is searched, and then the non-root directories are searched. The default behavior can be set by setting CMAKE_FIND_ROOT_PATH_MODE_LIBRARY. This can be manually redefined for each call. Using CMAKE_FIND_ROOT_PATH_BOTH, the search order will be as described above. If NO_CMAKE_FIND_ROOT_PATH is used, then CMAKE_FIND_ROOT_PATH will not be used. If ONLY_CMAKE_FIND_ROOT_PATH is used, then only the reconfigured directories and directories below CMAKE_STAGING_PREFIX will be found.

(see http://www.cmake.org/cmake/help/v3.0/command/find_library.html )

, , , find_library CMAKE_FIND_ROOT_PATH . cmakelists.txt:

cmake_minimum_required( VERSION 3.0 )

project( "cmakefindlibtest" )

message( "CMAKE_FIND_ROOT_PATH is ${CMAKE_FIND_ROOT_PATH}" )
list( APPEND CMAKE_FIND_ROOT_PATH "C:/DEV/lib/" )
message( "CMAKE_FIND_ROOT_PATH is now ${CMAKE_FIND_ROOT_PATH}" )
#find_library( punycode_library_test punycode PATHS "C:/DEV/lib" )
find_library( punycode_library_test punycode  )
message( "punycode_library_test is now ${punycode_library_test}" )

add_executable( cmakefindlibtest main.cpp )
target_link_libraries( cmakefindlibtest ${punycode_library_test} )

main.cpp - . C:\DEV\lib punycode.lib ( Windows). CMAKE_FIND_ROOT_PATH . , find_library, :

c:\DEV\cmakefindtest\_build>cmake ..
-- Building for: Visual Studio 11 2012
CMAKE_FIND_ROOT_PATH is
CMAKE_FIND_ROOT_PATH is now C:/DEV/lib/
punycode_library_test is now punycode_library_test-NOTFOUND
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
punycode_library_test
    linked by target "cmakefindlibtest" in directory C:/DEV/cmakefindtest

-- Configuring incomplete, errors occurred!
See also "C:/DEV/cmakefindtest/_build/CMakeFiles/CMakeOutput.log".

, PATHS find_library invocation

find_library( punycode_library_test punycode PATHS "C:/DEV/lib" )

:

c:\DEV\cmakefindtest\_build>cmake ..
-- Building for: Visual Studio 11 2012
CMAKE_FIND_ROOT_PATH is
CMAKE_FIND_ROOT_PATH is now C:/DEV/lib/
punycode_library_test is now C:/DEV/lib/punycode.lib
-- Configuring done
-- Generating done
-- Build files have been written to: C:/DEV/cmakefindtest/_build

find_library CMAKE_FIND_ROOT_PATH?

Update:

, CMAKE_LIBRARY_PATH , , http://public.kitware.com/pipermail/cmake-developers/2012-January/002850.html, , .

, CMAKE_FIND_ROOT_PATH find_library. http://www.cmake.org/Wiki/CMake_Cross_Compiling CMAKE_FIND_ROOT_PATH,

, FIND_XXX().

, - , .

+4
2

CMAKE_FIND_ROOT_PATH , docs find_library. , find_library.

CMAKE_FIND_ROOT_PATH -. , find_library(.. jpeg ...) /usr/lib/libjpeg.so, set(CMAKE_FIND_ROOT_PATH ~/my_toolchain), ~/my_toolchain/usr/lib/libjpeg.so.

, , , , , CMAKE_PREFIX_PATH. set(CMAKE_PREFIX_PATH "c:/DEV") set(CMAKE_LIBRARY_PATH "c:/DEV/lib") find_library c:/DEV/lib.

+2

- openwrt .

, CMAKE_FIND_ROOT_PATH toolchain, rpcd .

, - lib ./usr/lib ./lib. , CMAKE_FIND_ROOT_PATH , ./usr/lib ./lib , .

, , , CMAKE_FIND_ROOT_PATH C:/DEV C:/DEV/lib.

, -, .

+1

Source: https://habr.com/ru/post/1547798/


All Articles