Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake find_library does not find the library

Tags:

cmake

magma

I came up with the following super simple FindMAGMA.cmake script to find the MAGMA library given there is none around:

# - Find the MAGMA library
#
# Usage:
#   find_package(MAGMA [REQUIRED] [QUIET] )
#
# It sets the following variables:
#   MAGMA_FOUND               ... true if magma is found on the system
#   MAGMA_LIBRARY_DIRS        ... full path to magma library
#   MAGMA_INCLUDE_DIRS        ... magma include directory
#   MAGMA_LIBRARIES           ... magma libraries
#
# The following variables will be checked by the function
#   MAGMA_USE_STATIC_LIBS     ... if true, only static libraries are found
#   MAGMA_ROOT                ... if set, the libraries are exclusively searched
#                                 under this path

#If environment variable MAGMA_ROOT is specified, it has same effect as MAGMA_ROOT
if( NOT MAGMA_ROOT AND NOT $ENV{MAGMA_ROOT} STREQUAL "" )
    set( MAGMA_ROOT $ENV{MAGMA_ROOT} )
    # set library directories
    set(MAGMA_LIBRARY_DIRS ${MAGMA_ROOT}/lib)
    # set include directories
    set(MAGMA_INCLUDE_DIRS ${MAGMA_ROOT}/include)
    # set libraries
    find_library(
        MAGMA_LIBRARIES
        NAMES "libmagma"
        PATHS ${MAGMA_ROOT}
        PATH_SUFFIXES "lib"
        NO_DEFAULT_PATH
    )
    set(MAGMA_FOUND TRUE)
else()
    set(MAGMA_FOUND FALSE)
endif()

Getting the include and lib paths is straightforward. However, it does not find the file "libmagma.a" in Ubuntu or "libmagma.dylib" in Mac OS X unless I include the extension but this defeats the purpose, doesn't it? Can anyone please advice what I'm doing wrong here?

like image 611
SkyWalker Avatar asked Jul 19 '13 13:07

SkyWalker


People also ask

What does Find_library do in CMake?

This command is used to find a library. A cache entry, or a normal variable if NO_CACHE is specified, named by <VAR> is created to store the result of this command. If the library is found the result is stored in the variable and the search will not be repeated unless the variable is cleared.

What is Cmake_find_root_path?

Semicolon-separated list of root paths to search on the filesystem. This variable is most useful when cross-compiling. CMake uses the paths in this list as alternative roots to find filesystem items with find_package() , find_library() etc.


1 Answers

Remove the leading lib from the library name

find_library(
    MAGMA_LIBRARIES
    NAMES magma
    PATHS ${MAGMA_ROOT}
    PATH_SUFFIXES lib
    NO_DEFAULT_PATH
)

Also, take a look at FindPackageHandleStandardArgs which can help you get rid of some boilerplate code that is usually required in find scripts.

like image 129
ComicSansMS Avatar answered Oct 18 '22 18:10

ComicSansMS