[CMake] How to build a library divided in many directories ?

Andreas Schneider mail at cynapses.org
Mon Feb 25 06:10:33 EST 2008


packadal wrote:
> Looks like the right way to do this would be to write a CMakeLists.txt 
> in each subdirectory, as this would be cleaner, and much more 
> changes-friendly, but I can't seem to build only one library when I do 
> it this way.
> 
> example of my source tree :
> 
> + src
> |   - Application
> |   - Attributes
> |   - Audio
> .
> .
> .
> |   - Utils
> 
> Each directory containing multiple source files for the lib.
> I managed to build the library, putting each and every file in a single 
> variable in one file, but this is looking quite ugly...
> 
> So how should i do please ?
> 

Create a CMakeLists.txt in every subdirectory

src/CMakeLists.txt:
add_subdirectory(Application)
add_subdirectory(Attributes)
..

set(foo_SRCS
   ${Application_SRCS}
   ${Attributes_SRCS}
)


src/Application/CMakeLists.txt:
SET(Application_SRCS
   foo.c
   foo2.c
   CACHE INTERNAL
)

src/Attributes/CMakeLists.txt:
SET(Attribues_SRCS
   foo.c
   foo2.c
   CACHE INTERNAL
)


or create static libs for every subdirectory and link them together to a 
shared library.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 257 bytes
Desc: OpenPGP digital signature
Url : http://public.kitware.com/pipermail/cmake/attachments/20080225/58b22dd8/signature.pgp


More information about the CMake mailing list