CMake Install 安装第三方依赖库

cmake 提供 install 命令来安装文件,方便打包。但是有时也会对第三方依赖库有需求一起打包,在不确定第三方库dll文件路径和名称的情况下,需要另一种方式来打包了。

比如想要打包opencv_world.dll,一般cmake依赖opencv的方式是通过第三方软件包(* -config.cmake)的方式:

# CMakeLists.txt
find_package(OpenCV REQUIRED)

target_link_libraries(my_project ${OpenCV_LIBS})

那么在install opencv时可以采用该宏自动找到opencv_world.dll并安装到目标路径下

MACRO(INSTALL_IMPORTED_DLLS target_list target_component destination_dir)
  foreach(target_dll ${target_list})
    get_target_property(target_type ${target_dll} TYPE)
    if (NOT target_type STREQUAL "INTERFACE_LIBRARY")
       get_target_property(target_dll_location ${target_dll} IMPORTED_LOCATION_RELEASE)
       if( one_trg_dll_location MATCHES ".dll$")
          install(FILES ${target_dll_location} DESTINATION ${destination_dir} CONFIGURATIONS Release COMPONENT ${target_component})
       endif()
       get_target_property(target_dll_location ${target_dll} IMPORTED_LOCATION_DEBUG)
       if( target_dll_location MATCHES ".dll$")
          install(FILES ${target_dll_location} DESTINATION ${destination_dir} CONFIGURATIONS Debug COMPONENT ${target_component})
       endif()
    endif()
  endforeach()
ENDMACRO()

INSTALL_IMPORTED_DLLS(${OpenCV_LIBS} bin bin)

 参考:c++ - CMake - 安装第三方DLL依赖项 - Thinbug

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值