Unknown CMake command “ExternalProject_Add”

2019-02-21 15:20发布

I have following 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 json-c library to my project, but when I run cmake I'm getting error: Unknown CMake command "ExternalProject_Add". My CMake version is 3.6.2 on OS X

2条回答
Rolldiameter
2楼-- · 2019-02-21 15:55

While it is not directly written in documentation pages, 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>)
查看更多
迷人小祖宗
3楼-- · 2019-02-21 16:05

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

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

before the call of externalproject_add(YOUR STUFF HERE)

Explanation:

CMAKE_ROOT points to the cmake installation in use. All modules are within subfolder Modules.

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

查看更多
登录 后发表回答