gpt4 book ai didi

c++ - CMake - 安装第三方 dll 依赖项

转载 作者:太空狗 更新时间:2023-10-29 23:12:39 24 4
gpt4 key购买 nike

我正在使用具有多个 DLL 的预编译第三方库(一个用于实际的第三方,还有一些作为其自身的依赖项)我的目录结构如下

MyApp
CMakeLists.txt // Root CMake file
src
MyCode.cpp
thirdpartydep // Precompiled thirdparty dependency
FindThirdPartyDep.cmake
bin/
thirdparty.dll
thirdparty_dep1.dll
thirdparty_dep2.dll
include/
thirdparty.h
lib/
thirdparty.lib // this is the importlibrary that loads thirdparty.dll

到目前为止,我们一直在使用 copy_if_different 复制 thirdpartydep/bin 目录中的所有 DLL,并手动列出 DLL 的路径。我正在尝试正确设置 install 目标以将 thirdpartydep/bin 中的 dll 复制到 CMAKE_INSTALL_PREFIX/bin 但我不知道了解如何告诉 cmake 关于属于 thirdpartydep 的额外二进制文件。

最佳答案

如果您使用现代 CMake 并正确构建 CONFIG 第三方包 (* -config.cmake) 而不是 MODULES (Find*.cmake),那么这将起作用:

MACRO(INSTALL_ADD_IMPORTED_DLLS target_list target_component destination_folder)
foreach(one_trg ${target_list})
get_target_property(one_trg_type ${one_trg} TYPE)
if (NOT one_trg_type STREQUAL "INTERFACE_LIBRARY")
get_target_property(one_trg_dll_location ${one_trg} IMPORTED_LOCATION_RELEASE)
if( one_trg_dll_location MATCHES ".dll$")
install(FILES ${one_trg_dll_location} DESTINATION ${destination_folder} CONFIGURATIONS Release COMPONENT ${target_component})
endif()
get_target_property(one_trg_dll_location ${one_trg} IMPORTED_LOCATION_DEBUG)
if( one_trg_dll_location MATCHES ".dll$")
install(FILES ${one_trg_dll_location} DESTINATION ${destination_folder} CONFIGURATIONS Debug COMPONENT ${target_component})
endif()
endif()
endforeach()
ENDMACRO()

它是这样使用的:

set(THIRDPARTY_TARGETS "example_target1 example_target2 opencv_core")
if(MSVC)
INSTALL_ADD_IMPORTED_DLLS("${THIRDPARTY_TARGETS}" bin bin)
endif()

关于c++ - CMake - 安装第三方 dll 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44650008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com