From 392193ea0cc1324f2cdca432c336e9d71478dffb Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 1 Feb 2010 03:17:14 -0500 Subject: [PATCH] Hooked up Perl bindings, via SWIG. --- CMakeLists.txt | 89 ++++++++++++++++++++++++++++++++++++++++++++ extras/physfs-swig.i | 86 ++++++++++++++++++++++++++++++++++++++++++ src/physfs.h | 7 ---- 3 files changed, 175 insertions(+), 7 deletions(-) create mode 100644 extras/physfs-swig.i diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bdd5b7..dc7b9c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -358,6 +358,94 @@ IF(PHYSFS_BUILD_WX_TEST) ENDIF(wxWidgets_FOUND) ENDIF(PHYSFS_BUILD_WX_TEST) + +# Scripting language bindings... + +#CMake's SWIG support is basically useless. +#FIND_PACKAGE(SWIG) + +FIND_PROGRAM(SWIG swig DOC "Path to swig command line app: http://swig.org/") +IF(NOT SWIG) + MESSAGE(STATUS "SWIG not found. You won't be able to build scripting language bindings.") +ELSE(NOT SWIG) + MARK_AS_ADVANCED(SWIG) + IF(DEFINED CMAKE_BUILD_TYPE) + IF((NOT CMAKE_BUILD_TYPE STREQUAL "") AND (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")) + IF(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") + SET(SWIG_OPT_CFLAGS "-small") + ELSE(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") + SET(SWIG_OPT_CFLAGS "-O") + 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(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) +ENDIF(NOT SWIG) + +IF(PHYSFS_BUILD_PERL) + MESSAGE(STATUS "Configuring Perl bindings...") + INCLUDE(FindPerl) + IF(NOT PERL_FOUND) + MESSAGE(STATUS "Perl not found. You won't be able to build perl bindings.") + SET(PHYSFS_BUILD_PERL FALSE) + ENDIF(NOT PERL_FOUND) + + MACRO(GET_PERL_CONFIG _KEY _VALUE) + IF(PHYSFS_BUILD_PERL) + MESSAGE(STATUS "Figuring out perl config value '${_KEY}' ...") + EXECUTE_PROCESS( + COMMAND ${PERL_EXECUTABLE} -w -e "use Config; print \$Config{${_KEY}};" + RESULT_VARIABLE GET_PERL_CONFIG_RC + OUTPUT_VARIABLE ${_VALUE} + ) + IF(NOT GET_PERL_CONFIG_RC EQUAL 0) + MESSAGE(STATUS "Perl executable ('${PERL_EXECUTABLE}') reported failure: ${GET_PERL_CONFIG_RC}") + SET(PHYSFS_BUILD_PERL FALSE) + ENDIF(NOT GET_PERL_CONFIG_RC EQUAL 0) + IF(NOT ${_VALUE}) + MESSAGE(STATUS "Perl executable ('${PERL_EXECUTABLE}') didn't have a value for '${_KEY}'") + SET(PHYSFS_BUILD_PERL FALSE) + ENDIF(NOT ${_VALUE}) + + IF(PHYSFS_BUILD_PERL) + MESSAGE(STATUS "Perl says: '${${_VALUE}}'.") + ENDIF(PHYSFS_BUILD_PERL) + ENDIF(PHYSFS_BUILD_PERL) + ENDMACRO(GET_PERL_CONFIG) + + # !!! FIXME: installsitearch might be the wrong location. + GET_PERL_CONFIG("installarchlib" PERL_INCLUDE_PATH) + 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 -w451 ${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..." + ) + + 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) + INSTALL(TARGETS ${PHYSFS_INSTALL_TARGETS} RUNTIME DESTINATION bin LIBRARY DESTINATION lib @@ -396,6 +484,7 @@ MESSAGE_BOOL_OPTION("Thread safety" PHYSFS_HAVE_THREAD_SUPPORT) MESSAGE_BOOL_OPTION("Build own zlib" PHYSFS_INTERNAL_ZLIB) 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 wxWidgets test program" PHYSFS_BUILD_WX_TEST) MESSAGE_BOOL_OPTION("Build stdio test program" PHYSFS_BUILD_TEST) IF(PHYSFS_BUILD_TEST) diff --git a/extras/physfs-swig.i b/extras/physfs-swig.i new file mode 100644 index 0000000..bd3d428 --- /dev/null +++ b/extras/physfs-swig.i @@ -0,0 +1,86 @@ +/* Metadata to generate the scripting language bindings. Please ignore. */ +%module physfs + +%{ +#include "physfs.h" +%} + +%ignore _INCLUDE_PHYSFS_H_; /* ignore the include-once blocker. */ +%ignore PHYSFS_DECL; /* ignore the export define. */ +%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_ */ +%rename(File) PHYSFS_File; +%rename(Version) PHYSFS_Version; +%rename(ArchiveInfo) PHYSFS_ArchiveInfo; +%rename(getLinkedVersion) PHYSFS_getLinkedVersion; +%rename(init) PHYSFS_init; +%rename(deinit) PHYSFS_deinit; +%rename(supportedArchiveTypes) PHYSFS_supportedArchiveTypes; +%rename(freeList) PHYSFS_freeList; +%rename(getLastError) PHYSFS_getLastError; +%rename(getDirSeparator) PHYSFS_getDirSeparator; +%rename(permitSymbolicLinks) PHYSFS_permitSymbolicLinks; +%rename(getCdRomDirs) PHYSFS_getCdRomDirs; +%rename(getBaseDir) PHYSFS_getBaseDir; +%rename(getUserDir) PHYSFS_getUserDir; +%rename(getWriteDir) PHYSFS_getWriteDir; +%rename(setWriteDir) PHYSFS_setWriteDir; +%rename(addToSearchPath) PHYSFS_addToSearchPath; +%rename(removeFromSearchPath) PHYSFS_removeFromSearchPath; +%rename(getSearchPath) PHYSFS_getSearchPath; +%rename(setSaneConfig) PHYSFS_setSaneConfig; +%rename(mkdir) PHYSFS_mkdir; +%rename(delete) PHYSFS_delete; +%rename(getRealDir) PHYSFS_getRealDir; +%rename(enumerateFiles) PHYSFS_enumerateFiles; +%rename(exists) PHYSFS_exists; +%rename(isDirectory) PHYSFS_isDirectory; +%rename(isSymbolicLink) PHYSFS_isSymbolicLink; +%rename(getLastModTime) PHYSFS_getLastModTime; +%rename(openWrite) PHYSFS_openWrite; +%rename(openAppend) PHYSFS_openAppend; +%rename(openRead) PHYSFS_openRead; +%rename(close) PHYSFS_close; +%rename(read) PHYSFS_read; +%rename(write) PHYSFS_write; +%rename(eof) PHYSFS_eof; +%rename(tell) PHYSFS_tell; +%rename(seek) PHYSFS_seek; +%rename(fileLength) PHYSFS_fileLength; +%rename(setBuffer) PHYSFS_setBuffer; +%rename(flush) PHYSFS_flush; +%rename(readSLE16) PHYSFS_readSLE16; +%rename(readULE16) PHYSFS_readULE16; +%rename(readSBE16) PHYSFS_readSBE16; +%rename(readUBE16) PHYSFS_readUBE16; +%rename(readSLE32) PHYSFS_readSLE32; +%rename(readULE32) PHYSFS_readULE32; +%rename(readSBE32) PHYSFS_readSBE32; +%rename(readUBE32) PHYSFS_readUBE32; +%rename(readSLE64) PHYSFS_readSLE64; +%rename(readULE64) PHYSFS_readULE64; +%rename(readSBE64) PHYSFS_readSBE64; +%rename(readUBE64) PHYSFS_readUBE64; +%rename(writeSLE16) PHYSFS_writeSLE16; +%rename(writeULE16) PHYSFS_writeULE16; +%rename(writeSBE16) PHYSFS_writeSBE16; +%rename(writeUBE16) PHYSFS_writeUBE16; +%rename(writeSLE32) PHYSFS_writeSLE32; +%rename(writeULE32) PHYSFS_writeULE32; +%rename(writeSBE32) PHYSFS_writeSBE32; +%rename(writeUBE32) PHYSFS_writeUBE32; +%rename(writeSLE64) PHYSFS_writeSLE64; +%rename(writeULE64) PHYSFS_writeULE64; +%rename(writeSBE64) PHYSFS_writeSBE64; +%rename(writeUBE64) PHYSFS_writeUBE64; +%rename(isInit) PHYSFS_isInit; +%rename(symbolicLinksPermitted) PHYSFS_symbolicLinksPermitted; +%rename(mount) PHYSFS_mount; +%rename(getMountPoint) PHYSFS_getMountPoint; +#endif /* SWIGPERL */ + +%include "../src/physfs.h" + diff --git a/src/physfs.h b/src/physfs.h index e44a946..015d7ec 100644 --- a/src/physfs.h +++ b/src/physfs.h @@ -212,13 +212,6 @@ #ifndef _INCLUDE_PHYSFS_H_ #define _INCLUDE_PHYSFS_H_ -#ifdef SWIG -%module physfs -%{ -#include "physfs.h" -%} -#endif - #ifdef __cplusplus extern "C" { #endif