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:
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 )
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?
发布评论