如何在cmake中更改SWIG生成的.py文件?

发布于 2024-10-14 17:04:06 字数 1066 浏览 4 评论 0原文

我们可以使用EXECUTABLE_OUTPUT_PATH${PROJECT_BINARY_DIR}/bin之类的东西。如何通过 SWIG 设置生成的 python 模块的输出路径。

例如,得到以下 CMakeLists.txt

FIND_PACKAGE(SWIG)
IF(SWIG_FOUND) 
FIND_PACKAGE(PythonLibs)
IF(PYTHONLIBS_FOUND)

INCLUDE(${SWIG_USE_FILE})

EXECUTE_PROCESS( COMMAND python -c "import sys;print"%s.%s"%sys.version_info[0:2]" OUTPUT_VARIABLE PYTHON_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)


INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

SET(CMAKE_SWIG_FLAGS "")

SET_SOURCE_FILES_PROPERTIES(partio.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(partio.i PROPERTIES SWIG_FLAGS "-includeall")
SWIG_ADD_MODULE(partio python partio.i)
SWIG_LINK_LIBRARIES(partio ${PYTHON_LIBRARIES} ${ZLIB_LIBRARY} partio)

SET(PYTHON_DEST "lib64/python${PYTHON_VERSION}/site-packages" )
INSTALL(TARGETS _partio DESTINATION ${PYTHON_DEST})
INSTALL(FILES ${CMAKE_BINARY_DIR}/${outdir}/src/py/partio.py  DESTINATION ${PYTHON_DEST})

ENDIF(PYTHONLIBS_FOUND)
ENDIF(SWIG_FOUND)

We can use EXECUTABLE_OUTPUT_PATH to something like ${PROJECT_BINARY_DIR}/bin. How to set the output path for a generated python module by SWIG.

ex, got the following CMakeLists.txt

FIND_PACKAGE(SWIG)
IF(SWIG_FOUND) 
FIND_PACKAGE(PythonLibs)
IF(PYTHONLIBS_FOUND)

INCLUDE(${SWIG_USE_FILE})

EXECUTE_PROCESS( COMMAND python -c "import sys;print"%s.%s"%sys.version_info[0:2]" OUTPUT_VARIABLE PYTHON_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)


INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

SET(CMAKE_SWIG_FLAGS "")

SET_SOURCE_FILES_PROPERTIES(partio.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(partio.i PROPERTIES SWIG_FLAGS "-includeall")
SWIG_ADD_MODULE(partio python partio.i)
SWIG_LINK_LIBRARIES(partio ${PYTHON_LIBRARIES} ${ZLIB_LIBRARY} partio)

SET(PYTHON_DEST "lib64/python${PYTHON_VERSION}/site-packages" )
INSTALL(TARGETS _partio DESTINATION ${PYTHON_DEST})
INSTALL(FILES ${CMAKE_BINARY_DIR}/${outdir}/src/py/partio.py  DESTINATION ${PYTHON_DEST})

ENDIF(PYTHONLIBS_FOUND)
ENDIF(SWIG_FOUND)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

内心激荡 2024-10-21 17:04:06

来自 CMake 2.8 文档

另一个特殊变量是
CMAKE_SWIG_OUTDIR,它允许一个
指定所有 swig 的写入位置
生成的模块(swig -outdir 选项)

因此,例如:

set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/bin)

From the CMake 2.8 docs:

Another special variable is
CMAKE_SWIG_OUTDIR, it allows one to
specify where to write all the swig
generated module (swig -outdir option)

So, for example:

set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
眼前雾蒙蒙 2024-10-21 17:04:06

我不熟悉 CMAKE,但是我知道您可以使用 SWIG 可执行文件的命令行选项设置 SWIG 的输出路径:

swig.exe -outdir /path/I/want

也许上面的行显示 SET(CMAKE_SWIG_FLAGS "")

您可以输入括号中是必需的命令行选项吗?

Im not versed with CMAKE, however I know you can set the output path of SWIG using a command line option to the SWIG executable:

swig.exe -outdir /path/I/want

Perhaps the line above that reads SET(CMAKE_SWIG_FLAGS "")

You can put in the parenthesis the required command line option?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文