问题描述
我想在开始构建主项目之前先构建gsl。我在根 CMakeLists.txt
文件中添加了以下几行。
I want to build gsl before I start building my main project. I added following lines to root CMakeLists.txt
file.
cmake_minimum_required(VERSION 2.8)
project(moose)
include(CheckIncludeFiles)
include(ExternalProject)
# Use local gsl
ExternalProject_Add(gsl_local
URL ${CMAKE_CURRENT_SOURCE_DIR}/external/gsl/gsl-1.16.tar.gz
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/gsl
CONFIGURE_COMMAND ./../gsl_local/configure --prefix=${CMAKE_CURRENT_SOURCE_DIR}/gsl
BUILD_COMMAND make
INSTALL_COMMAND ""
)
麻烦的是首先不构建gsl,而是继续构建项目 moose
,该项目需要 gsl / gsl.h
。它失败是因为 gsl / gsl.h
不在正确的位置。如何在开始构建主项目之前强制CMake构建外部项目。
The trouble is that it does not build gsl first but goes on to build project moose
which requires gsl/gsl.h
. It fails because gsl/gsl.h
is not in proper place. How to force CMake to build external project before it starts building main project.
推荐答案
使用add_library / add_executable定义主库/可执行文件后,请使用<$将gsl_local设置为项目的依赖项c $ c> add_dependencies 命令()。
After you define your main library/executable with add_library/add_executable, set gsl_local as a dependency of your project using the add_dependencies
command (link).
add_dependencies(moosebin gsl_local)
请注意, moosebin是您使用 add_library
或<$ c $创建的目标的名称。 c> add_executable ,不一定与您使用 project()
定义的内容相同。
Note that "moosebin" here is the name of the target you create with add_library
or add_executable
, which is not necessarily the same as what you define with project()
.
这篇关于使用CMake在主项目之前强制构建外部项目(使用buildtools)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!