[CMake] static library from several subdirectories

Alexander Neundorf a.neundorf-work at gmx.net
Fri Mar 12 13:21:44 EST 2010


On Friday 12 March 2010, Verweij, Arjen wrote:
> Hi,
>
> >> For a legacy FORTRAN project, I'm looking for a cmake-way to create a
> >> static library from several subdirectories. The current solution is
> >
> >using a
> >
> >> custom POST_BUILD step with ar and ranlib, but the resulting archive
> >
> >is not
> >
> >> known to cmake and can't be used to link to the main.
> >
> >You can just list all source files in the top level CMakeLists.txt, no
> >matter
> >whether they are in a subdirectory or in the same directory.
> >
> >Alex
>
> Hopefully I'm misunderstanding you, since otherwise the list would contain
> close to 4000 files.

Well, I don't see a real problem with this. If this makes your files too long, 
just separate the setting of these source-variables into separate files.

> But I took a look at Michael Wild's approach (thanks Tyler) which leads me
> to believe there is no clean way to go about it. I suppose in the spirit of
> his solution I could create a global list of the archives I obtain, and
> feed them to target_link_libraries (myexecutable
> ${my_global_list_of_archives}) in the same scope where I call
> add_executable().

If you are creating an executable (I thought you were creating a static 
library as end result), you can just link your executable against all these 
static libs.

Alex


More information about the CMake mailing list