6

Is it possible to get CMake to gather up all the package libraries used during compilation, recursively grab their required libraries, and then put them all in a single directory?

As an example if my application requires gtk it would grab glib and its required libraries libiconv, gettext, and libffi.

Jason Smith
  • 765
  • 8
  • 23
  • 2
    I don't think that CMake has this, but you could write a script that recursively walks through all dependencies using `ldd` and copies discovered libraries to your directory (and call it from cmake) – szx Jun 28 '14 at 08:07
  • 1
    Agreed, from the overview standpoint, CMake provides the tools to test if needed libraries are available for the build, collect the library locations and obtain the cflags and ldflags information needed so that a multi-file/directory compilation can complete successfully. Within the CMakeLists.txt files, and others, you have the freedom to use script type commands to move data to desired directories to create a more efficient layout. – David C. Rankin Jun 28 '14 at 09:03
  • Not sure why this was down voted .. interesting question. :) What you want is not part of core CMake functionality (AFAIK) but you can write a script which does this. Why not just generate a native package instead of storing dependencies? – wojciii Jun 28 '14 at 10:35
  • Ldd might work. I'm trying to do this for a cross compiling system, linux and mingw-w64, so that I can determine what has changed between library versions. Then I can create a patch with just the updated files. – Jason Smith Jun 28 '14 at 17:19
  • It seems that between ldd and i686-w64-mingw32-objdump I should be able to get what I need for a script to go through and gather up the libraries. – Jason Smith Jun 28 '14 at 18:32
  • 1
    Since your title mentions "deploying"... It is certainly feasible to deploy dependencies in CMake "post-build". I would suggest looking at http://stackoverflow.com/q/6173915/417197 or http://stackoverflow.com/q/5970845/417197 or http://stackoverflow.com/q/13577979/417197. – André Jun 29 '14 at 07:20
  • I have indeed done this with a `shell script` and `ldd`. However, the end result might or might not work on some other Linux distribution if you just deploy ALL libraries so you have to be careful which libraries you include. Static linking makes things easier if it doesn't violate licensing. – juzzlin Mar 22 '16 at 20:54

1 Answers1

2

You can use the GetPrerequesites CMake module. See here for more information

Dimitri Merejkowsky
  • 1,001
  • 10
  • 12
  • I had been using the ldd and i686-w64-mingw32-objdump method, but this module does make life a little easier and it works across platforms. Thank you for the tip. – Jason Smith Apr 01 '16 at 18:32