[OE-core] dealing with CMake ExternalProject (was: Re: [PATCH] cmake: Export SSH_AUTH_SOCK for cmake at configure)

André Draszik git at andred.net
Mon May 28 12:21:25 UTC 2018


On Mon, 2018-05-28 at 11:55 +0300, Hannu Lounento wrote:
> On 25/05/18 18:34, Christopher Larson wrote:
> > We should probably investigate if it's possible to shift those into 
> > do_fetch eventually. Contacting upstream during do_configure is not
> > kosher.
> 
> The reason for fetching during configure is that the CMake build system 
> in the git repository in question (later referred to as the "parent 
> project") uses the ExternalProject keyword [1], which "creates a custom 
> target to drive download, update/patch, configure, build, install and 
> test steps of an external project" [1].
> 
> The external project that the aforementioned CMake build system uses is 
> gtest (later referred to as the "child project"), which is many times 
> built as part of a parent project. Usually git submodule is used to 
> clone child projects, which works nicely with Bitbake with the gitsm 
> fetcher. In this particular case the parent project uses the 
> ExternalProject keyword instead, which is one of the options suggested 
> in gtest's documentation [2]. While the parent project is not a public 
> open source project, it is not in our direct control either and hence we 
> cannot just change it to use git submodule instead.

You can simply instruct ExternalProject to refer to an existing (local)
directory, instead of a remote git repository.  Either by patching it in
your parent project's recipe, or trying to get upstream to integrate such a
change:

Something along the lines of this works fine for me here:

CMakeLists.txt:

find_path(GTEST_SRC_LOCATION
    NAMES googlemock/src/gmock-all.cc googletest/src/gtest-all.cc
    HINTS ENV GTEST_SRC_ROOT
    PATHS "/usr/src/googletest"
    NO_DEFAULT_PATH
    )
if (GTEST_SRC_LOCATION)
    set(GTEST_GIT_REPOSITORY "" CACHE INTERNAL "googletest git repository")
    set(GTEST_GIT_TAG        "" CACHE INTERNAL "googletest git tag")
else ()
    set(GTEST_GIT_REPOSITORY "https://github.com/google/googletest.git" CACHE INTERNAL "googletest git repository")
    set(GTEST_GIT_TAG        "release-1.8.0" CACHE INTERNAL "googletest git tag")
    set(GTEST_SRC_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" CACHE INTERNAL "googletest source location")
endif ()
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)


And CMakeLists.txt.in contains (amongst others):

include(ExternalProject)
ExternalProject_Add(googletest
  GIT_REPOSITORY    ${GTEST_GIT_REPOSITORY}
  GIT_TAG           ${GTEST_GIT_TAG}
  SOURCE_DIR        "${GTEST_SRC_LOCATION}"


This way, you can have an independent recipe that downloads gtest, and the
recipe of your parent project just needs to ensure to depend on the
downloaded gtest and set the GTEST_SRC_ROOT environment variable. There even
is a debian package for the gtest source code (hence the /usr/src/googletest
above), so not only yocto builds, but even local workstation builds outside
yocto would benefit from such a change.

No need for dramatic changes (such as switching to git submodules).


Cheers,
Andre'





More information about the Openembedded-core mailing list