0

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.

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

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

I tried adding,

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. my cmake version is 3.5.2, os: ubuntu 16.10.

jnbrq -Canberk Sönmez
  • 1,790
  • 1
  • 17
  • 29
  • Possible duplicate of [Howto include selected sources from third party project in CMake](http://stackoverflow.com/questions/29041008/howto-include-selected-sources-from-third-party-project-in-cmake) – Tsyvarev Feb 25 '17 at 22:39

1 Answers1

0

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

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.

Telokis
  • 3,399
  • 14
  • 36