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

编程入门 行业动态 更新时间:2024-10-25 06:31:01
本文介绍了使用CMake在主项目之前强制构建外部项目(使用buildtools)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在开始构建主项目之前先构建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定义主库/可执行文件后,请使用 add_dependencies 命令( link )。

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 或 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)

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

发布评论

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

>www.elefans.com

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