[CMake] Build multiple lib

Ryan Pavlik rpavlik at iastate.edu
Wed Sep 22 13:18:08 EDT 2010


On Wed, Sep 22, 2010 at 11:19 AM, Andrea Galeazzi <galeazzi at korg.it> wrote:

> Citando Michael Wild <themiwi at gmail.com>:
>
>
>
>> On 22. Sep, 2010, at 12:48 , Andrea Galeazzi wrote:
>>
>>  Hi everybody,
>>> I've got a static lib project in vc6 as follow
>>> lib1
>>> lib2
>>> ......
>>> libN
>>> MainLib
>>>
>>> The MainLib doesn't actually have any source but it depends form  all the
>>> other projects (lib1,.....,libN) so it builds a static lib  which contains
>>> all the ones.
>>> Now my problems is how to write a CMakeLists in order to reproduce  both
>>> the same build and the same structure of solution in VS 2010  as the
>>> original one.
>>> Does anybody have any ideas?
>>> Cheers
>>>
>>
>> Do you ever *need* lib1..libN except for assembling MainLib? If not,  just
>> drop them, they're useless.
>>
>> Michael
>>
>> --
>> There is always a well-known solution to every human problem --  neat,
>> plausible, and wrong.
>> H. L. Mencken
>>
>>
>>
> That's true but how can I then generate a vcprj for each lib? Now my
> filesystem is:
> MainLib
>    CMakeLists.txt
>    +lib1
>       CMakeLists.txt
>       source1_1
>       source1_2
>       ........
>    +lib2
>       CMakeLists.txt
>       source2_1
>       source2_2
>       ........
>     ..........
>     +libN
>       CMakeLists.txt
>       sourceN_1
>       sourceN_2
>       ........
>
> CMakeLists.txt in MainLib has:
> add_library(MainLib STATIC )
> add_subdirectory(lib1)
> ...........
> target_link_libraries (MainLib lib1)
>
> it produces a right vs solution but it dosen't produce the MainLib.lib
>
>
>
If you want to do the separate vcproj files for each separate library, you
probably need to make mainlib shared and add an empty dummy.cxx file in your
add_library call.  (A static library is pretty much just a bunch of object
files glued together, so you don't really "link" a static library, in my
understanding, you just need to track those transitive link dependencies for
whatever ends up using your library).

The alternate, and preferred, technique would be to build a single library
for mainlib, and separate the sources for the "sub-components" using
source_group instead of projects.  There shouldn't really be a difference in
link time or build time, and since you probably should be using the solution
file rather the individual vcproj files to launch your environment, there's
really be very little effective difference.

Ryan
-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100922/f258efa5/attachment.htm>


More information about the CMake mailing list