[CMake] using find_library with a ExternalProject

Bill Hoffman bill.hoffman at kitware.com
Mon Oct 22 09:07:32 EDT 2012


On 10/21/2012 10:20 PM, Ian Monroe wrote:
> So I had code like:
> include(ExternalProject)
> ExternalProject_Add(
>     mockcpp
>     DOWNLOAD_COMMAND hg clonessh://hg@bitbucket.org/godsme/mockcpp
>     CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${MOCKCPP_PREFIX}
>     UPDATE_COMMAND hg pull
> )
>
>   find_library(MOCKCPP_LIBRARY
>                   NAMES
>                   mockcpp
>                   PATHS
>                   ${MOCKCPP_PREFIX}/lib
>                   NO_DEFAULT_PATH)
>
> This worked just fine until I used it on a fresh build. Then cmake
> wouldn't finish since at cmake-time the library doesn't exist.

This is a limitation of External project, you can not mix external 
project with non-external project CMake code and have it work in a 
portable manner.  Since external project defers download, configure and 
build until build time, there is nothing for the find_library to find at 
configure time because the code is not even there in many cases.

The way to do it is to change the rest of the project into external 
projects:
ExternalProject_Add(mockcpp)
ExternalProject_Add(MyProject)

Inside MyProject, you call find_library because mockcpp will be 
downloaded, configured, and built by then.

-Bill



-- 
Bill Hoffman
Kitware, Inc.
28 Corporate Drive
Clifton Park, NY 12065
bill.hoffman at kitware.com
http://www.kitware.com
518 881-4905 (Direct)
518 371-3971 x105
Fax (518) 371-4573


More information about the CMake mailing list