Initial work on Ruby bindings, barely started.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 01 Feb 2010 04:22:05 -0500
changeset 1032 ea6aaadcfa04
parent 1031 206114270422
child 1033 c846b83628f4
Initial work on Ruby bindings, barely started. Mostly this is work on abstracting things in the build system.
CMakeLists.txt
extras/physfs-swig.i
--- a/CMakeLists.txt	Mon Feb 01 03:29:56 2010 -0500
+++ b/CMakeLists.txt	Mon Feb 01 04:22:05 2010 -0500
@@ -378,11 +378,40 @@
             ENDIF(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
         ENDIF((NOT CMAKE_BUILD_TYPE STREQUAL "") AND (NOT CMAKE_BUILD_TYPE STREQUAL "Debug"))
     ENDIF(DEFINED CMAKE_BUILD_TYPE)
+
+    MACRO(CONFIGURE_SWIG_BINDING _LANG _INSTALLPATH _EXTRAOUTPUTS _EXTRACFLAGS)
+        STRING(TOUPPER "${_LANG}" _UPPERLANG)
+        STRING(TOLOWER "${_LANG}" _LOWERLANG)
+        SET(_TARGET "physfs-${_LOWERLANG}")
+        IF(PHYSFS_BUILD_${_UPPERLANG})
+            ADD_CUSTOM_COMMAND(
+                OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/physfs-${_LOWERLANG}.c" ${_EXTRAOUTPUTS}
+                MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/extras/physfs-swig.i"
+                COMMAND "${SWIG}"
+                ARGS ${SWIG_OPT_CFLAGS} -${_LOWERLANG} -outdir "${CMAKE_CURRENT_BINARY_DIR}" -o "${CMAKE_CURRENT_BINARY_DIR}/physfs-${_LOWERLANG}.c" "${CMAKE_CURRENT_SOURCE_DIR}/extras/physfs-swig.i"
+                COMMENT "Generating ${_LANG} bindings..."
+            )
+
+            ADD_LIBRARY(${_TARGET} SHARED "${CMAKE_CURRENT_BINARY_DIR}/physfs-${_LOWERLANG}.c")
+            TARGET_LINK_LIBRARIES(${_TARGET} ${PHYSFS_LIB_TARGET})
+            SET_TARGET_PROPERTIES(${_TARGET} PROPERTIES
+                COMPILE_FLAGS "${_EXTRACFLAGS}"
+                OUTPUT_NAME "physfs"
+            )
+            INSTALL(TARGETS ${_TARGET} LIBRARY DESTINATION "${_INSTALLPATH}")
+            MESSAGE(STATUS "${_LANG} bindings configured!")
+        ELSE(PHYSFS_BUILD_${_UPPERLANG})
+            MESSAGE(STATUS "Couldn't figure out ${_LANG} configuration. Skipping ${_LANG} bindings.")
+        ENDIF(PHYSFS_BUILD_${_UPPERLANG})
+    ENDMACRO(CONFIGURE_SWIG_BINDING)
+
     MACRO(ADD_SCRIPT_BINDING_OPTION _VAR _LANG _DEFVAL)
         OPTION(${_VAR} "Build ${_LANG} bindings." ${_DEFVAL})
         MARK_AS_ADVANCED(${_VAR})
     ENDMACRO(ADD_SCRIPT_BINDING_OPTION)
+
     ADD_SCRIPT_BINDING_OPTION(PHYSFS_BUILD_PERL "Perl" TRUE)
+    ADD_SCRIPT_BINDING_OPTION(PHYSFS_BUILD_RUBY "Ruby" TRUE)
 ENDIF(NOT SWIG)
 
 IF(PHYSFS_BUILD_PERL)
@@ -421,30 +450,30 @@
     GET_PERL_CONFIG("ccflags" PERL_CCFLAGS)
     GET_PERL_CONFIG("installsitearch" PERL_INSTALL_PATH)
 
-    IF(PHYSFS_BUILD_PERL)
-        ADD_CUSTOM_COMMAND(
-            OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/physfs-perl.c" "${CMAKE_CURRENT_BINARY_DIR}/physfs.pm"
-            MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/extras/physfs-swig.i"
-            COMMAND "${SWIG}"
-            ARGS ${SWIG_OPT_CFLAGS} -perl -outdir "${CMAKE_CURRENT_BINARY_DIR}" -o "${CMAKE_CURRENT_BINARY_DIR}/physfs-perl.c" "${CMAKE_CURRENT_SOURCE_DIR}/extras/physfs-swig.i"
-            COMMENT "Generating Perl bindings..."
-        )
+    CONFIGURE_SWIG_BINDING(Perl "${PERL_INSTALL_PATH}" "${CMAKE_CURRENT_BINARY_DIR}/physfs.pm" "\"-I${PERL_INCLUDE_PATH}/CORE\" ${PERL_CCFLAGS} -w")
+    INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/physfs.pm" DESTINATION "${PERL_INSTALL_PATH}")
+ENDIF(PHYSFS_BUILD_PERL)
+
+IF(PHYSFS_BUILD_RUBY)
+    MESSAGE(STATUS "Ruby bindings aren't ready yet. Disabling.")
+    SET(PHYSFS_BUILD_RUBY FALSE)  # !!! FIXME: write me.
+ENDIF(PHYSFS_BUILD_RUBY)
 
-        ADD_LIBRARY(physfs-perl SHARED "${CMAKE_CURRENT_BINARY_DIR}/physfs-perl.c")
-        SET_TARGET_PROPERTIES(physfs PROPERTIES VERSION ${PHYSFS_VERSION})
-        SET_TARGET_PROPERTIES(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION})
-        TARGET_LINK_LIBRARIES(physfs-perl ${PHYSFS_LIB_TARGET})
-        SET_TARGET_PROPERTIES(physfs-perl PROPERTIES
-            COMPILE_FLAGS "\"-I${PERL_INCLUDE_PATH}/CORE\" ${PERL_CCFLAGS} -w"
-            OUTPUT_NAME "physfs"
-        )
-        INSTALL(TARGETS physfs-perl LIBRARY DESTINATION "${PERL_INSTALL_PATH}")
-        INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/physfs.pm" DESTINATION "${PERL_INSTALL_PATH}")
-        MESSAGE(STATUS "Perl bindings configured!")
-    ELSE(PHYSFS_BUILD_PERL)
-        MESSAGE(STATUS "Couldn't figure out perl configuration. Skipping perl bindings.")
-    ENDIF(PHYSFS_BUILD_PERL)
-ENDIF(PHYSFS_BUILD_PERL)
+IF(PHYSFS_BUILD_RUBY)
+    MESSAGE(STATUS "Configuring Ruby bindings...")
+    FIND_PACKAGE(Ruby)
+    IF(NOT RUBY_FOUND)
+        MESSAGE(STATUS "Ruby not found. You won't be able to build ruby bindings.")
+        SET(PHYSFS_BUILD_RUBY FALSE)
+    ENDIF(NOT RUBY_FOUND)
+
+    #MESSAGE(STATUS "RUBY_EXECUTABLE '${RUBY_EXECUTABLE}'")
+    #MESSAGE(STATUS "RUBY_INCLUDE_DIRS '${RUBY_INCLUDE_DIRS}'")
+    #MESSAGE(STATUS "RUBY_LIBRARY '${RUBY_LIBRARY}'")
+    #MESSAGE(STATUS "RUBY_VERSION '${RUBY_VERSION}'")
+    #CONFIGURE_SWIG_BINDING(Ruby "${PERL_INSTALL_PATH}" "" "")
+ENDIF(PHYSFS_BUILD_RUBY)
+
 
 INSTALL(TARGETS ${PHYSFS_INSTALL_TARGETS}
         RUNTIME DESTINATION bin
@@ -485,6 +514,7 @@
 MESSAGE_BOOL_OPTION("Build static library" PHYSFS_BUILD_STATIC)
 MESSAGE_BOOL_OPTION("Build shared library" PHYSFS_BUILD_SHARED)
 MESSAGE_BOOL_OPTION("Build Perl bindings" PHYSFS_BUILD_PERL)
+MESSAGE_BOOL_OPTION("Build Ruby bindings" PHYSFS_BUILD_RUBY)
 MESSAGE_BOOL_OPTION("Build wxWidgets test program" PHYSFS_BUILD_WX_TEST)
 MESSAGE_BOOL_OPTION("Build stdio test program" PHYSFS_BUILD_TEST)
 IF(PHYSFS_BUILD_TEST)
--- a/extras/physfs-swig.i	Mon Feb 01 03:29:56 2010 -0500
+++ b/extras/physfs-swig.i	Mon Feb 01 04:22:05 2010 -0500
@@ -13,8 +13,8 @@
 %ignore PHYSFS_CALL;  /* ignore the calling conventions define. */
 %ignore PHYSFS_file;  /* legacy type define. */
 
-#ifdef SWIGPERL
-/* The Perl bindings put everything in a namespace, so we don't need PHYSFS_ */
+/* Some bindings put everything in a namespace, so we don't need PHYSFS_ */
+#if defined(SWIGPERL) || defined(SWIGRUBY)
 %rename(File) PHYSFS_File;
 %rename(Version) PHYSFS_Version;
 %rename(ArchiveInfo) PHYSFS_ArchiveInfo;