如何使用cmake函數get_先決條件和get_filename_component來實現目標依賴安裝?

[英]how to use the cmake functions get_prerequisites and get_filename_component for target dependency installation?


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.

我們已經建立了一個具有外部共享庫依賴關系的cmake項目。我們希望使用CPack打包項目的二進制文件和依賴項。然而,當我們試圖尋找目標的依賴時,我們在windows和linux系統上得到了不同的結果。

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.

我們看了CMake的get先決條件模塊(2.8.12)。我們已經成功地使用了下面的CMake代碼,以獲得linux上CMake目標(二進制)依賴(_libFile)的完整路徑,但是我們並沒有獲得對windows依賴的完整路徑。在Windows上,變量依賴於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)

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

所以問題是:為什么我們在windows和linux上的依賴位置會得到不同的結果?

1 个解决方案

#1


9  

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.)

get_先決條件返回的引用不是絕對完整的路徑引用,而且它們也不能通過一個簡單的get_filename_component調用返回絕對引用。(在Mac上,它們可能包含@executable_path,例如。)

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

但是,在get先決條件中還有另一個函數。cmake模塊名為gp_resolve_item,可以在這里幫助您。

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.

這應該將DLL名稱轉換為DLL的完整路徑位置,假設它們在您的路徑中。如果它們位於其他目錄中,您可能需要將它們作為“dirs”參數提供給get_先決條件和gp_resolve_item。

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

get先決條件的文檔。cmake模塊在這里:http://www.cmake.org/cmake/help/v3.0/module/get先決條件。html。

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

而且,可能還會深入到BundleUtilities。cmake模塊查看它如何使用get先決條件。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/06/23/72f5e4c721ef6b88c4896690e7338208.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com