我正在使用pybind11
和CMake
3.9.4编写python模块。
为方便起见,我希望在pybind11
中使用ExternalProject_Add
下载CMakeLists.txt
源文件。
当我运行cmake .
时,它不会下载pybind11
源文件,并会抛出错误。
CMake Error at CMakeLists.txt:21 (add_subdirectory):
The source directory
/Users/me/foo/pybind11_external-prefix/src/pybind11_external
does not contain a CMakeLists.txt file.
CMake Error at CMakeLists.txt:22 (pybind11_add_module):
Unknown CMake command "pybind11_add_module".
有一种解决方法:
cmake .
make
(然后,它会下载pybind11
源文件)cmake .
make
然而,这并不聪明......有没有办法使用pybind11
下载ExternalProject_Add
而不评论线路并恢复它们(并且没有运行cmake
和{{1两次)?
/Users/me/foo/CMakeLists.txt
make
/Users/me/foo/foo.hpp
cmake_minimum_required(VERSION 3.8)
project(foo)
set(CMAKE_CXX_STANDARD 14)
include(ExternalProject)
ExternalProject_Add(
pybind11_external
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.2.1
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
set(PYBIND11_CPP_STANDARD -std=c++14)
ExternalProject_Get_Property(pybind11_external source_dir)
include_directories(${source_dir}/include)
add_subdirectory(${source_dir}) # comment out, then restore this line
pybind11_add_module(foo SHARED foo.cpp) # comment out, then restore this line
add_dependencies(foo pybind11_external) # comment out, then restore this line
/Users/me/foo/foo.cpp
#ifndef FOO_LIBRARY_H
#define FOO_LIBRARY_H
#include<pybind11/pybind11.h>
int add(int i, int j);
#endif