How do I point find_package()
to my "custom" directory $SYSROOT/usr/lib/arm-linux-gnueabihf/
so it can find libz.so
?
I have a library in this location:
/home/user/bla/sysroot/usr/lib/arm-linux-gnueabihf/libz.so
With a header that can be found here:
/home/user/bla/sysroot/usr/include/zlib.h
With CMake I try:
cmake_minimum_required(VERSION 3.18)
find_package(ZLIB REQUIRED)
Which results in:
CMake Error at /home/user/cmake/linux/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.11")
So CMake cannot find ZLIB_LIBRARY
(libz.so
) but it can parse the version (1.2.11
) from the header file.
I set my SYSROOT in CMake like this:
SET(CMAKE_FIND_ROOT_PATH "${toolchain_dir}/sysroot/")
But it seems CMake doesn't know about usr/lib/arm-linux-gnueabihf/libz.so.
What I tried
I tried to give HINTS or PATH to find_package
like this:
find_package(ZLIB REQUIRED HINTS "${sysroot_dir}/usr/lib/arm-linux-gnueabihf/" NO_DEFAULT_PATH)
or like this:
find_package(ZLIB REQUIRED PATH "${sysroot_dir}/usr/lib/arm-linux-gnueabihf/" NO_DEFAULT_PATH)
But it results in this error message:
CMake Error at CMakeLists.txt:12 (find_package):
Could not find a package configuration file provided by "ZLIB" with any of
the following names:
ZLIBConfig.cmake
zlib-config.cmake
Add the installation prefix of "ZLIB" to CMAKE_PREFIX_PATH or set
"ZLIB_DIR" to a directory containing one of the above files. If "ZLIB"
provides a separate development package or SDK, be sure it has been
installed.
extra info
Here is the contents of my toolchain file that I use (targeting raspberry pi 4) with -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake
# Define our host system
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
# toolchain
set(toolchain_dir "/home/user/bla")
set(sysroot_dir "${toolchain_dir}/sysroot")
SET(CMAKE_C_COMPILER "${toolchain_dir}/tools/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc")
SET(CMAKE_CXX_COMPILER "${toolchain_dir}/tools/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++")
# Define the sysroot path for the RaspberryPi distribution
SET(CMAKE_FIND_ROOT_PATH "${toolchain_dir}/sysroot/")
message(STATUS "${CMAKE_FIND_ROOT_PATH}")
# Use our definitions for compiler tools
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories only
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)