如何使用cmake函数get_prerequisites和get_filename_component用于目标依赖关系安装? [英] how to use the cmake functions get_prerequisites and get_filename_component for target dependency installation?

查看:380
本文介绍了如何使用cmake函数get_prerequisites和get_filename_component用于目标依赖关系安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经设置了一个包含外部共享库依赖项的cmake项目。我们想使用CPack打包我们项目的二进制文件和依赖关系。但是,当我们尝试找到目标的依赖关系时,我们在windows和linux系统上得到不同的结果。



我们看了一下CMake的GetPrerequisites模块(2.8.12)。我们已经成功地使用了下面的CMake代码来获取一个CMake目标的完整路径(BINARY )dependency(_libFile)on linux,但是我们没有得到一个依赖关于windows的完整路径。在Windows上,变量dependency_realpath保存类似$ {CMAKE_SOURCE_DIR} / DEPENDENCY_FILE的东西,这不是正确的依赖路径。

  string (TOUPPER$ {CMAKE_BUILD_TYPE}CONFIG)
GET_TARGET_PROPERTY(MY_BINARY_LOCATION $ {BINARY} LOCATION _ $ {CONFIG})
GET_PREREQUISITES($ {MY_BINARY_LOCATION} DEPENDENCIES 0 0)

foreach(DEPENDENCY_FILE $ {DEPENDENCIES})
get_filename_component(dependency_realpath $ {DEPENDENCY_FILE} REALPATH)

所以问题是:为什么我们对windows和linux上的依赖关系位置有不同的结果?

解决方案

get_prerequisites返回的引用不是绝对全路径引用,它们也不能通过简单的get_filename_component调用来解析为绝对引用。 (在Mac上,例如,它们可能包含@executable_path。)



但是,GetPrerequisites.cmake模块中有另一个函数gp_resolve_item可以帮助你。 / p>

尝试此操作:

  get_prerequisites($ {MY_BINARY_LOCATION} DEPENDENCIES 0 0 )

foreach(DEPENDENCY_FILE $ {DEPENDENCIES})
gp_resolve_item($ {MY_BINARY_LOCATION}$ {DEPENDENCY_FILE} (resolved_file ='$ {resolved_file}')
endforeach()

将DLL名称转换为DLL的完整路径位置,假设它们在您的PATH中。如果它们在某些其他目录中,您可能需要提供这些作为get_prerequisites和gp_resolve_item的dirs参数。



GetPrerequisites.cmake模块的文档在这里: http://www.cmake.org/cmake/help/v3.0/module /GetPrerequisites.html



此外,还可以深入了解BundleUtilities.cmake模块,了解如何使用GetPrerequisites。


We have set up a cmake project with external shared library dependencies. We want to package the binaries and dependencies of our project using CPack. However we are getting different results on windows and linux systems when trying to find dependencies of our targets.

We had a look at the GetPrerequisites Module of CMake (2.8.12).We have successfully used the following CMake code to get the full path of a CMake target (BINARY) dependency (_libFile) on linux, however we don't get a the full path of the dependency on windows. On Windows the variable dependency_realpath holds something like ${CMAKE_SOURCE_DIR}/DEPENDENCY_FILE, which is not the correct path to the dependency.

string(TOUPPER "${CMAKE_BUILD_TYPE}" CONFIG)
GET_TARGET_PROPERTY(MY_BINARY_LOCATION ${BINARY} LOCATION_${CONFIG} )
GET_PREREQUISITES(${MY_BINARY_LOCATION} DEPENDENCIES 0 0 "" "")

foreach( DEPENDENCY_FILE ${DEPENDENCIES})
    get_filename_component( dependency_realpath ${DEPENDENCY_FILE} REALPATH)

So the question would be: Why are we getting different results for the dependency locations on windows and linux?

解决方案

The references that get_prerequisites returns are not absolute full path references, and they are also not resolve-able to absolute references via a simple get_filename_component call. (On Mac, they may contain @executable_path, for instance.)

However, there is another function in the GetPrerequisites.cmake module called gp_resolve_item that can help you here.

Try this:

get_prerequisites(${MY_BINARY_LOCATION} DEPENDENCIES 0 0 "" "")

foreach(DEPENDENCY_FILE ${DEPENDENCIES})
  gp_resolve_item("${MY_BINARY_LOCATION}" "${DEPENDENCY_FILE}" "" "" resolved_file)
  message("resolved_file='${resolved_file}'")
endforeach()

That should convert DLL names into full path locations of the DLLs, assuming they are in your PATH. If they are in some other directories, you may need to provide those as the "dirs" arguments to get_prerequisites and gp_resolve_item.

The documentation for the GetPrerequisites.cmake module is here: http://www.cmake.org/cmake/help/v3.0/module/GetPrerequisites.html

Also, possibly dig into the BundleUtilities.cmake module to see how it uses GetPrerequisites.

这篇关于如何使用cmake函数get_prerequisites和get_filename_component用于目标依赖关系安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆