cmake检查库是否是静态的 [英] cmake check if library is static

查看:56
本文介绍了cmake检查库是否是静态的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检查找到的库是否为静态库?为了找到该库,我这样做:

Is there a way to check if a found library is a static library? In order to find the library I do this:

IF(WIN32)
    SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib)
ELSE()
    SET(CMAKE_FIND_LIBRARY_SUFFIXES .a)
ENDIF()
find_library(QUANTLIB_LIBRARY NAMES QuantLib PATHS ${QUANTLIB_LIBRARY_SEARCH})

但是在Windows上, .lib 可能是DLL的符号文件.我需要确保这实际上是库的静态形式,否则以后的链接将导致难以理解的错误消息.

But on windows a .lib could be the symbol file for a DLL. I need to ensure this is actually the static form of the library, otherwise linking later will result in hard-to-understand error messages.

如果您想知道,我真的不想使用一个Satic库,但是QuantLib在多线程和共享库方面被打破了.这是使它正常工作的最好机会:静态链接到我的共享库之一.

推荐答案

如果将库正确添加为目标,则应该可以执行以下操作.

If the library is added as a target properly you should be able to do something like this.

get_target_property(target_type your_target_name TYPE)
if (target_type STREQUAL STATIC_LIBRARY)
  ...

有关详细信息,请参见 TYPE .

See TYPE for details.

这篇关于cmake检查库是否是静态的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆