I have two projects, both of which use CMake. Now I want to include one of the projects as a library inside the other, while still maintaining the ability to compile them as standalone projects.
What I have done so far is: Use the version control system to clone a copy of the child project in a subdir of the parent project. I've used the "add_subdirectory" to include the CMakeLists.txt of the child project into the parent project. And I have fixed name collisions between targets by renaming some of the targets in the child project.
However, an issue that I am running into is that the various configuration tests in the child project don't seem to be running. For example, the child project uses the FindThreads module to determine what synchronization primitives are available. The parent project is unaware of threading issues and therefore does not have any tests related to this. Similarly, the child project has various tests for headers and such that are not needed by the parent project. None of these tests appear to be running, and the symbols defined by these tests aren't being added to the CMakeCache.txt file.
I really don't want to have to hoist all of the child project's tests (which mostly deal with platform-specific issues that are not relevant to the parent) into the parent project's CMakeLists.txt.
CMake 2.8 added a new External Project module, which lets you create a custom target to drive the build of another CMake project. The documentation on this is kind of weak, but it looks like it might do what you want.
I think the idea would be to call ExternalProject_Add from your parent project, pointing it to the source directory of the child project (you can even have it check the child project out of SVN or CVS for you, nice!).