[Cmake] Combining Separate CMake Projects

Brad King brad.king at kitware.com
Mon Jun 28 10:06:49 EDT 2004


Chris Scharver wrote:
> Hi,
> 
> I have several CMake-configurable directories. They're primarily used 
> for stand-alone libraries, and then I have a final application that uses 
> all the libraries. When I build the application, I want to combine the 
> separate CMake projects together into a single build directory. The 
> directory structure is as follows (... indicates source files):
> 
> library1/
>     CMakeLists.txt
>     ...
> library2/
>     CMakeLists.txt
>     ...
> application/
>     CMakeLists.txt
>     data/
>     source/
>         CMakeLists.txt
>         ...
> 
> I have been building each library separately, and then I build the 
> application pointing it toward the libraries' include and build 
> directories. What I want to do is create the build relative to the 
> application directory. Currently, I'm doing this using 
> SUBDIRS(../library1 ../library2 source). However, when I build, this 
> creates the incorrect build directory structure. The libraries' object 
> directories are parallel to application's build directory. I get this:
> 
> build/
>     source/
> library1/
> library2/
> 
> What I want is this:
> 
> build/
>     library1/
>     library2/
>     source/
> 
> Is there something that I could use other than SUBDIRS? The libraries 
> can stand alone, but I want to compile such that building the 
> application ensures that the libraries are built within the build 
> directory. Is there something akin to SUBDIRS that will allow me to 
> import another CMake project? I noticed that I cannot use an absolute 
> path in the SUBDIRS command, but that seems exactly what I want to be 
> able to do. FIND_PACKAGE doesn't seem to be quite what I'm looking 
> for--I want everything built from one CMake run without having to go 
> through several CMake-configure-build cycles for each directory. Any 
> help would be much appreciated.

As far as I know there is currently no way to do this short of setting 
up the build system to copy the library source directories into a 
subdirectory of the application.  What you want to do is easily 
accomplished by creating a single CMakeLists.txt file in the directory 
above all three source trees.  Doing this will allow the whole thing to 
be built as one application, but you will still be able to point cmake 
to one of the subdirectories to build it individually.

-Brad


More information about the Cmake mailing list