[Cmake] Building a common static lib from multiple directories...

Andy Cedilnik andy.cedilnik at kitware.com
Mon Mar 10 07:34:23 EST 2003


Hi Jean,

What you can do is instead of using SUBDIRS, you include subdirectories:
PROJECT(Driver)

INCLUDE(${Driver_SOURCE_DIR}/drivers_1/CMakeLists.txt)
INCLUDE(${Driver_SOURCE_DIR}/drivers_2/CMakeLists.txt)
...

ADD_LIBRARY(drivers ${drivers_1_SRCS} ${drivers_2_SRCS} ...)

And all the CMakeLists.txt files would look like this:

SET(drivers_1_SRCS
    ${Driver_SOURCE_DIR}/drivers_1/toto.cpp
    ${Driver_SOURCE_DIR}/drivers_1/titi.cpp
    ...)

This will not create libdrivers_1.a and libdrivers_2.a, but you will
have the libdrivers.a. If you want those, you can always say:

INCLUDE(${Driver_SOURCE_DIR}/drivers_1/CMakeLists.txt)
INCLUDE(${Driver_SOURCE_DIR}/drivers_2/CMakeLists.txt)
...

ADD_LIBRARY(drivers_1 ${drivers_1_SRCS})
ADD_LIBRARY(drivers_2 ${drivers_2_SRCS})
ADD_LIBRARY(drivers ${drivers_1_SRCS} ${drivers_2_SRCS} ...)

				Andy

On Mon, 2003-03-10 at 04:38, Jean-Francois LECOMTE wrote:
> Just another question from a newbie.
> I've the following directory structures
> 
> d drivers
> f drivers/driver.h
> d drivers/drivers_1
> f drivers/drivers_1/toto.cpp
> f drivers/drivers_1/titi.cpp
> ...
> d drivers/drivers_2
> f drivers/drivers_2/tata.cpp
> ...
> 
> 
> i would like to have one CMakeList.txt in each subdirectory
> drivers/drivers_* to build each driver separate from another one in a
> convenient static library (libdrivers_1.a, libdrivers_2.a, ...) then
> link all theses libraries in a common one, libdrivers.a...
> 
> I've no idea how to make this with CMake.
> Maybe the way i choose my directories structures is wrong. This
> convenient libraries method comes from the autoconf philosophy.
> 
> Many thanks.
>  





More information about the CMake mailing list