[CMake] make a project also a subproject

Leif Walsh leif.walsh at gmail.com
Fri Jun 22 12:10:02 EDT 2012


Suppose I have two projects, A and B.  A builds a shared lib that links with a static lib in B.

Sometimes, I want to build and test B by itself.  Other times I want to build A, which requires building B.

For now, I manually (or with a script) build B, then set an environment variable to say where the built static lib is, and then build A (which uses the environment variable).  This is...not superb.

If I wrote A's CMakeLists.txt to have add_subdirectory(B), it would error when it hit B's project(B).  It probably would work (with some tweaking) if I removed project(B), but then I couldn't build B by itself.

Is there a "right way" to do this?  Is there a good, reliable way to detect that project(A) has already been called, and then (if that's the case) skip project(B)?  Will that work?

-- 
Cheers,
Leif



More information about the CMake mailing list