[CMake] Build only what you need in third party libs

David Cole david.cole at kitware.com
Fri Jan 29 14:25:27 EST 2010


On Thu, Jan 28, 2010 at 5:23 PM, Brian Davis <bitminer at gmail.com> wrote:

>
> Update: currently crying uncle ... and switching to ExternalProject_Add.
> CMake and the third party libs were simply not designed for this.
>
> Question on ExternalProject_Add above:
>
>
> ExternalProject_Add(
>   DOWNLOAD_COMMAND ""
>   CMAKE_ARGS
>     -DMYPROJ_UBERBUILD:BOOL=OFF
>   SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
>   ...
> )
>
> I had in my project:
>
> SET( THIRD_PARTY_SRC_DIR  3rdParty/Win )
>
> add_subdirectory( ${THIRD_PARTY_SRC_DIR}/vtk-5.4.2 ./vtk-5.4.2  )
>
> and so I replaced it with:
>
> ExternalProject_Add(
>     vtk-5.4.2
>     DOWNLOAD_COMMAND ""
>     SOURCE_DIR ${THIRD_PARTY_SRC_DIR}/vtk-5.4.2
> #    SOURCE_DIR
> C:\projects\NIH2009\source\branches\trunk\source\cpp\lib\3rdParty\Win\vtk-5.4.2
>     SOURCE_DIR /source/cpp/lib/3rdParty/Win/vtk-5.4.2
>
> )
>
> Where these lines are in a CMakeLists.txt file located at:
>
> C:\projects\NIH2009\source\branches\trunk\source\cpp\lib\CMakeLists.txt
>
> but I get the error in Visual Studio:
>
> 2>CMake Error: The source directory
> "C:/projects/NIH2009/source/branches/trunk/build/dvip4-Win64/cpp_source/lib/3rdParty/Win/vtk-5.4.2"
> does not appear to contain CMakeLists.txt.
>
> Note the prefixing of
> C:/projects/NIH2009/source/branches/trunk/build/dvip4-Win64/cpp_source/lib
>
> vtk is located at
> C:\projects\NIH2009\source\branches\trunk\source\cpp\lib\3rdParty\Win\vtk-5.4.2
>
> and project root CMakeLists.txt is at
> C:\projects\NIH2009\source\branches\trunk
>
>
>
> ExternalProject_Add(
>     vtk-5.4.2
>     DOWNLOAD_COMMAND ""
>     SOURCE_DIR /source/cpp/lib/3rdParty/Win/vtk-5.4.2
>
> )
>
> and get:
>
> 2>CMake Error: The source directory
> "/source/cpp/lib/3rdParty/Win/vtk-5.4.2" does not appear to contain
> CMakeLists.txt.
>
> so I try:
>
> SOURCE_DIR /3rdParty/Win/vtk-5.4.2
>
> 2>CMake Error: The source directory "/3rdParty/Win/vtk-5.4.2" does not
> appear to contain CMakeLists.txt.
>
>
> so I try absolute path:
>
>
> ExternalProject_Add(
>     vtk-5.4.2
>     DOWNLOAD_COMMAND ""
>     SOURCE_DIR
> C:\projects\NIH2009\source\branches\trunk\source\cpp\lib\3rdParty\Win\vtk-5.4.2
> }
>
> Ahhh the hacking... I am going to find my way out of this forest one day...
> and onto a desert.
>
> And now CMake finds the vtk goop.   Now the question: Is there a project
> relative directory syntax to use here or is ExternalProject not like
> add_subdirectory in this regard?
>
>
Relative path use is probably not well-defined for ExternalProject_Add.

If, as you say:
  "vtk is located at
C:\projects\NIH2009\source\branches\trunk\source\cpp\lib\3rdParty\Win\vtk-5.4.2
and
project root CMakeLists.txt is at C:\projects\NIH2009\source\branches\trunk"


Then I would construct a call to ExternalProject_Add in the project root
CMakeLists like this:
  ExternalProject_Add(
    vtk-5.4.2
    DOWNLOAD_COMMAND ""
    SOURCE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/source/cpp/lib/3rdParty/Win/vtk-5.4.2
  )

All _DIR type arguments in CMake should be specified as full absolute paths
unless there is documentation that tells you it's ok to use a relative path
name and what directory such values should be relative to...

For ExternalProject_Add, it's best to use full path names with "/"
separators for all _DIR parameters.


HTH,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100129/e383ca5e/attachment.htm>


More information about the CMake mailing list