mac*_*ard 7 c++ dll installation cmake
我正在使用一个预编译的第三方库,它有多个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
Run Code Online (Sandbox Code Playgroud)
到目前为止,我们一直在thirdpartydep/bin使用copy_if_different并手动列出 DLL 的路径来复制目录中的所有 DLL。我正在尝试正确设置install目标以将 dll 复制到其中thirdpartydep/bin,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()
Run Code Online (Sandbox Code Playgroud)
它的用法如下:
set(THIRDPARTY_TARGETS "example_target1 example_target2 opencv_core")
if(MSVC)
INSTALL_ADD_IMPORTED_DLLS("${THIRDPARTY_TARGETS}" bin bin)
endif()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4413 次 |
| 最近记录: |