[CMake] Add subdir and library in CmakeList.txt

Karr, David A. David.Karr at titan.com
Mon Sep 26 11:42:02 EDT 2005


I have a project on which we've used CMake to do something similar 
for at least a couple of years now.  I see just two notable 
differences between what we've done and what you want to do:

1. In the CMakeLists.txt file in the parent directory, our
ADD_LIBRARY command occurs _before_ the SUBDIRS command, not after.

2. We've never upgraded the version of CMake since installing it on
this project, so we're still on version 1.6.7.

This CMakeLists.txt worked in VC++ and in a Linux gcc environment.

Coincidentally, I just spent a few hours last week redesigning the 
libraries of that project, as a result of which I moved the original
ADD_LIBRARY command from the parent directory into a new subdirectory.
It was always awkward having a library built in a directory above the
directories where other libraries were built, not just because of 
CMake, and I was ready to take any excuse for not doing that any more.

David Karr


> From: "Jonick, Kathy-P57450" <Kathleen.Jonick at gdc4s.com>
> Subject: RE: [CMake] Add subdir and library in CmakeList.txt
> To: <cmake at cmake.org>
> Message-ID:
> 	<C7FCC5C93630AB4E80049ED163FFD2247BABC5 at AZ25EXM04.gddsi.com>
> Content-Type: text/plain;	charset="us-ascii"
> 
> File1.c is location in the current directory.  But it is looking in
the
> directory listed in the SUBDIRS command.  I wanted it to build those
> directories, then create the library in the current directory.
> 
> Thanks!
> 
> Kathy
> 
> >Is it possible to include a SUBDIR list as well as a library in one
> CMakeList.txt file?
> >
> >I want to be able to build a library in the current directory, as
well
> as call the CMakeList.txt file in 2 subdirectories.  My CMakeList.txt
> file looks like:
> >SUBDIRS(dir1 dir2)
> >
> >SET(SOURCES <file list> )
> >
> >ADD_LIBRARY(libname SHARED ${SOURCES})
> >
> >But when I run cmake, I get messages looking for the files listed in
> the subdirectories, rather than the current directory:
> >CMake Error: can not find file
> >/home/cmake_demo/current_dir/dir1/file1.c
> >
> >Tried .c .C .c++ .cc .cpp .cxx .m .M .mm .h .h++ .hm .hpp .hxx .in
.txx
> >
> >Is this possible?  If not, how do I build the library in current dir?




More information about the CMake mailing list