cmake:外部项目更新和离线工作 [英] cmake: external project update and a work offline

查看:62
本文介绍了cmake:外部项目更新和离线工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用外部项目使图书馆很长时间保持最新状态像这样:

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

 include(AddAsio)

和脚本AddAsio.cmake像这样:

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.

此脚本会在每次构建时尝试更新(git pull,查看外部项目定义),即使所有必需的标头确实存在于此.并在没有连接的情况下中断了构建过程.

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?

推荐答案

AFAIK,没有简单的方法通过检查某些文件是否存在来使外部项目不更新.但是,您可以将 UPDATE_DISCONNECTED 设置为外部项目,或者设置目录的 EP_UPDATE_DISCONNECTED 属性以禁用外部项目的更新.连同构建选项,该过程可以动态进行.例如,通过使用命令 cmake -DBUILD_OFFLINE = ON

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
)

这篇关于cmake:外部项目更新和离线工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆