CMake Static Lib
Hi
I've got a question on cmake on which i have not found an answer for in the docs so far. I have a program A, a static library B, and an external library C. A,B are written by me and are cmake projects. A depends on B, B depends on C. Now when A wants to use B, it needs to link both B and C. For example like this: target_link_libraries(A B C) However that makes A depend on the internals of B. It does not need to know that B uses C internally. How do i make cmake link the library dependencies of B automatically? Thanks in advance Frank |
Hi -
If you want to make CMake guess the dependency order, without telling it, then you need to use the special "prescience" switch: Quote:
http://www.cmake.org/pipermail/cmake...ry/019020.html However, there are also tools like "gencmake" freely available: http://www.cmake.org/Wiki/CMake#Basi...atch-generator 'Hope that helps .. PSM |
Hi
thanks for your reply. Unfortunately i think you misunderstood my problem: I do not have a build/dependency order problem. I simply want A to learn about the libraries that B links, without having to tell A explicitely WHICH library B links. Let's consider an example: Say A is a GUI program which can display images. Now there is a library B, which contains an image class and ways to load various image formats into this image class. Now of course this library depends on other libraries such as libpng, libjpeg, whatever. What I want now is: I want to tell the cmake file of A to link B, and all dependencies that B has (in this case: libpng, libjpeg). But I do not explicitely want to tell A to link libpng,libjpeg. It is supposed to learn that from B. All this is not a matter of functionality - just a matter of encapsulation. I do not want a library user of B to have to worry about which libraries B uses. In qmake this is done with create_prl and link_prl (see [1]): One uses the create_prl option on B. This makes the compilation of B write a special .prl file that encodes A's dependencies. Now the link_prl option is used on A, which in turn reads the .prl file (and thus the dependencies of B) and links them automatically. Thats exactly the functionality I want - but I did not find a way to achieve this in cmake. Did that clarify things? Thanks again Frank [1] http://doc.trolltech.com/4.5/qmake-e...html#libdepend |
I have not done much serious work in cmake, but this sort of problem can be solved (in the “autoconf way”) by using libtool inter-library dependencies, which work on both static and shared archives (in fact, the purpose of libtool is to make the choice of static vs. shared transparent to the user).
|
Exporting and Importing Targets
I think this should answer your question
www cmake org /Wiki/CMake_2.6_Notes#Importing_Targets daniel Quote:
|
18 months later, I'd like to revive that thread...
The link provided by daniel77.linux (now http://www.cmake.org/Wiki/CMake/Tuto...orting_Targets) describes a method that allows a project to generate a .cmake file that can then be imported by another project. That seems to be a good direction. Dtag, have you managed to solve your particular problem? Could you describe your solution? Regards |
All times are GMT -5. The time now is 12:11 PM. |