[Cmake] CMakeLists setup for simple problem

Brad King brad.king at kitware.com
Tue Jun 1 10:45:10 EDT 2004


michael_cm at gmx.ch wrote:
> Hi,
> 
> I would like to set up the following directory structure:
> 
> src_dir/common
> src_dir/app1
> src_dir/app2
> ...
> 
> 
> In the directory 'common', I'd like to have classes used by application1 and
> application2 (and some more applications). The files belonging to these
> applications (including the file with the main() function) are stored in
> 'app1', 'app2' and so on.
> 
> I'd like to use cmake to create my make files, since I'd like to compile the
> project on different platforms.
> 
> Unfortunately I didn't really get it to work and would therefore like to
> know how to properly set up the CMakeLists.txt files for this (I guess)
> simple problem.

# src_dir/CMakeLists.txt
PROJECT(MYPROJ)
INCLUDE_DIRECTORIES(${MYPROJ_SOURCE_DIR}/common)
SUBDIRS(common app1 app2)

# src_dir/common/CMakeLists.txt
ADD_LIBRARY(mycommon src1.cxx src2.cxx)

# src_dir/app1/CMakeLists.txt
ADD_EXECUTABLE(app1 app1.cxx)
TARGET_LINK_LIBRARIES(app1 mycommon)

# src_dir/app2/CMakeLists.txt
ADD_EXECUTABLE(app2 app2.cxx)
TARGET_LINK_LIBRARIES(app2 mycommon)

-Brad


More information about the Cmake mailing list