Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用CMake在主项目之前强制构建外部项目(使用buildtools)_Cmake - Fatal编程技术网

使用CMake在主项目之前强制构建外部项目(使用buildtools)

使用CMake在主项目之前强制构建外部项目(使用buildtools),cmake,Cmake,我想在开始构建我的主项目之前构建gsl。我在rootCMakeLists.txt文件中添加了以下行 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/gs

我想在开始构建我的主项目之前构建gsl。我在root
CMakeLists.txt
文件中添加了以下行

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构建外部项目

使用add_library/add_executable定义主库/可执行文件后,使用
add_dependencies
命令()将gsl_local设置为项目的依赖项

请注意,“moosebin”是您使用
add\u library
add\u executable
创建的目标的名称,它不一定与您使用
project()定义的名称相同

add_dependencies(moosebin gsl_local)