Ruby and SWIG with CMake

Has anyone managed to use CMake to create Ruby bindings through SWIG? I have a working example for creating Python bindings via SWIG in my CMake file, but when I use the same approach to create a Ruby binding, the actual Ruby file is not created. Using a working Python bundle, a Python file is created.

Here are the relevant parts of my CMakeLists.txt file:

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})

Someone was lucky to create Ruby bindings through SWIG using CMake ?!

+3
source share
1 answer

We use it. You can look at these examples:

http://svn.opensuse.org/svn/yast/trunk/libyui-bindings/

However, we do not use SWIG macros (except for searching for SWIG itself), but we use 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})

, , "lib" .so .

SET_TARGET_PROPERTIES( yui_ruby PROPERTIES PREFIX "" OUTPUT_NAME "yui")

yui.so libyui.so.

, , .so , ruby.

+3

All Articles