cmake Windows .dll复制find_package命令
问题 为什么不将.dll复制到构建/发行/目录中,因为.EXE的构建?
Description
我使用此简单设置创建一个新的CMAKE文件:
cmake_minimum_required(VERSION 3.21)
project(use_sort)
find_package(sortdemo REQUIRED)
add_executable(example main.cpp)
target_link_libraries(example PRIVATE sortdemo::my_sort_lib sortdemo::my_print_lib)
该项目被配置为X64 Release链接到共享LIBS。 但是在Release文件夹中,我只能看到.exe,而无需.dll。
库my_sort_lib和my_print_lib是我在c:\ program文件中安装的库:
我不知道是否有必要,但是我也添加了这些库的cmakelists的链接: https://github.com/petrasvestartas/cmake/cmake/main/main/main/install_export
我尝试过的内容:
这不会复制任何DLL,
include(GNUInstallDirs )
install(
TARGETS "example"
RUNTIME_DEPENDENCIES
)
这给了我错误
include(GNUInstallDirs )
install(
TARGETS "example"
RUNTIME_DEPENDENCIES "sortdemo::my_sort_lib"
)
错误:
CMake Error at CMakeLists.txt:28 (install):
install TARGETS given unknown argument "sortdemo::my_sort_lib".
这也会给我错误,并且不可理解(使用另一个stackoverflow帖子中的答案)
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 "sortdemo::my_sort_lib" "sortdemo::my_print_lib")
if(MSVC)
INSTALL_ADD_IMPORTED_DLLS("${THIRDPARTY_TARGETS}" bin bin)
endif()
错误
Make Error at CMakeLists.txt:28 (get_target_property):
get_target_property() called with non-existent target "my_sort_lib".
Call Stack (most recent call first):
CMakeLists.txt:44 (INSTALL_ADD_IMPORTED_DLLS)
Question
Why .dlls are not copied to the build/Release/ directory as .exe is built?
Description
I create a new CMake file with this simple setup:
cmake_minimum_required(VERSION 3.21)
project(use_sort)
find_package(sortdemo REQUIRED)
add_executable(example main.cpp)
target_link_libraries(example PRIVATE sortdemo::my_sort_lib sortdemo::my_print_lib)
The project gets configured and installed as x64 Release linked to SHARED libs.
But in Release folder I can only see the .exe, without .dlls.
The libraries my_sort_lib and my_print_lib are my libraries that were installed before in C:\Program Files:
I do not know if it is necessary, but I also add a link to the CMakeLists of these libraries: https://github.com/petrasvestartas/CMAKE/tree/main/install_export
The full project is here:
https://github.com/petrasvestartas/CMAKE/tree/main/find_package
What I tried:
This does not copy any dlls
include(GNUInstallDirs )
install(
TARGETS "example"
RUNTIME_DEPENDENCIES
)
This gives me error
include(GNUInstallDirs )
install(
TARGETS "example"
RUNTIME_DEPENDENCIES "sortdemo::my_sort_lib"
)
Error:
CMake Error at CMakeLists.txt:28 (install):
install TARGETS given unknown argument "sortdemo::my_sort_lib".
This gives me error too and not understandable (use this answer from another stackoverflow post)
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 ".dllquot;)
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 ".dllquot;)
install(FILES ${one_trg_dll_location} DESTINATION ${destination_folder} CONFIGURATIONS Debug COMPONENT ${target_component})
endif()
endif()
endforeach()
ENDMACRO()
set(THIRDPARTY_TARGETS "sortdemo::my_sort_lib" "sortdemo::my_print_lib")
if(MSVC)
INSTALL_ADD_IMPORTED_DLLS("${THIRDPARTY_TARGETS}" bin bin)
endif()
Error
Make Error at CMakeLists.txt:28 (get_target_property):
get_target_property() called with non-existent target "my_sort_lib".
Call Stack (most recent call first):
CMakeLists.txt:44 (INSTALL_ADD_IMPORTED_DLLS)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论