amigo421 amigo421 - 1 month ago 7
Git Question

cmake: external project update and a work offline

I was using external projects to keep libraries up to date for a long time
something like:

include(AddAsio)


and script AddAsio.cmake like this:

cmake_minimum_required(VERSION 2.8.8)
include(ExternalProject)
find_package(Git REQUIRED)

ExternalProject_Add(
asio
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/include/ext
GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
GIT_TAG master
TIMEOUT 10
UPDATE_COMMAND ${GIT_EXECUTABLE} pull
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
)

ExternalProject_Get_Property(asio source_dir)
set(ASIO_INCLUDE_DIR ${source_dir}/asio/include CACHE INTERNAL "Path to include folder for Asio")
include_directories(${INCLUDE_DIRECTORIES} ${ASIO_INCLUDE_DIR})
message("asio source dir" ${ASIO_INCLUDE_DIR})


there was no issue for a long time, however yesterday I've faced with a problem when my internet provider was not working and I tried to work offline.

this script tries to update (git pull, look at external project definition) each time of build, even all required headers do exist there. and breaks build process in case of no connection.

any idea how to keep this mechanism of components update but do not stop a building in case of libraries already exist locally?

Answer

AFAIK, there is no easy way to make an external project not to update by examining if certain files exist. However, you could set UPDATE_DISCONNECTED to an external project or set EP_UPDATE_DISCONNECTED property of a directory to disable update of external projects. Along with a build option, the process could be made dynamically. For example, you could build the following project without updating foo and bar by configuring with the command cmake -DBUILD_OFFLINE=ON

cmake_minimum_required (VERSION 2.8.11)
project (myrootproject C)

add_library(hello SHARED hello.c)
option(BUILD_OFFLINE "Build offline" OFF)

if (${BUILD_OFFLINE})
    set_property(DIRECTORY ${myrootproject_SOURCE_DIR}
                 PROPERTY EP_UPDATE_DISCONNECTED 1)
endif()

include(ExternalProject)

ExternalProject_Add(foo
    SVN_REPOSITORY svn://foobar.org/
)

ExternalProject_Add(bar
    GIT_REPOSITORY https://github.com/blah/blah
)