cmakeconfigureautogen

ExternalProject_Add autogen project prevent configure on rebuild


I have a CMake project on linux and I'm using ExternalProject to build Google Protobuf. It works great, however any subsequent builds still call the configure step in the external project (which is annoying because protobuf is an autogen project with a rather long step). I used the UPDATE_DISCONNECTED argument so it wouldn't re-clone which helps some, but you'd think if it didn't re-clone, it wouldn't need to re-configure or re-build/install. How can I get CMake to just build it the one time and skip subsequent builds (i.e. my next make from the build directory)?

Here's my CMakeLists.txt

cmake_minimum_required(VERSION 2.8.11)
project(pbuf_test)

include(${PROJECT_SOURCE_DIR}/cmake/protogen.cmake)

set(PBUF_DIR ${PROJECT_BINARY_DIR}/protobuf)

include(ExternalProject)
ExternalProject_Add(protobuf
    PREFIX ${PROTOBUF_DIR}
    GIT_REPOSITORY https://github.com/google/protobuf.git
    GIT_TAG v3.4.1
    UPDATE_DISCONNECTED 1
    BUILD_IN_SOURCE 1
    CONFIGURE_COMMAND ./autogen.sh COMMAND ./configure --prefix=${PBUF_DIR}
)

set(PBUF_INCLUDE_DIR ${PBUF_DIR}/include)
set(PBUF_LIBRARY ${PBUF_DIR}/lib/libprotobuf.so)
set(PBUF_PROTOC ${PBUF_DIR}/bin/protoc)

file(GLOB PBUF_FILES "${PROJECT_SOURCE_DIR}/msg/*.proto")
custom_protobuf_generate_cpp(PBUF_SRCS PBUF_HDRS ${PBUF_FILES})

include_directories(
    ${PROJECT_BINARY_DIR}
    ${PBUF_INCLUDE_DIR}
)

add_executable(${PROJECT_NAME} main.cpp ${PBUF_SRCS} ${PBUF_HDRS})
add_dependencies(${PROJECT_NAME} protobuf)
target_link_libraries(${PROJECT_NAME}
    ${PBUF_LIBRARY}
)   

Full example project here


Solution

  • The only way I know is to move the steps to build the external project into a script called by add_command. And then add an dependency between your project and the external project's output/lib/binary.

    BTW: Within my project, we do it the hard way. But we do not want any unexpected updates of external libs.