CMake find_library找不到库

时间:2013-07-19 13:35:17

标签: cmake magma

我提出了以下超级简单的FindMAGMA.cmake脚本来查找MAGMA库,因为周围没有:

# - 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()

获取include和lib路径非常简单。但是,它在Ubuntu中找不到文件“libmagma.a”,在Mac OS X中找不到“libmagma.dylib”,除非我包含扩展名但是这会失败,不是吗?任何人都可以在这里建议我做错了吗?

1 个答案:

答案 0 :(得分:5)

从库名称

中删除前导lib
find_library(
    MAGMA_LIBRARIES
    NAMES magma
    PATHS ${MAGMA_ROOT}
    PATH_SUFFIXES lib
    NO_DEFAULT_PATH
)

另外,请查看FindPackageHandleStandardArgs,它可以帮助您摆脱查找脚本中通常需要的一些样板代码。