在主项目配置期间如何配置ExternalProject? [英] How to configure ExternalProject during main project configuration?

查看:176
本文介绍了在主项目配置期间如何配置ExternalProject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CMake的 ExternalProject 允许定义如何进行外部项目将被下载,配置,构建和安装.所有其步骤都将在构建时执行.

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 the build time.

我想在配置主项目期间执行外部项目的配置步骤.完成外部项目配置后,可以使用导入目标的描述,以便可以使用find_package()函数加载外部项目.

I would like to perform the configuration step of an external project during configuration of the main project. When the external project configuration is done the description of imported targets are available so the external project can be loaded with find_package() function.

是否可以在配置时建立一些目标?

Is it possible to build some targets at configuration time?

推荐答案

ExternalProject 只是要执行的一系列步骤.因此,您可以使用它的两个实例:

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

  1. ExternalProject_Add()调用将在主项目的配置阶段构建.例如,如该问题中所述:
  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(<project_name> <options...>
    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()调用将在主项目的 build阶段中构建.
  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(<project_name> <options...>
    CONFIGURE_COMMAND "" # Disable configure step. But other steps will be generated.
)

通过对两个ExternalProject_Add()调用使用相同的< options> ,我们实现了所创建的两个外部项目的抢占":构建并遵循第二个项目的步骤将使用第一个.

By using same <options> 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.

这篇关于在主项目配置期间如何配置ExternalProject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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