[CMake] Help on ExternalProject_Add

Jean-Christophe Fillion-Robin jchris.fillionr at kitware.com
Thu Feb 10 02:39:10 EST 2011


Hi Luigi,

You will find some comments below ...

Jc

On Wed, Feb 9, 2011 at 9:07 AM, Luigi Calori <l.calori at cineca.it> wrote:

> Hi everybody,
> I' m trying to use ExternalProject to wrap serveral building recipies for
> different packages I have to use:
> I am taking the habit of using it as a replacement of shell scripts or
> manual session for building from source.
> In my usage I found some problems, possibly due to my ignorance, so please
> forgive me:
>
> 1) I would like to build the same package from the same source multiple
> times (for example because I need to change some config (shared/non shared)
>    or build (debug /release) ... I would like to keep a common source dir
> across the different builds...
>    So I tried to specify a source dir outside binary dir, but the  the
> download and patch steps seem repeated even if the source is already present
>    (the download step can be   saved)
>    Is this behavior intended or am I missing something?
>    I have tried to split the projects in two: one that download and patch
> the source and another that build it, but
>    unfortunately the build only project complain that is source dir is
> empty at meta-project configure time.
>

Have a look at the CMakeLists.txt enclosed. It basically checkout a project
using a first external project and then configure+built in second external
project depending on the first one.



>   The problem seems that the stamp files that decide weather a step has to
> be executed, are collected on the same STAMP_DIR:
>   For a previous version of the module, I patched it by adding a
> SOURCE_STAMP_DIR that differentiate the folder where the stamps files are
> kept,
>   between  download and patch step, and the other stepsI.
>   could that be generally useful? In case I could try to dive in and file a
> feature request + patch
>

> 2) Regarding VCS, I see that CVS, SVN and GIT are now supported, I' ve to
> use also Bazaar and Mercurial,
>    is it possible to use DOWNLOAD_COMMAND for addressing those, are there
> any examples?
>    otherwise would it be useful to add new BZR_REPOSITORY and HG_REPOSITORY
> commands?
>

You will have to use both the DOWNLOAD and the UPDATE command.

I am not familiar with bazaar or mercurial .. but if the "initial checkout
or clone" and the following "update or pull" associated with these
repository can be achieved using a single command line. It should be pretty
straightforward.

Otherwise, you  could either:

  - create a cmake files that could be invoked as download and update
command  (${CMAKE_COMMAND} -P /path/to/your/bazaar-download-script.cmake,
${CMAKE_COMMAND} -P /path/to/your/bazaar-update-script.cmake)

  - patch ExternalProject and submit a patch



>
> 3) In case of Cmake based projects,  there seem no way to inherit
>  variables or settings from the "meta" project into the ExternalProject
> apart from explicitly listing
>    definition variables as CMAKE_ARGS -Dvar1:var1type=${var1}
> -Dvar2:var2type=${var2} .
>    Is that tue or there is some other way to do it? ...


Option and cmake variables defined in the "meta" project could be used to
configure any external project. As of today, there is no way of
automatically guessing with which External project these options and
variables should be assigned to.
That means the options should be explicitly associated with an external
project  (using CMAKE_ARGS).


> and in case, is the   vartype needed?
>

Under the hood, cmake is invoked, if no vartype is specified, it default to
"UNINITIALIZED". See
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#property:TYPE

If you omit to specify the type, the variable won't show in both ccmake and
cmake-gui.




>
> Sorry for the length and thanks a lot in advance
>
> Luigi
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>



-- 
Direct: 1-518-836-2174
Ext: 304
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110210/5fd31643/attachment.htm>
-------------- next part --------------

#
# BuildHelper script
# Author: Jean-Christophe Fillion-Robin <jchris.fillionr at kitware.com>
#


CMAKE_MINIMUM_REQUIRED(VERSION 2.8.2)

PROJECT(BuildHelper)

INCLUDE(ExternalProject)

set(ep_base        "${CMAKE_BINARY_DIR}")
set(ep_suffix      "-cmake")

# Compute -G arg for configuring external projects with the same CMake generator:
IF(CMAKE_EXTRA_GENERATOR)
  SET(gen "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
ELSE()
  SET(gen "${CMAKE_GENERATOR}")
ENDIF()


set(proj DummyCpp)

ExternalProject_Add(${proj}-GetSource
  SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
  PREFIX ${proj}${ep_suffix}
  GIT_REPOSITORY "git://github.com/jcfr/DummyCpp.git"
  GIT_TAG "origin/master"
  CONFIGURE_COMMAND ""
  BUILD_COMMAND ""
  INSTALL_COMMAND ""
  )

SET(DummyCpp_CMAKE_BUILD_TYPE Release CACHE STRING "Build type")

ExternalProject_Add(${proj}-Build-${DummyCpp_CMAKE_BUILD_TYPE}
  SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
  BINARY_DIR ${proj}-${DummyCpp_CMAKE_BUILD_TYPE}
  PREFIX ${proj}${ep_suffix}
  DOWNLOAD_COMMAND ""
  CMAKE_GENERATOR ${gen}
  INSTALL_COMMAND ""
  CMAKE_ARGS
    -DCMAKE_BUILD_TYPE:STRING=${DummyCpp_CMAKE_BUILD_TYPE}
  DEPENDS
    "${proj}-GetSource"
  )


More information about the CMake mailing list