我正在使用一个预编译的第三方库,它有多个 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
到目前为止,我们一直在复制thirdpartydep/bin
目录使用copy_if_different
并手动列出 DLL 的路径。我正在尝试设置install
正确定位以复制 dllthirdpartydep/bin
to 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()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)