[CMake] using find_library with a ExternalProject
Ian Monroe
ian at monroe.nu
Mon Oct 22 12:34:19 EDT 2012
On Mon, Oct 22, 2012 at 6:07 AM, Bill Hoffman <bill.hoffman at kitware.com> wrote:
> 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.
So what was the target use-case for ExternalProject? From the name it
sounds like it was meant exactly for making your non-external project
(aka your project) be able to pull in dependencies from external
projects.
To make the project itself an external project gives up a lot of
flexibility in cmake configuration. And would just plan mess up my
source tree. :)
Ian
More information about the CMake
mailing list