CMake find_library matching behavior?

Why not use find_file() instead of find_library() if you want to find a .dll.


You might want to take a look at this documentation links:

http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_library

http://www.cmake.org/cmake/help/v2.8.10/cmake.html#variable:CMAKE_FIND_LIBRARY_PREFIXES

http://www.cmake.org/cmake/help/v2.8.10/cmake.html#variable:CMAKE_FIND_LIBRARY_SUFFIXES

find_library may accept one or more library names. Those names get the value of CMAKE_FIND_LIBRARY_PREFIXES prepended and CMAKE_FIND_LIBRARY_SUFFIXES appended. This two variables should be set for each OS depending on how the librares are prefixed or suffixed there.

In your case I'd write for Windows

SET(CMAKE_FIND_LIBRARY_PREFIXES "")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll")

and for Linux

SET(CMAKE_FIND_LIBRARY_PREFIXES "lib")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")

and then write

find_library(
    magick
    CORE_RL_magick_ (or NAMES if there are multiple names for the same library on different systems)

    PATHS
      path1
      path2
    ...
    (other options that are specified in documentation and would be usefull to you)
)

EDIT:

CMAKE_FIND_LIBRARY_PREFIXES and CMAKE_FIND_LIBRARY_SUFIXES are set automatically by project() command so calling it first and find_library() after that point is a better solution than setting the variables manually.

Tags:

Cmake