如何将源文件添加到CMake中的外部项目? [英] How to add source files to an external project in CMake?

查看:878
本文介绍了如何将源文件添加到CMake中的外部项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 ExternalProject_Add 将SQLite整合到我的项目中。

I want to integrate SQLite into my project using ExternalProject_Add.

cmake_minimum_required(VERSION 2.8.8)
include(ExternalProject)

# Download, configure, build and install SQLite
ExternalProject_Add(SQLite
    PREFIX            ${CMAKE_SOURCE_DIR}
    TMP_DIR           ${CMAKE_SOURCE_DIR}/temp
    STAMP_DIR         ${CMAKE_SOURCE_DIR}/stamp
    #--Download step--------------
    DOWNLOAD_DIR      ${CMAKE_SOURCE_DIR}/download
    URL               http://www.sqlite.org/2014/sqlite-autoconf-3080704.tar.gz
    URL_HASH          SHA1=70ca0b8884a6b145b7f777724670566e2b4f3cde
    #--Update/Patch step----------
    UPDATE_COMMAND    ""
    #--Configure step-------------
    SOURCE_DIR        ${CMAKE_SOURCE_DIR}/source
    CONFIGURE_COMMAND "" # How to add sqlite3.c to the target here?
    #--Build step-----------------
    BINARY_DIR        ${CMAKE_SOURCE_DIR}/build
    BUILD_COMMAND     "cmake --build ."
    #--Install step---------------
    INSTALL_DIR       ${CMAKE_SOURCE_DIR}/install
)

构建命令将使用本地编译器构建添加到目标 SQLite 。但是,有没有。如何在 CONFIGURE_COMMAND 中的外部项目中添加唯一的源文件 sqlite3.c

The build command would use the native compiler to build all source files added to the target SQLite. However, there are non. How can I add the only source file sqlite3.c to the external project within the CONFIGURE_COMMAND?

推荐答案

ExternalProject_Add 假设您要拉入的项目已经运行(可能复杂,可能是非基于CMake的)工作构建系统。

ExternalProject_Add assumes that the project you want to pull in already ships with a (possibly complex, possibly non-CMake-based) working build system.

您有两种可能性:


  • 您可以坚持使用您正在使用的sqlite的合并autoconf版本。在这种情况下, CONFIGURE_COMMAND 将调用 configure BUILD_COMMAND 将调用 make 。请注意,这种方法将不会移植到没有安装autoconf的平台上。

  • 您可以切换到裸光源合并的sqlite版本,并提供您自己的建立CMakeLists.txt 。由于sqlite可以使用最少的配置进行构建,并且合并只包含单个源和头文件,这并不像听起来那么难。在这种情况下,您可以简单地调用 cmake 进行配置和构建。

  • You can stick with the amalgamated autoconf version of sqlite that you are currently using. In that case the CONFIGURE_COMMAND would invoke configure and the BUILD_COMMAND would invoke make. Note that this approach will not be portable to platforms that do not have autoconf installed.
  • You can switch to the bare-source amalgamated version of sqlite and provide your own CMakeLists.txt for building. Since sqlite can be built with a minimum of configuration and the amalgamation only consists of a single source and header file, this is not as hard as it may sound. In this case you can simply invoke cmake for configuation and building.

注意但是,您不能将此信息与 ExternalProject_Add 一起提供。您将需要一个外部构建脚本,无论是CMake,autoconf还是其他内容。

Note however that you cannot provide this information in-line with ExternalProject_Add. You will need an external build script, whether that is CMake, autoconf or something else.

这篇关于如何将源文件添加到CMake中的外部项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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