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并安装到目标路径下文章来源:https://www.toymoban.com/news/detail-630192.html
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文章来源地址https://www.toymoban.com/news/detail-630192.html
到了这里,关于CMake Install 安装第三方依赖库的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!