CMake QT_LIBRARIES 二进制等效项

发布于 2024-11-18 09:26:57 字数 102 浏览 0 评论 0原文

我想在构建后步骤中复制所需的二进制文件。该变量是否有一个版本列出了与库关联的二进制文件?像 ${QT_BINARIES} 这样的东西会列出专门针对所包含模块的文件。

I want to copy the required binary files in my post-build step. Is there a version of this variable listing the binary files associated with the libraries? Something like ${QT_BINARIES} which would list the files specifically for the modules included.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小矜持 2024-11-25 09:26:57

是的,有一个 $(QT_LIBRARIES),它将包含您请求的那些 Qt-dll(及其依赖项)。

与变量 $(QT_BINARY_DIR) 结合使用,您可以重建二进制文件列表。例如,Windows 上的类似以下内容(从我自己的构建后 cmakefile 中删除)。

foreach( Qt_library ${QT_LIBRARIES} )
    get_filename_component( Qt_library_name ${Qt_library} NAME_WE )
    # Note: the following Regex works for me on windows, I am not sure if it 
    # fully portable.
    string( REGEX REPLACE "^lib(.*)" "\\1" Qt_library_name ${Qt_library_name} )

    set( Qt_shared_library ${QT_BINARY_DIR}/${Qt_library_name}.dll )
    if( EXISTS ${Qt_shared_library} )
        # Add it to the list of 'desired' qt-libraries for later installation
        list( APPEND Qt_Install_Libraries ${Qt_shared_library} )
    endif( EXISTS ${Qt_shared_library} )
endforeach( Qt_library ${QT_LIBRARIES} )
list( REMOVE_DUPLICATES Qt_Install_Libraries )
install( FILES ${Qt_Install_Libraries} DESTINATION bin COMPONENT ThirdParty )

在本例中,我在最后一行使用了安装命令,但当然您可以将其替换为副本。

Yes, there is a $(QT_LIBRARIES), which will contain those Qt-dlls you requested (and their dependencies).

In combination with the variable $(QT_BINARY_DIR) you could reconstruct a list of the binaries. E.g. something like the following (stripped from my own post-build cmakefile) on Windows.

foreach( Qt_library ${QT_LIBRARIES} )
    get_filename_component( Qt_library_name ${Qt_library} NAME_WE )
    # Note: the following Regex works for me on windows, I am not sure if it 
    # fully portable.
    string( REGEX REPLACE "^lib(.*)" "\\1" Qt_library_name ${Qt_library_name} )

    set( Qt_shared_library ${QT_BINARY_DIR}/${Qt_library_name}.dll )
    if( EXISTS ${Qt_shared_library} )
        # Add it to the list of 'desired' qt-libraries for later installation
        list( APPEND Qt_Install_Libraries ${Qt_shared_library} )
    endif( EXISTS ${Qt_shared_library} )
endforeach( Qt_library ${QT_LIBRARIES} )
list( REMOVE_DUPLICATES Qt_Install_Libraries )
install( FILES ${Qt_Install_Libraries} DESTINATION bin COMPONENT ThirdParty )

In this case I used an install-command on the last line, but certainly you could replace it with a copy.

带上头具痛哭 2024-11-25 09:26:57

您还应该考虑查看 CMake 的 BundleUtilities 功能,该功能可以分析共享库先决条件,复制必要的“非系统”库(甚至修复它们以在 Mac 上使用 @executable_path 引用),并使您的可执行文件准备好使用自己的库必要库的私人副本。

请参阅此处的示例: http://www.cmake.org/Wiki/BundleUtilitiesExample

它特别有用仅拉入可执行文件实际引用的 Qt 库...

执行此操作后,您将获得捆绑应用程序的“独立”副本(或在同一目录中具有共享库的可执行文件),可以安全地使用它复制的到另一台机器。

You should also consider reviewing CMake's BundleUtilities capability, which analyzes shared library prerequisites, copies in necessary "non-system" libraries (and even fixes them up to use @executable_path references on the Mac), and leaves your executable ready to roll with its own private copies of the necessary libraries.

See the example here: http://www.cmake.org/Wiki/BundleUtilitiesExample

It's especially useful for pulling in only those Qt libraries actually referenced by your executable...

After this operation, you're left with a "stand-alone" copy of your bundle app (or executable with shared libraries in the same directory) that can be safely copied to another machine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文