我正在写使用Python模块pybind11与CMake3.9.4。因为它是方便,我想下载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".
Run Code Online (Sandbox Code Playgroud)
有一个解决方法:
cmake .make(然后,它下载pybind11源文件)cmake .make但是,这并不聪明......有没有办法下载pybind11使用ExternalProject_Add而不注释掉这些行并恢复它们(并且没有运行cmake和make两次)?
/Users/me/foo/CMakeLists.txt
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
Run Code Online (Sandbox Code Playgroud)
/Users/me/foo/foo.hpp
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".
Run Code Online (Sandbox Code Playgroud)
/Users/me/foo/foo.cpp
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
Run Code Online (Sandbox Code Playgroud)
Cha*_*esB 10
使用 CMake 的FetchContent模块(版本 3.11+),您可以执行以下操作:
include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG v2.2.3
)
FetchContent_GetProperties(pybind11)
if(NOT pybind11_POPULATED)
FetchContent_Populate(pybind11)
add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
endif()
Run Code Online (Sandbox Code Playgroud)
这将在配置时下载 pybind11 和add_subdirectory它。然后你就可以打电话了pybind11_add_module。
| 归档时间: |
|
| 查看次数: |
3212 次 |
| 最近记录: |