Unknown CMake command "ExternalProject_Add"

While it is not directly written in documentation pages for versions prior to v3.14, 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 works for any other modules except Find<name> ones. Those modules are used via

find_package(<name>)

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

include(ExternalProject)

before the call of externalproject_add(YOUR STUFF HERE). See Modules

There are two include variants:

include(<MODULE_NAME_WITHOUT_.cmake>)
include(<FULL_PATH_TO_MODULE_WITH_.cmake>)

Examples:

include(gcovr)
include(${PROJECT_DIR}/cmake/gcovr.cmake)

Modules are plain cmake files and have to be included like your own module files (In case you have them).

The variable CMAKE_MODULE_PATH is a list of all directories where cmake is loading modules from. You can print out the current value with:

message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") 

Or you are using smart macros for that. See CMake