LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 05-22-2009, 11:56 AM   #1
Dtag
LQ Newbie
 
Registered: May 2009
Posts: 7

Rep: Reputation: 0
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

Last edited by Dtag; 05-22-2009 at 11:57 AM.
 
Old 05-22-2009, 03:59 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,858
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

If you want to make CMake guess the dependency order, without telling it, then you need to use the special "prescience" switch:
Quote:
EXAMPLE:

cmake -prescience my_exe
Seriously: you do need to specify the dependency, and one usually does it manually. For example:

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

Last edited by paulsm4; 05-22-2009 at 04:00 PM.
 
Old 05-22-2009, 04:29 PM   #3
Dtag
LQ Newbie
 
Registered: May 2009
Posts: 7

Original Poster
Rep: Reputation: 0
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
 
Old 05-23-2009, 03:26 AM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 64
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).
 
Old 08-31-2010, 03:09 AM   #5
daniel77.linux
LQ Newbie
 
Registered: Aug 2010
Posts: 1

Rep: Reputation: 0
Exporting and Importing Targets

I think this should answer your question
www cmake org /Wiki/CMake_2.6_Notes#Importing_Targets

daniel

Quote:
Originally Posted by Dtag View Post
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

Last edited by daniel77.linux; 08-31-2010 at 03:12 AM.
 
Old 02-08-2012, 12:15 AM   #6
bricedebrignaisplage
Member
 
Registered: Apr 2006
Location: singapore
Distribution: debian
Posts: 51

Rep: Reputation: 16
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
 
  


Reply

Tags
cmake


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CMake Static Lib Dtag Programming 0 05-23-2009 07:44 PM
cmake question yfaye Programming 3 04-09-2009 09:24 PM
Making a static lib from objects + static libs kovacsp Programming 2 12-19-2007 12:53 PM
audacity unable to locate required lib files present in /usr/lib/ adityavpratap Slackware 4 11-30-2006 06:06 AM
How do I create a static lib with g++? BrianK Programming 1 05-27-2005 07:30 PM


All times are GMT -5. The time now is 08:40 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration