【发布时间】:2017-02-25 22:16:15
【问题描述】:
考虑以下 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)
但不幸的是,它根本不起作用。我能做些什么来解决这个错误?
附:我的cmake版本是3.5.2,操作系统:ubuntu 16.10。
【问题讨论】: