physfs compilation on windows
* external calls must always be named
* physfs has to be compiled as dll
* there shouln't be external variables, implemented a function that sets buffer
* physfs extras is now integrated in main physfs
* removed physfs extras
--- a/CMakeLists.txt Tue Nov 20 17:50:17 2012 +0100
+++ b/CMakeLists.txt Tue Nov 20 18:33:09 2012 +0100
@@ -252,7 +252,6 @@
# physfs library
add_subdirectory(misc/physfs)
-add_subdirectory(misc/physfs/extras)
#Android related build scripts
if(ANDROID)
--- a/QTfrontend/CMakeLists.txt Tue Nov 20 17:50:17 2012 +0100
+++ b/QTfrontend/CMakeLists.txt Tue Nov 20 18:33:09 2012 +0100
@@ -168,7 +168,6 @@
set(HW_LINK_LIBS
physfs
- physfsrwops
${QT_LIBRARIES}
${SDL_LIBRARY}
${SDLMIXER_LIBRARY}
--- a/hedgewars/CMakeLists.txt Tue Nov 20 17:50:17 2012 +0100
+++ b/hedgewars/CMakeLists.txt Tue Nov 20 18:33:09 2012 +0100
@@ -233,13 +233,11 @@
message(STATUS "Video recording disabled by user")
endif()
-if(MINGW)
- get_filename_component(MINGWBINPATH ${CMAKE_C_COMPILER} PATH)
- set(MINGWLIBPATH "${MINGWBINPATH}/../lib"
- CACHE FILEPATH "Path to MinGW import libraries")
-
- set(pascal_flags "-Fl${MINGWLIBPATH}" ${pascal_flags})
-endif(MINGW)
+#if(MINGW)
+# get_filename_component(MINGWBINPATH ${CMAKE_C_COMPILER} PATH)
+# set(MINGWLIBPATH "${MINGWBINPATH}/../lib"
+# CACHE FILEPATH "Path to MinGW import libraries")
+#endif(MINGW)
set(fpc_flags ${noexecstack_flags} ${pascal_flags} ${hwengine_project})
@@ -281,7 +279,6 @@
# compile physfs before engine
add_dependencies(${engine_output_name} physfs)
-add_dependencies(${engine_output_name} physfsrwops)
#when ffmpeg/libav is found we need to compile it before engine
#TODO: convert avwrapper to .pas unit so we can skip this step
--- a/hedgewars/uPhysFSLayer.pas Tue Nov 20 17:50:17 2012 +0100
+++ b/hedgewars/uPhysFSLayer.pas Tue Nov 20 18:33:09 2012 +0100
@@ -1,27 +1,30 @@
unit uPhysFSLayer;
-{$IFDEF ANDROID}
- {$linklib physfs}
- {$linklib physfsrwops}
-{$ELSE}
- {$LINKLIB ../bin/libphysfs.a}
- {$LINKLIB ../bin/libphysfsrwops.a}
-{$ENDIF}
-
-{$IFDEF WIN32}
- {$LINKLIB kernel32}
- {$LINKLIB user32}
- {$LINKLIB shell32}
- {$LINKLIB advapi32}
- {$LINKLIB msvcrt}
-{$ENDIF}
-
-{$IFDEF DARWIN}
- {$LINKFRAMEWORK IOKit}
-{$ENDIF}
interface
uses SDLh;
+{$IFDEF ANDROID}
+ {$linklib physfs}
+{$ELSE}
+ {$IFNDEF WIN32}
+ {$linklib ../bin/libphysfs.a}
+ {$ENDIF}
+ {$IFDEF DARWIN}
+ {$LINKFRAMEWORK IOKit}
+ {$ENDIF}
+{$ENDIF}
+
+const
+{$IFDEF WIN32}
+ PhysfsLibName = 'libphysfs';
+{$ELSE}
+ {$IFDEF DARWIN}
+ PhysfsLibName = 'physfs';
+ {$ELSE}
+ PhysfsLibName = 'physfs.a';
+ {$ENDIF}
+{$ENDIF}
+
procedure initModule;
procedure freeModule;
@@ -42,19 +45,19 @@
implementation
uses uUtils, uVariables;
-function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external;
-function PHYSFS_deinit() : LongInt; cdecl; external;
-function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external;
-function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external;
+function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external PhysfsLibName;
+function PHYSFS_deinit() : LongInt; cdecl; external PhysfsLibName;
+function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl ; external PhysfsLibName;
+function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhysfsLibName;
-function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external;
-function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external;
-function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external;
-function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external;
-function PHYSFS_close(f: PFSFile): LongBool; cdecl; external;
-function PHYSFS_exists(fname: PChar): LongBool; cdecl; external;
+function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external PhysfsLibName;
+function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName;
+function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
+function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName;
+function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
+function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName;
-procedure hedgewarsMountPackages(); cdecl; external;
+procedure hedgewarsMountPackages(); cdecl; external PhysfsLibName;
function rwopsOpenRead(fname: shortstring): PSDL_RWops;
begin
--- a/hedgewars/uScript.pas Tue Nov 20 17:50:17 2012 +0100
+++ b/hedgewars/uScript.pas Tue Nov 20 18:33:09 2012 +0100
@@ -1980,8 +1980,17 @@
// custom script loader via physfs, passed to lua_load
const BUFSIZE = 1024;
-var physfsReaderBuffer: pointer; cvar; external;
-function physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external;
+{$IFDEF WIN32}
+ PhysfsLibName = 'libphysfs';
+{$ELSE}
+ {$IFDEF DARWIN}
+ PhysfsLibName = 'physfs';
+ {$ELSE}
+ PhysfsLibName = 'physfs.a';
+ {$ENDIF}
+{$ENDIF}
+function physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhysfsLibName;
+procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhysfsLibName;
procedure ScriptLoad(name : shortstring);
@@ -1998,7 +2007,7 @@
if f = nil then
exit;
-physfsReaderBuffer:= @buf;
+physfsReaderSetBuffer(@buf);
ret:= lua_load(luaState, @physfsReader, f, Str2PChar(s));
pfsClose(f);
--- a/misc/physfs/CMakeLists.txt Tue Nov 20 17:50:17 2012 +0100
+++ b/misc/physfs/CMakeLists.txt Tue Nov 20 18:33:09 2012 +0100
@@ -34,7 +34,9 @@
INCLUDE(CheckLibraryExists)
INCLUDE(CheckCSourceCompiles)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
+include_directories(${SDL_INCLUDE_DIR}) #hw
+include_directories(${LUA_INCLUDE_DIR}) #hw
IF(MACOSX)
# Fallback to older OS X on PowerPC to support wider range of systems...
@@ -135,6 +137,10 @@
src/archiver_wad.c
src/archiver_zip.c
src/archiver_iso9660.c
+ #custom files from Hedgewars
+ extras/physfsrwops.c
+ extras/physfslualoader.c
+ extras/hwpacksmounter.c
${PHYSFS_BEOS_SRCS}
)
@@ -254,8 +260,14 @@
ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_ISO9660=1)
ENDIF(PHYSFS_ARCHIVE_ISO9660)
+IF(WINDOWS)
+ OPTION(PHYSFS_BUILD_STATIC "Build static library" FALSE)
+ OPTION(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
+ELSE(WINDOWS)
+ OPTION(PHYSFS_BUILD_STATIC "Build static library" TRUE)
+ OPTION(PHYSFS_BUILD_SHARED "Build shared library" FALSE)
+ENDIF(WINDOWS)
-OPTION(PHYSFS_BUILD_STATIC "Build static library" TRUE)
IF(PHYSFS_BUILD_STATIC)
ADD_LIBRARY(physfs STATIC ${PHYSFS_SRCS})
SET_TARGET_PROPERTIES(physfs PROPERTIES OUTPUT_NAME "physfs")
@@ -263,15 +275,15 @@
SET(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs")
ENDIF(PHYSFS_BUILD_STATIC)
-#OPTION(PHYSFS_BUILD_SHARED "Build shared library" FALSE)
-#IF(PHYSFS_BUILD_SHARED)
-# ADD_LIBRARY(physfs SHARED ${PHYSFS_SRCS})
-# SET_TARGET_PROPERTIES(physfs PROPERTIES VERSION ${PHYSFS_VERSION})
-# SET_TARGET_PROPERTIES(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION})
-# TARGET_LINK_LIBRARIES(physfs ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
-# SET(PHYSFS_LIB_TARGET physfs)
-# SET(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs")
-#ENDIF(PHYSFS_BUILD_SHARED)
+IF(PHYSFS_BUILD_SHARED)
+ find_package(SDL REQUIRED)
+ ADD_LIBRARY(physfs SHARED ${PHYSFS_SRCS})
+ SET_TARGET_PROPERTIES(physfs PROPERTIES VERSION ${PHYSFS_VERSION})
+ SET_TARGET_PROPERTIES(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION})
+ TARGET_LINK_LIBRARIES(physfs ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS} SDL)
+ SET(PHYSFS_LIB_TARGET physfs)
+ SET(PHYSFS_INSTALL_TARGETS ${PHYSFS_INSTALL_TARGETS} ";physfs")
+ENDIF(PHYSFS_BUILD_SHARED)
IF(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
MESSAGE(FATAL "Both shared and static libraries are disabled!")
@@ -280,7 +292,6 @@
# CMake FAQ says I need this...
IF(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC)
SET_TARGET_PROPERTIES(physfs PROPERTIES CLEAN_DIRECT_OUTPUT 1)
- SET_TARGET_PROPERTIES(physfs-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
ENDIF(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC)
OPTION(PHYSFS_BUILD_TEST "Build stdio test program." FALSE)
--- a/misc/physfs/extras/Android.mk Tue Nov 20 17:50:17 2012 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := physfsrwops
-
-LOCAL_CFLAGS := -O2 -DPHYSFS_NO_CDROM_SUPPORT
-
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../liblua $(LOCAL_PATH)/../src $(LOCAL_PATH)/../../../project_files/Android-build/SDL-android-project/jni/SDL/include
-
-LOCAL_SRC_FILES := hwpacksmounter.c \
- physfslualoader.c \
- physfsrwops.c
-
-LOCAL_SHARED_LIBRARIES := SDL physfs
-
-include $(BUILD_SHARED_LIBRARY)
--- a/misc/physfs/extras/CMakeLists.txt Tue Nov 20 17:50:17 2012 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-find_package(SDL REQUIRED)
-
-include_directories(${SDL_INCLUDE_DIR})
-include_directories(${LUA_INCLUDE_DIR})
-include_directories(${CMAKE_SOURCE_DIR}/misc/physfs/src)
-
-add_library(physfsrwops STATIC physfsrwops.c physfslualoader.c hwpacksmounter.c)
-
--- a/misc/physfs/extras/physfslualoader.c Tue Nov 20 17:50:17 2012 +0100
+++ b/misc/physfs/extras/physfslualoader.c Tue Nov 20 18:33:09 2012 +0100
@@ -3,7 +3,7 @@
#define BUFSIZE 1024
-void * physfsReaderBuffer;
+void *physfsReaderBuffer;
const char * physfsReader(lua_State *L, PHYSFS_File *f, size_t *size)
{
@@ -22,3 +22,8 @@
return physfsReaderBuffer;
}
}
+
+void physfsReaderSetBuffer(void *buffer)
+{
+ physfsReaderBuffer = buffer;
+}
\ No newline at end of file
--- a/misc/physfs/src/Android.mk Tue Nov 20 17:50:17 2012 +0100
+++ b/misc/physfs/src/Android.mk Tue Nov 20 18:33:09 2012 +0100
@@ -23,5 +23,8 @@
archiver_qpak.c \
archiver_wad.c \
archiver_zip.c \
+ ../extras/hwpacksmounter.c \
+ ../extras/physfslualoader.c \
+ ../extras/physfsrwops.c \
include $(BUILD_SHARED_LIBRARY)
--- a/project_files/hedgewars.pro Tue Nov 20 17:50:17 2012 +0100
+++ b/project_files/hedgewars.pro Tue Nov 20 18:33:09 2012 +0100
@@ -233,7 +233,7 @@
RESOURCES += ../QTfrontend/hedgewars.qrc
-LIBS += -L../bin -lphysfs -lphysfsrwops
+LIBS += -L../bin -lphysfs
macx {
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6