Unknown CMake command "ExternalProject_Add"

I have a CMakeLists.txt file:

cmake_minimum_required (VERSION 3.2 FATAL_ERROR) project (utils VERSION 1.0.0 LANGUAGES CXX) ExternalProject_Add(json-c GIT_REPOSITORY "https://github.com/json-c/json-c.git" UPDATE_COMMAND git pull "https://github.com/json-c/json-c.git" CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/SDL_image/./configure --prefix=${SDL_INSTALL_DIR} SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/json-c INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR} ) 

I want to add the json-c library to my project, but when I run cmake, I get the error: Unknown CMake command "ExternalProject_Add". My version of CMake 3.6.2 on OS X

+7
cmake
source share
2 answers

The required module should be part of your cmake installation. But you should include it in your project with:

 include(${CMAKE_ROOT}/Modules/ExternalProject.cmake) 

before calling externalproject_add(YOUR STUFF HERE)

Explanation:

CMAKE_ROOT indicates the cmake installation used. All modules are located in subfolders Modules .

You can print the current value with the message (STATUS "CMAKE_ROOT = $ {CMAKE_ROOT}"). Or you use smart macros for this. See CMake

+10
source share

Until it is written directly on the documentation pages, the CMake functions described in the cmake-modules section require , including a special module .

How the function ExternalProject_Add is described on the documentation page

 include(ExternalProject) 

before using it.

The same strategy works for any other modules except Find<name> . These modules are used through

 find_package(<name>) 
+11
source share

All Articles