[CMake] How to use VTK as an ExternalProject

Jean-Christophe Fillion-Robin jchris.fillionr at kitware.com
Mon Feb 7 23:03:58 EST 2011


Hi Nicolas,

To properly use the superbuild feature, you could structure your project as
described below:

<PROJ-SRC>/CMakeLists.txt
<PROJ-SRC>/Superbuild.cmake
<PROJ-SRC>/CMakeExternals/External-VTK.cmake

Within CMakeLists.txt, by default the variable USE_SUPERBUILD will be ON.
If this variable is ON, it means a file named, for example Superbuild.cmake
will have to be included.
Then, within superbuild.cmake, the "ExternalProject_add" command will have
to be invoked.

You will find below some hints regarding the content of these different
file:

*CMAKELISTS.TXT
PROJECT*( MYPROJECT )
...
*OPTION*( USE_SUPERBUILD "Use SuperBuild" ON )
...
*IF*( USE_SUPERBUILD )
  *INCLUDE*( "${CMAKE_CURRENT_SOURCE_DIR}/Superbuild.cmake" )
 * RETURN()*
*ENDIF*( USE_SUPERBUILD )
...
*FIND_PACKAGE*( VTK )??? //NOT WORKING
...
*

**Superbuild.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()

INCLUDE(CMakeExternals/External-VTK.cmake)

*ExternalProject_Add(GoFigure2*
   DOWNLOAD_COMMAND ""
   CMAKE_GENERATOR ${gen}
   CMAKE_ARGS
      -*DUSE_SUPERBUILD:BOOL=OFF*
       .....
  SOURCE_DIR ${GoFigure2_SOURCE_DIR}
  BINARY_DIR ${GoFigure2_BINARY_DIR}/GoFigure2-build
  DEPENDS
     VTK
  )

Looking at both
Slicer<http://viewvc.slicer.org/viewcvs.cgi/trunk/?root=Slicer4>and
CTK <https://github.com/commontk/CTK>, you will also be able to grab some
code ...

Nevertheless, note that CTK buildsystem is a little bit more complex since
it's able to include the external project dynamically depending on the
enabled libraries<http://www.commontk.org/index.php/Documentation/BuildSystem_Description>,
plugin ...


Thanks
Jc

On Mon, Feb 7, 2011 at 6:01 PM, Nicolas Rannou <
nicolas_rannou at hms.harvard.edu> wrote:

>  Hello,
>
> I would like to set up a "superbuild" for my project.
> I would like it to be as clean/basic as possible.
>
> Let's say I want to build VTK as my "ExternalProject". How should I proceed
> to link it to my current project.
>
> My current project requires VTK to be built.
> So FIND_PACKAGE cannot work. (vtk source code not there during the
> configuration step)
> And I didn't get any success manually setting VTK_DIR, VTK_INCLUDE_DIRS,
> etc. at the end of my External-VTK.cmake file. Is it the way to go?
>
> How should I proceed to do it?
> Is there any tutorial on the net? (I couldn't find any)
> I had a look at CTK's and Slicer's superbuilds but we would like something
> more basic and straight forward. Is it possible?
> Is there a special option in CMake/ExternalProjects to be enabled or
> anything we can do about it?
>
> A workaround was to build "myProject" as an ExternalProject linked to the
> "VTK ExternalProject", and to turn off USE_SUPERBUILD but I don't really
> like this solution.
>
> Any help would be greatly appreciated,
>
> Thanks
>
> *CMAKELISTS.TXT
> PROJECT*( MYPROJECT )
> ...
> *OPTION*( USE_SUPERBUILD "Use SuperBuild" ON )
> ...
> *IF*( USE_SUPERBUILD )
>   *INCLUDE*( "${GOFIGURE2_SOURCE_DIR}/CMake/SuperBuild/External-VTK.cmake"
> )
> *ENDIF*( USE_SUPERBUILD )
> ...
> *FIND_PACKAGE*( VTK )??? //NOT WORKING
> ...
> *
> External-VTK.cmake*
>
> set(proj VTK)
> ...
>   ExternalProject_Add(${proj}
>     SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
>     BINARY_DIR ${proj}-build
>     GIT_REPOSITORY "${git_protocol}://vtk.org/VTK.git"
>     GIT_TAG "origin/release"
>     CMAKE_GENERATOR ${gen}
>     CMAKE_ARGS
>       ${ep_common_args}
>       -DBUILD_EXAMPLES:BOOL=OFF
>       -DBUILD_SHARED_LIBS:BOOL=ON
>       -DCMAKE_CXX_FLAGS:STRING=${ep_common_cxx_flags}
>       -DCMAKE_C_FLAGS:STRING=${ep_common_c_flags}
>       -DVTK_USE_PARALLEL:BOOL=ON
>       -DVTK_DEBUG_LEAKS:BOOL=${USE_VTK_DEBUG_LEAKS}
>       -DVTK_USE_RPATH:BOOL=ON
>       -DVTK_INSTALL_LIB_DIR:PATH=${MyProject_INSTALL_LIB_DIR}
>       ${VTK_QT_ARGS}
>       ${VTK_MAC_ARGS}
>     INSTALL_COMMAND ""
>     DEPENDS
>       ${VTK_DEPENDENCIES}
>     )
> ...
> set(VTK_DIR ${CMAKE_BINARY_DIR}/${proj}-build)??? // NOT WORKING
>
> _______________________________________________
> 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/20110207/d381addf/attachment.htm>


More information about the CMake mailing list