[cmake-developers] Finding versioned libraries

Brad King brad.king at kitware.com
Wed Feb 15 09:51:55 EST 2012


On 2/15/2012 9:18 AM, Eric Noulard wrote:
> If the user does not trust find_library for checking proper extension then:
>     1) He could modify/append CMAKE_FIND_LIBRARY_SUFFIXES
>         in this case:
>            list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".so.2")
>         should work.
>
>     2) He could use find_file
>
> Now if we consider this is a bug,
> then with your modification "HasValidSuffix" is ill-named since it is more like
> "ContainsValidSuffix" or "MatchesValidSuffix".
>
> With this modification one could now find a not-properly-installed
> library (missing links)
> without noticing it.
>
> What is your purpose here, do you want to ensure that you find a
> particular version of a lib?

IMO searching for an exact file name like

   find_library(MYLIB libfoo.so.2)

is useful regardless of the expected library type.  The only reason
CMake requires the library prefix and suffix to appear in the name
is to prevent things like

   find_library(MYLIB python)

from locating the python executable which is called just "python".
We check for both the prefix and suffix to ensure the file name
looks like a library before considering it raw.  Back before CMake
2.6 started using full paths to link it was not possible to link
to library file that did not look exactly like a library (proper
prefix and suffix).  Now that we can pass the exact file name to
the linker we can have a softer test for what looks like a lib.

-Brad



More information about the cmake-developers mailing list