【发布时间】:2020-04-08 07:30:51
【问题描述】:
我使用 Cython 来包装 C 库并扩展其功能。 C 库由单独的团队开发,并随 CMakeLists.txt 提供。现在我使用源 .c 和 .h 文件来构建这个库。这就是我的build.py 诗歌文件(setup.py 模拟)的样子:
...
# source_files_paths - list of full paths to .c files
c_library = ('c_library', {'sources': source_files_paths})
...
def build(setup_kwargs):
setup_kwargs.update({
...,
'libraries': [c_library], # Here c library is built with build_clib command
...
})
是否可以在build函数(或setuptools.setup函数)中使用CMakeLists.txt构建c_library?
UPD:我也可以定义 .c 文件中使用的变量。我尝试添加define_macros:
c_library = ('c_library', {'sources': source_files_paths,
'define_macros': [('MY_MACRO': True)]})
仍然没有运气。
UPD2:我终于找到了解决问题的方法,尽管这不是我最初问题的答案。要添加宏,您应该以这种方式添加它:
c_library = ('c_library', {'sources': source_files_paths,
'macros': [('MY_MACRO': True)]})
根据http://svn.python.org/projects/python/branches/pep-0384/Lib/distutils/command/build_clib.py 中的build_libraries 函数,您还可以指定“include_dirs”、“obj_deps”和“cflags”参数。
【问题讨论】:
-
在工作中,我编写了一些脚本来使用 python 构建我的 cmake 项目。我能够使用 python 中的 subprocess 模块来做到这一点。这让我可以轻松地从 python 构建我的 cmake 项目。这是你想要的吗?
标签: python c cmake cython setup.py