dependencies不适用于外部项目

dependencies不适用于外部项目

本文介绍了cmake:add_dependencies不适用于外部项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下CMakeLists.txt

Consider the following CMakeLists.txt

cmake_minimum_required(VERSION 3.0)
project(xyz)

include(ExternalProject)

set(EXTSRC ${CMAKE_SOURCE_DIR}/external)

ExternalProject_Add(q
    GIT_REPOSITORY
        "https://github.com/sftrabbit/CppSamples-Samples.git"
    SOURCE_DIR ${EXTSRC}
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND "")

add_executable(xyzbin
    ${EXTSRC}/1-common-tasks/ranges/range-iteration.cpp)

add_dependencies(xyzbin q)

我希望先下载外部项目文件,然后再开始配置我的可执行目标.但是,事实并非如此.

I would expect that the external project files was downloaded first and then my executable target starts to be configured. However, this is not the case.

当我在源目录内的构建目录中运行"cmake .."时,它会产生:

When I run "cmake .." in a build directory inside the source directory, it yields:

(usual configure stuff above ....)
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error at CMakeLists.txt:16 (add_executable):
  Cannot find source file:

    /home/janberq/Desktop/cmake_problem/external/1-common-tasks/ranges/range-iteration.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx


CMake Error: CMake can not determine linker language for target: xyzbin
CMake Error: Cannot determine link language for target "xyzbin".
-- Generating done
-- Build files have been written to: /home/janberq/Desktop/cmake_problem/build

cmake似乎首先尝试获取链接器语言,在这种情况下这是不可能的,因为我没有源文件.

It seems like, cmake first tries to acquire linker language, which isn't possible in that case as I don't have source files.

我尝试添加,

set_target_properties(xyzbin PROPERTIES LINKER_LANGUAGE CXX)

但是不幸的是,它根本没有用.我该如何解决该错误?

But it didn't work at all, unfortunately. What can I do to fix that error?

P.S.我的cmake版本是3.5.2,操作系统:ubuntu 16.10.

P.S. my cmake version is 3.5.2, os: ubuntu 16.10.

推荐答案

ExternalProject_Add 添加一个目标.除非您执行 make .

ExternalProject_Add adds a target. It won't do anything until you do a make.

要在配置之前下载存储库,必须明确告知CMake这样做.或者,您可以创建一个 setup.sh 脚本,以下载依赖项并(可能)在此之后立即运行cmake.

To download the repository before configuring, you have to explicitly tell CMake to do so. Or you could create a setup.sh script downloading dependencies and (possibly) running cmake right after.

这篇关于cmake:add_dependencies不适用于外部项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:05