Confusing behavior of FIND_LIBRARY_USE_LIB64_PATHS when crosscompiling, no easy way to change it in toolchain files
Hello,
I use some custom (really simple) Linux sysroot, and I now had to spend some time why find_library
(and similar cmds) dont resolve into the sysroot.
Turns out there is alot trickery with paths, making the same thing work when running on the host (automatically disabling those properties if debian is detected), while it fails on a cross-build.
The issue is:
-
Platform/UnixPaths.cmake
setsFIND_LIBRARY_USE_LIB*_PATHS
property to true -
Platform/UnixPaths.cmake
adds alot stuff like paths to X11, lib32, lib64, ... -
Platform/Linux.cmake
will behave differently ifCMAKE_CROSSCOMPILING
, even if the cross filesystem is identical to the host.
I cant prevent this from the toolchain file, means I would have to provide a own platform
(separate file) if I don't want to leak this into the regular projects. Which again poses a problem as I now would have to either copy over alot of stuff, possibly causing trouble if the CMAKE_SYSTEM_NAME
is now a unknown name. Or including Platform/Linux.cmake
, then making sure I undo everything that's not fitting.
I would rather have a way to prevent most of Platform/UnixPaths.cmake
to be executed, while still using Platform/Linux.cmake
. ie either a Linux-NoPathMagic
Value for CMAKE_SYSTEM_NAME
, or a way to affect the FIND_LIBRARY_USE_LIB*_PATHS
properties vie variables from the toolchain file (why are those properties in the first place...)
And other things that I consider wrong:
-
Platform/Linux.cmake
sets the variableCMAKE_LIBRARY_ARCHITECTURE_REGEX
, assumingglibc
(wont work for musl: see debian package) -
Platform/Linux.cmake
does not resetFIND_LIBRARY_USE_LIBX32_PATHS
on debian.
# File CMakeLists.txt
cmake_minimum_required(VERSION 3.13...3.14)
# set path to custom cmake modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
project(Nothing)
# this would fix it:
# set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS FALSE)
# set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
# set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIBX32_PATHS FALSE)
find_library (
SomeLibrary
NAMES idontexist
HINTS /hugo
)
# File toolchain.cmake
# set(CMAKE_INSTALL_SO_NO_EXE 0)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_PROGRAM_PATH "/other/bin")
set(CMAKE_SYSROOT "/tmp/sysroot")
set(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}")
#set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
#set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
#set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Log after running cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake --debug-find ..
CMake Debug Log at CMakeLists.txt:11 (find_library):
find_library(SomeLibrary) removed original suffix /tmp/sysroot/hugo/ from
PATH_SUFFIXES while adding architecture paths for suffix '64'
....
find_library considered the following locations:
The item was not found.