[CMake] Gyp VS CMake

Rolf Eike Beer eike at sf-mail.de
Fri Feb 18 01:36:58 EST 2011


> Why did we skip point number 4. This was the biggest part of the CMake
> build system I made for my team. And I believe I borrowed a bit from the
> boost CMake adaption, so perhaps they have the same problem.
>
> Instead of using a built in feature to accomplish this I have numerous
> macros and functions which define and accumulate the actual dependencies
> between libraries and executables. When I say a library depends on another
> library I need more than a build order and a link option added. I need the
> include directories too. Ever sense I started working with CMake I've been
> fighting with its "single top level view of the project." I finally got it
> so that I each library and executable knew about what it depended on and
> each could be built stand-alone. I just don't think a large project lends
> itself to the monolithic CMake approach.
>
> Don't get me wrong, I was able to use CMake to solve its own short coming,
> so I like it, but it's almost like I needed a CMake generator. I almost
> wrote a python or perl script that would generate the CMake files, because
> of all the scripting I was doing in CMake. I don't need another scripting
> language.

I don't know if I got your point right, but let's try. ;)

Our projects consist of tons of libraries and executables. There are very
few "top level" projects, i.e. those where the users usually point CMake
to and say "let's build that". But some of the subprojects are shared
between that top level project (i.e. they are used in both) and sometimes
a user simply wants to build only a subproject.

So our solution was to add a PROJECT(foo) into every subproject. Then we
have a fancy little macro called ADD_SUBDIRECTORY_ONCE which adds the
given subdirectory to your project if it is not already included (using a
global property). So most of the subprojects start with a bunch of
ADD_SUBDIRECTORY_ONCE calls pulling in all of their dependencies. Then I
do INCLUDE_DIRECTORIES(${foo_SOURCE_DIR}/include
${bar_SOURCE_DIR}/include) which will pull in the headers. Linking goes as
always.

This dates back before I even knew about exports and such so there might
be a much more elegant solution than this. But it works.

Eike


More information about the CMake mailing list