考虑以下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)
我希望首先下载外部项目文件,然后开始配置我的可执行目标。但事实并非如此。
当我在源目录内的构建目录中运行“cmake ..”时,它会产生:
(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首先尝试获取链接器语言,在这种情况下这是不可能的,因为我没有源文件。
我尝试添加,
set_target_properties(xyzbin PROPERTIES LINKER_LANGUAGE CXX)
但不幸的是,它根本不起作用。我该怎么做才能解决这个错误?
P.S。我的cmake版本是3.5.2,os:ubuntu 16.10。
答案 0 :(得分:0)
ExternalProject_Add
添加目标。在您执行make
之前,它不会执行任何操作。
要在配置之前下载存储库,您必须明确告诉CMake这样做。或者你可以创建一个setup.sh
脚本来下载依赖项,并且(可能)在之后运行cmake。