[Cmake] Newbie Question...

Brad King brad . king at kitware . com
Wed, 23 Jul 2003 08:46:08 -0400 (EDT)


> I am new to CMake. I was wondering do I use FIND_LIBRARY or LINK_LIBRARY
> command to link in static and shared libraries?

If the library is not part of your project, use FIND_LIBRARY to find it
and TARGET_LINK_LIBRARIES to link it to one of your targets.  If the
library is part of your project, just use TARGET_LINK_LIBRARIES.

> Also, where do I specify the inclusion of header files? For a simple
> project do I just specify the headers along with the .cxx files in the
> ADD_EXECUTABLE command?

If you want your headers to show up in a VS project, add them with the
source files as you suggested.  If you want to specify include directories
in which to find headers, use the INCLUDE_DIRECTORIES command.

> Finally, can I anyone make a recommendation on how I would
> establish a CMakeLists.txt file for the following:
>
> MyProjects/
> -->lib_1/
> -->lib_2/  (depends on lib1)
> -->lib_3/  (depends on lib2 and lib1)
> -->exec/ (depends lib2 and lib3)
>
> I would I write a CMakeLists.txt for every sub directories? Then have
> one root CMakeLists.txt that would create the dependencies by using the
> SUBDIR command?

This is correct.  Just specify the following order in the top-level
listfile:

SUBDIRS(lib_1 lib_2 lib_3 exec)

Don't forget to use TARGET_LINK_LIBRARIES in each library directory to
link it to those on which it depends.

-Brad