有没有人幸运使用CMake通过SWIG创建Ruby绑定?我有一个在我的CMake文件中通过SWIG创建Python绑定的工作示例,但是当我使用相同的方法创建Ruby绑定时,实际的Ruby文件不会被创建。使用Python绑定工具,可以创建Python文件。
以下是我的CMakeLists.txt文件的相关部分:
if (${SWIG_FOUND})
find_package( Ruby REQUIRED )
include_directories(
${RUBY_INCLUDE_DIRS}
)
include (${SWIG_USE_FILE})
set (CMAKE_SWIG_FLAGS "") # set the global SWIG flags to empty
set_source_files_properties (TESTSWIG.i PROPERTIES CPLUSPLUS ON) # TESTSWIG.i is c++
SWIG_ADD_MODULE (test-ruby ruby TESTSWIG.i src/Test.cpp)
SWIG_LINK_LIBRARIES (test-ruby test ${RUBY_LIBRARY})
set(swig_SOURCES
${CMAKE_CURRENT_BINARY_DIR}/libtest-ruby.so
)
install(FILES ${swig_SOURCES}
DESTINATION lib/ruby
)
endif(${SWIG_FOUND})
任何人都有幸使用CMake通过SWIG创建Ruby绑定?!
答案 0 :(得分:3)
我们使用它。您可以查看以下示例:
http://svn.opensuse.org/svn/yast/trunk/libyui-bindings/
但是,我们不使用SWIG宏(除了查找SWIG本身),但我们使用ADD_CUSTOM_COMMAND:
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorarchdir']" OUTPUT_VARIABLE RUBY_VENDOR_ARCH_DIR)
MESSAGE(STATUS "Ruby executable: ${RUBY_EXECUTABLE}")
MESSAGE(STATUS "Ruby vendor arch dir: ${RUBY_VENDOR_ARCH_DIR}")
MESSAGE(STATUS "Ruby include path: ${RUBY_INCLUDE_PATH}")
SET( SWIG_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/yui_ruby.cxx" )
ADD_CUSTOM_COMMAND (
OUTPUT ${SWIG_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E echo_append "Creating wrapper code for ruby..."
COMMAND ${SWIG_EXECUTABLE} -c++ -ruby -autorename -o ${SWIG_OUTPUT} -I${LIBYUI_INCLUDE_DIR} ${SWIG_INPUT}
COMMAND ${CMAKE_COMMAND} -E echo "Done."
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../*.i
)
ADD_LIBRARY( yui_ruby SHARED ${SWIG_OUTPUT} )
INCLUDE_DIRECTORIES( ${RUBY_INCLUDE_PATH} ${LIBYUI_INCLUDE_DIR} )
SET_TARGET_PROPERTIES( yui_ruby PROPERTIES PREFIX "" OUTPUT_NAME "yui")
TARGET_LINK_LIBRARIES( yui_ruby ${LIBYUI_LIBRARY} )
TARGET_LINK_LIBRARIES( yui_ruby ${RUBY_LIBRARY} )
INSTALL(TARGETS yui_ruby LIBRARY DESTINATION ${RUBY_VENDOR_ARCH_DIR})
我认为您的版本无效,因为.so文件中的“lib”前缀。这正是我们
的原因SET_TARGET_PROPERTIES( yui_ruby PROPERTIES PREFIX "" OUTPUT_NAME "yui")
为了得到yui.so而不是libyui.so。
还要确保安装.so文件的路径位于ruby加载路径中。