[CMake] ExternalProject_Add - Automatic Incremental Rebuilds + Add Sources to IDE

Aaron Nowack aaronbnowack at gmail.com
Sun Sep 22 03:08:37 EDT 2013


I finally got this working, including the sources from both projects and
simultaneous building. It was simpler than I thought, and as similar to how
you originally suggested. I created a superbuild CMakeLists.txt which just
contains the add_subdirectory(libs) and add_subdirectory(apps). I reference
the include directories for the libs headers by setting cache variable in
the libs/CMakeLists.txt, which are then referenced in the
apps/CMakeLists.txt . Since it's all together the targets from libs can be
directly referenced when linking in apps.

I'm not finished, but this method is already slick and straight forward.
Our previous build system was based on plain makefiles with lots of edge
cases, hardlinking, and referencing msvc7.0 via msys commandline  flags (I
know...).

Thanks VERY much for cmake, our last build system was horrendous. I'm glad
Sandia sponsors this.


On Fri, Sep 20, 2013 at 12:45 PM, Aaron Nowack <aaronbnowack at gmail.com>wrote:

> You can structure the app CMakeLists such that it can reference the libs
>> as part of a big "build everything" tree like this, or as something that
>> has to be found with find_package, or as something you just point to with
>> CMake variables.
>
>
> Was the "parent" CMakeLists.txt an example of only how to combine the
> sources, or should it be reasonably possible to do step-building? For
> example, I attempted the following...
>
> I've setup a "parent" CMakeLists.txt for the apps and libs as you
> described with subdirectories for apps and libs. I build the libs first,
> and have it set a variable of where the library will be installed to, named
> apps_lib_path. apps_lib_path is set with PARENT_SCOPE so it is passed into
> the apps/ directory.
>
> Now, in the apps folder I must reference to the library that libs will
> build. This seems to create a chicken-egg issue as I am trying to reference
> a library that isn't yet created. I am using find_package(libs) which
> checks several possible locations for the library, the first being
> apps_lib_path for the library libApps. Since no libApps is present (hasn't
> been built yet, still in the cmake stage) it is set to NOTFOUND and cmake
> returns an error.
>
> The best approach I've seen for this sort of thing so far is being used in
>> the Open Cheimstry projects. They build and install everything as part of a
>> "super build" into a known installation prefix in the "super build" build
>> tree. Then, they use CMAKE_PREFIX_PATH and find_package to find
>> *previously* built/installed sub-projects in subsequent sub-projects.
>> Everything is built via ExternalProject there, but none of the individual
>> projects build anything with ExternalProject -- they find everything with
>> find_package. ( See their repos here: https://github.com/OpenChemistry-- the super build is in:
>> https://github.com/OpenChemistry/openchemistry )
>>
>
> This is a great example, so they install into a common place where each
> project can use find_project(other_project) and link correctly. They force
> incremental rebuilds by using ExternalProject_Add_Step.
>
> Thanks for the help,
> - Aaron
>
> On Wed, Sep 18, 2013 at 8:51 AM, David Cole <dlrdave at aol.com> wrote:
>
>> Ideally, for these rapid co-development phases I would like to
>>> a) Be able to rebuild a project using ExternalProject_Add
>>> whenever any source file changes.
>>>
>>
>> ExternalProject is not well suited for handling source level changes.
>>
>>
>>
>>  b) Provide the mechanism for an IDE project to include all
>>> the sources from another project specified by
>>> ExternalProject_Add.
>>>
>>
>> Because of my answer for "(a)", I still don't think it's a good idea.
>>
>>
>>
>>  For b) there was a bug open and closed here,
>>> http://www.cmake.org/Bug/view.**php?id=12322<http://www.cmake.org/Bug/view.php?id=12322>
>>>
>>> I understand David's point about making bad assumptions, but I would
>>> find it extremely useful if I was able to include the sources and
>>>
>> force a
>>
>>> rebuild as I'm describing.
>>>
>>
>> I understand, and many others would also find it useful, but I doubt it
>> can be done reliably. If somebody would like to prove me wrong, (on Windows
>> with all supported versions of Visual Studio, and on the Mac with all
>> versions of Xcode, and with Eclipse, and ...), I will gladly reverse my
>> opinion.
>>
>>
>>
>>  Does anyone have any ideas? We're currently doing a lot of
>>>
>> refactoring on
>>
>>> both repositories so removing as much development overhead will really
>>> help. When things get stable we will be using ExternalProject_Add on
>>> tagged revisions.
>>>
>>
>> The best solution for rapid co-development of multiple repositories is
>> NOT to use ExternalProject. ExternalProject, as recently discussed in
>> another mailing list thread here, is best suited for building static
>> snapshots of repositories that do not change frequently.
>>
>> Does everything build with CMake? Good. Then you can make something like
>> this work:
>>
>>    # CMakeLists.txt
>>    cmake_minimum_required(VERSION 2.8.11)
>>    project(GlueLibsAndApp)
>>    add_subdirectory(libs)
>>    add_subdirectory(app)
>>
>>     # Then, checkout the two separate repositories in "libs" and "app"
>> and boom: all your sources for everything are all in the generated IDE
>> project
>>
>> You can structure the app CMakeLists such that it can reference the libs
>> as part of a big "build everything" tree like this, or as something that
>> has to be found with find_package, or as something you just point to with
>> CMake variables.
>>
>> Then later on, you can create a super build that builds both libs and app
>> separately using ExternalProject, and have that app refer to the libs built
>> in that manner, rather than as targets in the same CMakeLists directory
>> structure.
>>
>>
>> The best approach I've seen for this sort of thing so far is being used
>> in the Open Cheimstry projects. They build and install everything as part
>> of a "super build" into a known installation prefix in the "super build"
>> build tree. Then, they use CMAKE_PREFIX_PATH and find_package to find
>> *previously* built/installed sub-projects in subsequent sub-projects.
>> Everything is built via ExternalProject there, but none of the individual
>> projects build anything with ExternalProject -- they find everything with
>> find_package. ( See their repos here: https://github.com/**OpenChemistry<https://github.com/OpenChemistry>-- the super build is in:
>> https://github.com/**OpenChemistry/openchemistry<https://github.com/OpenChemistry/openchemistry>)
>>
>>
>> HTH,
>> David
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130922/3446f6dc/attachment.htm>


More information about the CMake mailing list