[CMake] FIND_LIBRARY and PATH_SUFFIXES: documentation or implementation bug
Michael Hertling
mhertling at online.de
Fri Mar 25 01:48:51 EDT 2011
On 03/24/2011 10:55 AM, Marcel Loose wrote:
> Hi all,
>
> I stumbled upon this issue, while trying to track down why
> FindPythonLibs finds the static library libpython2.6.a
> in /usr/lib64/python2.6/config, instead of the shared library
> libpython2.6.so in /usr/lib64 on my system.
On my system, there is /usr/lib/python2.5/config/libpython2.5.a and
/usr/lib/libpython2.5.so, and a FIND_PACKAGE(PythonLibs) results in
PYTHON_LIBRARY==/usr/lib/libpython2.5.so. This is expected since the
first non-WIN32-specific FIND_LIBRARY() in FindPythonLibs.cmake does
not have PATH_SUFFIXES, so it doesn't look into the config directory
of the Python installations. However, if PYTHON_LIBRARY contains the
static .../pythonX.Y/config/libpythonX.Y.a, this usually means that
the first FIND_LIBRARY() has failed, so what is the result of a
FIND_LIBRARY(RESULT python2.6) on your system?
> The find module uses PATH_SUFFIXES python${_CURRENT_VERSION}/config,
> which in my case expands to python2.6/config. The documentation of
> find_library() reads:
>
> PATH_SUFFIXES specifies additional subdirectories to check below
> each search path
>
> Additional(!) subdirectories. However, if I do an strace I notice that
> *only* the directories with the path suffixes are searched, not the
> directories in the search path *without* the suffixes.
AFAICS, this is not true, see cmFindBase::AddPathSuffixes(). The paths
with the additional suffixes are searched first, but the paths without
the suffixes are considered, too. Look at the following CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(PATHSUFFIXES NONE)
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib/config)
FILE(WRITE ${CMAKE_BINARY_DIR}/lib/libxyz.so "")
FILE(WRITE ${CMAKE_BINARY_DIR}/lib/config/libxyz.a "")
SET(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
FIND_LIBRARY(XYZ1 xyz PATH_SUFFIXES config)
MESSAGE("XYZ1: ${XYZ1}")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".so")
FIND_LIBRARY(XYZ2 xyz PATH_SUFFIXES config)
MESSAGE("XYZ2: ${XYZ2}")
This yields:
XYZ1: ${CMAKE_BINARY_DIR}/lib/config/libxyz.a
XYZ2: ${CMAKE_BINARY_DIR}/lib/libxyz.so
The first call of FIND_LIBRARY() looks for libxyz.so and libxyz.a in
${CMAKE_BINARY_DIR}/lib/config and ${CMAKE_BINARY_DIR}/lib and finds
${CMAKE_BINARY_DIR}/lib/config/libxyz.a, but the second FIND_LIBRARY()
call only looks for libxyz.so and finds it in ${CMAKE_BINARY_DIR}/lib.
If the paths without the additional suffix are not taken into account,
this second call would fail.
Regards,
Michael
> Is this a bug in the documentation or a bug in the implementation of
> CMake?
>
> Best regards,
> Marcel Loose.
More information about the CMake
mailing list