4

CMakeLists.txt:

cmake_minimum_required(VERSION 3.3)
project(CMakeTest)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(event-cmake REQUIRED)

file(GLOB SOURCES "*.cpp" )

add_executable(test ${SOURCES})

cmake/Findevent-cmake.cmake:

ExternalProject_Add(event-cmake
  GIT_REPOSITORY https://github.com/libevent/libevent.git
  UPDATE_COMMAND ""
  INSTALL_COMMAND ""
)

I know that the CMakeLists here has no chance to include the resolved package, but I cannot even get CMake to download the external repo. It errors out with:

CMake Error at cmake/Findevent-cmake.cmake:3 (ExternalProject_Add):
  Unknown CMake command "ExternalProject_Add".
Call Stack (most recent call first):
  CMakeLists.txt:4 (find_package)

Is there a way to make it so that cmake will download the project and link to it?

chacham15
  • 13,719
  • 26
  • 104
  • 207
  • Did you try to remove the `UPDATE_COMMAND` and `INSTALL_COMMAND` entries? – Alexis Wilke Jan 15 '17 at 04:06
  • Yeah, doesnt help :( same error – chacham15 Jan 15 '17 at 04:26
  • Oh, actually it says that the command itself is not known. Maybe you have a `cmake` tool that's too old, like [version 2.x](http://www.kitware.com/media/html/BuildingExternalProjectsWithCMake2.8.html) instead of 3.x? – Alexis Wilke Jan 15 '17 at 07:21
  • When tried to move error message into the title, I have found that the question described the same problem already exist: http://stackoverflow.com/questions/41618522/unknown-cmake-command-externalproject-add. – Tsyvarev Jan 16 '17 at 07:08

1 Answers1

3

While it is not directly written in docs, CMake functions described under cmake-modules section requires including specific module.

As function ExternalProject_Add is described in the documentation page titled as "ExternalProject", you need to use

include(ExternalProject)

before using it.


Same strategy is works for any other modules except Find<name> ones. Those modules are used via

find_package(<name>)
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153