如何在cmake中更改SWIG生成的.py文件?
我们可以使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 CMake 2.8 文档:
因此,例如:
From the CMake 2.8 docs:
So, for example:
我不熟悉 CMAKE,但是我知道您可以使用 SWIG 可执行文件的命令行选项设置 SWIG 的输出路径:
也许上面的行显示 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:
Perhaps the line above that reads SET(CMAKE_SWIG_FLAGS "")
You can put in the parenthesis the required command line option?