[Cmake] Simple building question:

Brad King brad.king at kitware.com
Thu, 25 Mar 2004 15:56:16 -0500


Bernhard Glück wrote:

> In response to my previous post ( which seemed to complicated ) i will 
> formulate my questions in easier parts.
> 
> How do you people go on building a whole directory tree into one 
> library/executable ?
> Suppose you have a root dir with many sub directories and sub sub 
> directories full of source files and want to build them all into one
> library.. How do you organize that ?

Create a CMakeLists.txt file in the root of the directory containing all 
the sources.  Use a command like this to create the library:

ADD_LIBRARY(mylib
   src1.cxx
   src2.cxx
   DirA/src3.cxx
   DirB/src4.cxx
   # ...
)

While listing all the source files explicitly may seem tedious the first 
time, it is not very hard to maintain.  Also, unless the CMakeLists.txt 
file changes when a new source file is added, there is no way that the 
native build system can know that CMake needs to be rerun to add the 
source to the build.  Therefore a command like AUX_SOURCE_DIRECTORY 
should not be used in this case.

-Brad