Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

cmake

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?

like image 219
tisch Avatar asked Jun 23 '14 13:06

tisch


People also ask

How to manage dependencies with CMake?

There are a lot of ways of managing dependencies with CMake, so let’s to a quick overview of possible ways. The simplest way of doing dependency management is to simply copy source code of your dependencies into your project source directory.

What is get_prerequisites in CMake?

GetPrerequisites.cmake. get_prerequisites is a lower level function that allow you to get the dependencies. The thing is, I don't any good way/best practice to use it.

How do I install a shared library in CMake?

To install shared library dependencies, you can use the same file (INSTALL) command that CMake itself uses in cmake_install.cmake if you build a shared library target. It uses the TYPE SHARED_LIBRARY option to add some extra processing. The FOLLOW_SYMLINK_CHAIN option is also especially handy.

How do I evaluate the results of CMake installation?

(In fact, install (CODE ...) inserts the given code right into the current directory's cmake_install.cmake script. You can examine the results just by looking at that file, without even having to run the install.) The delayed evaluation also comes with a few wrinkles.


1 Answers

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.

like image 105
DLRdave Avatar answered Nov 03 '22 02:11

DLRdave