[CMake] suggested or best-practice for independent subproject library

Jeet Sukumaran js473 at duke.edu
Sun May 12 03:17:21 EDT 2013



I have a project that includes (and is dependent on) some independent 
sub-projects, e.g.

     "project1"/
         CMakeLists.txt
         src/
             library1/
                 CMakeLists.txt
                 include/
                     <source files ...>
                 src/
                     <source files ...>
             main/
                 CMakeLists.txt
                 <source files ...>

"library1" is actually maintained as a git submodule, and is included in a
number of entirely different project, (e.g.  "project2", "project3", etc.).
Within each of these main or super projects like "project1", I want to just
build the library1 and statically link programs to it as needed (i.e., 
without
installing library1's headers and binaries to the installation destination).
It would be nice to provide the facility for a third-party use to build and
install library1 independentally (e.g. system-wide).

What is the recommended why to organize the build through CMake?

Right now, the CMakeLists.txt of "project1" explicitly adds
"src/library1/include" to the include path, and calls
`add_subdirectory(src/library1/src)` to build the library and statically 
links
to it. Is this a good practice? I read the page on package configuration and
it seems that the convention would be to create a package configuration
framework for library1, and then have "project1" call "find_package()". I
tried doing this, but could not get it to work. With this setup, "project1"
requires that "library1" be built and installed and available before its
build.

One idea I had is that a package configuration setup for library1 that would
build and install everything to the project binary directory, from where
project1's targets could pick it up? But I could not get this to work 
with the
ProjectConfiguration recipe.





-- 



--------------------------------------
Jeet Sukumaran
--------------------------------------
jeet.sukumaran at duke.edu
--------------------------------------
Department of Biology
Duke University
Box 90338
Durham, NC 27708
--------------------------------------
Blog/Personal Pages:
    http://jeetworks.org/
Photograph Galleries:
    http://jeet.smugmug.com/
GitHub Repositories:
    http://github.com/jeetsukumaran
--------------------------------------



More information about the CMake mailing list