在主项目配置期间如何配置ExternalProject?

编程入门 行业动态 更新时间:2024-10-25 12:22:09
本文介绍了在主项目配置期间如何配置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:

  • ExternalProject_Add()调用将在主项目的配置阶段构建.例如,如该问题中所述:
  • 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 )

  • ExternalProject_Add()调用将在主项目的 build阶段中构建.
  • 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?

    本文发布于:2023-11-13 06:39:57,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1583725.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:主项   ExternalProject

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!