我遇到了 CMakesAdd_External_Project
功能的问题(比其他任何事情都更令人烦恼)。具体来说,我不明白键CONFIGURE_COMMAND
和。BUILD_COMMAND
INSTALL_COMMAND
在以下(工作)示例中,下载 Google 的测试库,问题末尾的两个文件将确保下载并构建第三方库(未安装)。
但是,当我尝试将配置和构建命令添加为“CONFIGURE_COMMAND”和“BUILD_COMMAND”(cmake .
和cmake --build
)时,不必执行execute_process
CMake 并显示错误消息:
[ 55%] Performing configure step for 'googletest'
/bin/sh: 1: cmake .: not found
我是否正在尝试做一些明显不在功能范围内的事情Add_External_Project
?
示例文件:
CMakeLists.txt
cmake_minimum_required (VERSION 3.0)
project (Test VERSION 0.1.0.0 LANGUAGES CXX)
# Download and unpack googletest at configure time
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.in" "${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt" @ONLY)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download" )
execute_process(COMMAND ${CMAKE_COMMAND} --build . WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download")
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src" "${CMAKE_BINARY_DIR}/googletest-build")
CMakeLists.txt.in
cmake_minimum_required(VERSION 3.0)
project(third-party NONE)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
SOURCE_DIR "@CMAKE_BINARY_DIR@/googletest-src"
BINARY_DIR "@CMAKE_BINARY_DIR@/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)