[CMake] SubDirs and Libraries

Brad King brad.king at kitware.com
Wed Oct 4 17:46:04 EDT 2006


Peter Kahn wrote:
> What is the standard way of having cmake access libaries built on the
> same subdir level?
> 
> I have a project with two subdirs: Util and App.   Util builds a
> library called 'utillib'.  Ap builds a
> library and an exe (aplib, and ap.exe).
> Main\
>    CMakeLists.tst
>    Util\CMakeLists.txt
>    App\CmakeLists.txt
> 
> If I define the utillib in Main\Util\CMakeLists.txt  how can the
> Main\App\CMakeLists.txt use it?  Should I define something in
> Main\CMakeLists.txt first and then populate it when Main\Util builds?

Just reference targets by their logical name (given to ADD_EXECUTABLE or
ADD_LIBRARY commands).

# CMakeLists.txt
ADD_SUBDIRECTORY(Util)
ADD_SUBDIRECTORY(App)

# Util/CMakeLists.txt
ADD_LIBRARY(mylib ...)

# App/CMakeLists.txt
ADD_EXECUTABLE(myexe ...)
TARGET_LINK_LIBRARIES(myexe mylib)

-Brad



More information about the CMake mailing list