[CMake] static library from several subdirectories

Verweij, Arjen VerweijA at tass-safe.com
Fri Mar 12 12:43:19 EST 2010


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.

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().

Arjen



More information about the CMake mailing list