[CMake] Joining multiple directories into one
Mathieu Malaterre
mathieu.malaterre at gmail.com
Mon Mar 9 10:18:16 EDT 2009
On Mon, Mar 9, 2009 at 3:03 PM, Brad King <brad.king at kitware.com> wrote:
> Jussi Pakkanen wrote:
>>
>> Hi all
>>
>> I'm looking into compiling OpenOffice.org with CMake. Currently it
>> uses dmake and a custom build tool. The basic structure is that every
>> logical component (Writer, widget toolkit etc) has its own
>> subdirectory. These are well separated.
>>
>> The problem comes from the internal structure of these components. The
>> most common case is that the component produces one product (usually a
>> shared library) from source files scattered in several different
>> subdirectories. As an example:
>>
>> dir1/foo.cxx
>> dir1/foo2.cxx
>> dir1/subdir/baz.cxx
>> dir2/sub1/ggg.cxx
>> dir2/sub2/rrr.cxx
>>
>> And so on and so on. Each subdirectory has a dmakefile that lists the
>> source files to use. I have written a parser that converts these to
>> CMake's syntax. Every component has a subdirectory called "util". This
>> is where the final product is defined and built. What I want to know
>> is what is the correct cross-platform way to do this in CMake. Here
>> are some choices I came up with so far:
>
> The easiest way is to put the add_library() call at the top-most directory
> which shares all the sources and use relative paths to list them
>
> add_library(mylib SHARED dir1/foo.cxx dir1/foo2.cxx ...)
This is the easiest way indeed. If you are still very picky (style,
convention, user mood) on where to list src file you can always list
file within subdirectory and from the toplevel directory request the
src for each directory:
toplevel/
ADD_SUBDIRECTORY(dir1)
GET_DIRECTORY_PROPERTY(dir1_srcs DIRECTORY dir1 DEFINITION DIR1_SRCS)
dir1/
SET(DIR1_SRCS
foo.cxx
foo2.cxx
)
2cts
--
Mathieu
More information about the CMake
mailing list