如何构建cmake ExternalProject,同时配置主要? [英] How to build cmake ExternalProject while configurating main one?

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

问题描述

当他们的安装目标被打乱时,可能很难引用ExternalProjects。因此,可能希望在为给定项目生成主项目文件之前构建和安装ExternalProjects一次。

It can be a pain to refrence ExternalProjects when their install targets are messed up. So one may want to build and install ExternalProjects once before generating main project files for given project. Is it possible with CMake and how to do it?

推荐答案

您可以使用 cmake 调用 execute_process 用于配置和构建CMake项目,其中包含ExternalProject:

You may use cmake call within execute_process for configure and build CMake project, which contains ExternalProject:

other_project / CMakeLists.txt

project(other_project)
include(ExternalProject)

ExternalProject_Add(<project_name> <options...>)

.txt

execute_process(
    COMMAND ${CMAKE_COMMAND} --build . ${CMAKE_SOURCE_DIR}/other_project
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/other_project
)

$ {CMAKE_BINARY_DIR} / other_project 中配置并构建 other_project (因为 - build code>。如果您在 ExternalProject_Add 电话中未停用安装,那么在构建other_project 时会执行此操作。

Such a way other_project will be configured and built (because of --build option) in directory ${CMAKE_BINARY_DIR}/other_project. If you do not disable installation in ExternalProject_Add call, then it will performed when building other_project.

通常,您需要ExternalProject的一些选项,例如 SOURCE_DIR BINARY_DIR INSTALL_DIR ,从主项目中的变量推导出来。 achive有两种方法:

Normally, you want some options to ExternalProject, like SOURCE_DIR, BINARY_DIR, INSTALL_DIR, to be deduced from variables in the main project. You have two ways for achive that:


  1. 创建 CMakeLists.txt other_project

  1. Create CMakeLists.txt for other_project with configure_file, called from main project (before execute_process command).

将主项目中的变量作为 -D 参数传递给 $ {CMAKE_COMMAND}

Pass variables from main project as -D parameters to ${CMAKE_COMMAND}.

这篇关于如何构建cmake ExternalProject,同时配置主要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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