[CMake] Adding one static library into another

Eric Nodwell enodwell at ucalgary.ca
Thu Apr 29 10:21:10 EDT 2010


Ryan,

Thanks for the reply.  I think the answer then is that, no it's not possible in CMake.  (Unless of course you have access to all the original source code.)

Just to be clear, the question was about adding objects to an existing static library (libA), so that the resulting static library (libB) is a superset of the original libA.

It's quite possible that this is something one should in principle not be trying to do.  (Although as per my example it can be done "by hand".)  Clearly, at the point where one compiles the library into an executable (or shared library), the end result is the same, whether one links in both a libA and a libB, or a single libB that is a superset of both.

In the current case, the static library is the final result of the particular build process.  It comes down to a difference of having to distribute only a libB (more convenient) or both libA and libB.

Eric



On 2010-04-28, at 3:47 PM, Ryan Pavlik wrote:

> This is a pretty frequently asked question - the short answer is, if you are building all the libraries yourself, just add all the source files to a single cmake static library, otherwise install a ____-config.cmake file that will automatically set a dependency.  Trying to do this apparently auto*-y ar trick is possible but ugly and "not the right way to do it".
> 
> Ryan
> 
> On 04/28/2010 02:57 PM, Eric Nodwell wrote:
>> Is there any way to have CMake make a new static library that includes the objects from another existing static library?
>> 
>> As an example (here a Linux-specific example) of doing this manually, suppose I have an existing library "libA.a", as well as an object file "B.o" that I have just compiled, and I want to combine the two of them into a single static library named "libB.a" .  By hand I could do this:
>> 
>> ar xv libA.a      # generates an A.o or something similar
>> ar rcs libB.a B.o A.o
>> 
>> Can this be done (in a cross-platform way) with CMake commands?
>> 
>> (Of course, if I have access to the source code for A, this is simple, but that may not always be the case.)
>> 
>> Thank you for any tips,
>> Eric
>> 
>> _______________________________________________
>> Powered by www.kitware.com
>> 
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>> 
>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>> 
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>>   
> 
> -- 
> Ryan Pavlik
> HCI Graduate Student
> Virtual Reality Applications Center
> Iowa State University
> 
> rpavlik at iastate.edu
> http://academic.cleardefinition.com
> Internal VRAC/HCI Site: http://tinyurl.com/rpavlik
> 
> 



More information about the CMake mailing list