更改通过 pybind11_add_module 创建的库的输出目录
Changing output directory of library created through pybind11_add_module
我正在使用 CMake 使用 Pybind11 为我的代码构建一些 python 绑定。它运行良好,但它们在主 build
目录中编译。我希望它们建立在 build\python
目录中。我正在尝试以下操作:
pybind11_add_module(myModule src/main.cpp)
set_target_properties(myModule PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python")
但它没有按预期工作,myModule
仍然建立在 build
目录上,就好像 set_target_properties
没有被调用一样。
在官方pybind11_add_module
文档中是这样写的:
This function behaves very much like CMake’s builtin add_library (in fact, it’s a wrapper function around that command). It will add a library target called to be built from the listed source files. In addition, it will take care of all the Python-specific compiler and linker flags as well as the OS- and Python-version-specific file extension. The produced target can be further manipulated with regular CMake commands.
所以我假设 set_target_properties
可以用来表示它后面的不同输出目录,不是这样吗?如果不行,怎么办?
提前致谢!
pybind11
模块是 SHARED 或 MODULE 类型的库。
SHARED 库的构建目录是通过 LIBRARY_OUTPUT_DIRECTORY
在除 Windows(及其 dll
之外)的所有平台上指定的。
MODULE 库的构建目录在所有平台上都是通过 LIBRARY_OUTPUT_DIRECTORY
指定的。
中可以找到 CMake 中输出工件类型和相应 OUTPUT
变量的详细描述
我正在使用 CMake 使用 Pybind11 为我的代码构建一些 python 绑定。它运行良好,但它们在主 build
目录中编译。我希望它们建立在 build\python
目录中。我正在尝试以下操作:
pybind11_add_module(myModule src/main.cpp)
set_target_properties(myModule PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python")
但它没有按预期工作,myModule
仍然建立在 build
目录上,就好像 set_target_properties
没有被调用一样。
在官方pybind11_add_module
文档中是这样写的:
This function behaves very much like CMake’s builtin add_library (in fact, it’s a wrapper function around that command). It will add a library target called to be built from the listed source files. In addition, it will take care of all the Python-specific compiler and linker flags as well as the OS- and Python-version-specific file extension. The produced target can be further manipulated with regular CMake commands.
所以我假设 set_target_properties
可以用来表示它后面的不同输出目录,不是这样吗?如果不行,怎么办?
提前致谢!
pybind11
模块是 SHARED 或 MODULE 类型的库。
SHARED 库的构建目录是通过 LIBRARY_OUTPUT_DIRECTORY
在除 Windows(及其 dll
之外)的所有平台上指定的。
MODULE 库的构建目录在所有平台上都是通过 LIBRARY_OUTPUT_DIRECTORY
指定的。
OUTPUT
变量的详细描述