[CMake] Make install in subdirs (cmake newbie)
Michael Wild
themiwi at gmail.com
Wed Mar 16 05:14:37 EDT 2011
On 03/16/2011 09:37 AM, Jörg Schlichter wrote:
> Hi!
>
> I started to use cmake (and I like it), but I am now confronted with a
> problem I cannot to solve:
>
> We have a layout of our software tree looking more or less like this:
>
> |
> |--public_headers
> |--lib
> |
> |--src
> |--project1
> |--project2
> |--...
>
> project1, project2 etc. are some shared libraries (using Qt). During the
> build process, these libraries should be installed to "lib", the headers
> to "public_headers". The "public_headers" directory is searched by the
> other projects during compilation for headers they need.
> We did this so far with qmake, and it worked quiet well. (By the way,
> changing this directory layout is not an option).
>
> I tried to do this now with cmake, so I created a CMakeLists.txt in
> directory src, which looks about like this:
>
> ...
> SUBDIRS( project1, project2, ...)
Don't use that command, it's deprecated. Use add_subdirectory() instead.
>
> In the project directories I have "real" CMakeLists.txt files describing
> all the stuff needed for compilation and installation of a project.
> If I do there a "cmake; make all install" all is compiled and installed
> as it should be.
>
> The problem is, it does not work if I do "cmake; make all install" in
> the directory src. In this case "make all" is executed for all projects,
> and afterwards "make install" is executed for all projects. However, if
> project2 expects a header of project1 to be installed in
> "public_headers", compilation of project2 will fail, because the
> installation step of project1 was not yet executed.
>
> Is there anything I can do to solve this problem?
>
> Thanks
> Joerg
Sounds like a case for "super-build". The idea is the following: in
src/CMakeLists.txt you do a series of checks for required third-party
software, user-options etc. and, most importantly, include the
ExternalProject module. And then for each of the projectX directories,
you make a call to ExternalProject_Add(), passing it the detected
parameters and user-options and specifying the interdependencies. This
way, every project gets built as a separate CMake project, in an order
that satisfies the dependencies.
HTH
Michael
More information about the CMake
mailing list