[CMake] static library from several subdirectories

Verweij, Arjen VerweijA at tass-safe.com
Tue Mar 16 17:30:03 EDT 2010


Hi Markus,

I have tested Michael's suggestion. It works wonders for combining source files into a single lib, regardless of the directory levels. For instance, I tested with:

CMakeLists.txt
a/CMakeLists.txt
a/liba.c
b/CMakeLists.txt
b/b/CMakeLists.txt
b/b/libb.c

Just keep add_subdirectory()'ing until you can add_sources( yourlib [sources] ). So if you have FORTRAN source, you should be done.

I don't have FORTRAN source, but .fr .f90r .cppr .cr .hr files that need to be preprocessed with fpp to obtain the resulting .f .f90 .cpp .c .h files, which can be used in add_sources(). This seem to cause problems with the setup I had so far, since I get the error:

  add_dependencies Adding dependency to non-existent target: bar3d
You have called ADD_LIBRARY for library madymo3d without any source files. This typically indicates a problem with your CMakeLists.txt file

If I manage to solve it I will report back here.

Regards,
Arjen


>-----Original Message-----
>From: cmake-bounces at cmake.org [mailto:cmake-bounces at cmake.org] On Behalf
>Of Markus Raab
>Sent: dinsdag 16 maart 2010 17:43
>To: cmake at cmake.org
>Subject: Re: [CMake] static library from several subdirectories
>
>Verweij, Arjen wrote:
>
>> I'm looking for a cmake-way to create a static library from several
>> subdirectories.
>
>I have exactly the same problem, please share if you get a good
>solution.
>
>What about collecting all files in a cache variable? Then you could add
>files per directory, but with a global scope. Could that work?
>
>I would really like to avoid to have them all listed in a file. cmake
>was
>the tool of choice, exactly because I want to get rid of a single
>configure.ac. This is important because folders might be excluded
>depending
>on options or available libraries.
>
>thank you
>Markus
>
>--
>http://www.markus-raab.org | Die Geschichte lehrt dauernd, aber sie
>                      -o)  | findet keine Schüler.  -- Dr. Ingeborg
>Kernel 2.6.24-1-a      /\  | Bachmann
>on a x86_64           _\_v |
>
>_______________________________________________
>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


More information about the CMake mailing list