How to configure ExternalProject during main project configuration?

后端 未结 4 656
粉色の甜心
粉色の甜心 2021-02-05 10:37

The CMake\'s ExternalProject allows to define how to an external project is going to be downloaded, configured, built and installed. All whose steps are going to be performed at

4条回答
  •  春和景丽
    2021-02-05 11:08

    ExternalProject is just a sequence of steps to perform. So you may use two instances of it:

    1. ExternalProject_Add() call to be built at main project's configuration stage. E.g., as described in that question:

    other_project/CMakeLists.txt:

    project(other_project)
    include(ExternalProject)
    
    ExternalProject_Add( 
        BUILD_COMMAND "" # Disable build step.
        INSTALL_COMMAND "" # Disable install step too.
    )
    

    CMakeLists.txt:

    # The first external project will be built at *configure stage*
    execute_process(
        COMMAND ${CMAKE_COMMAND} --build . ${CMAKE_SOURCE_DIR}/other_project
        WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/other_project
    )
    
    1. ExternalProject_Add() call to be built at main project's build stage.

    CMakeLists.txt:

    # The second external project will be built at *build stage*
    ExternalProject_Add( 
        CONFIGURE_COMMAND "" # Disable configure step. But other steps will be generated.
    )
    

    By using same for both ExternalProject_Add() calls we achieve "preemption" of both external projects created: build and follow steps of the second project will use result of configure step of the first one.

提交回复
热议问题