Просмотр исходного кода

Now compiles everything whether we need it or not, removing whole files with
#ifdefs...this will make it easier to "embed" this library in other projects
or use a different build system: just push everything through the compiler
with preprocessor defines for the parts you want/need...platform modules are
determined automatically without the build system needing to intervene, so
you just have to #define the archivers, etc that you want.

Ryan C. Gordon 19 лет назад
Родитель
Сommit
69598e49ab
11 измененных файлов с 144 добавлено и 65 удалено
  1. 7 0
      CHANGELOG.txt
  2. 42 20
      CMakeLists.txt
  3. 38 0
      physfs_platforms.h
  4. 5 3
      platform/beos.cpp
  5. 7 12
      platform/macclassic.c
  6. 5 3
      platform/os2.c
  7. 7 1
      platform/pocketpc.c
  8. 5 3
      platform/posix.c
  9. 8 3
      platform/skeleton.c
  10. 14 17
      platform/unix.c
  11. 6 3
      platform/windows.c

+ 7 - 0
CHANGELOG.txt

@@ -6,6 +6,13 @@
            branch for history's sake. Added shared and static build options
            to CMakeLists.txt, and the expected "make install" target.
            Renamed some FILENAME files to FILENAME.txt, removed physfs.rc.
+           Now compiles everything whether we need it or not, removing whole
+           files with #ifdefs...this will make it easier to "embed" this
+           library in other projects or use a different build system: just
+           push everything through the compiler with preprocessor defines for
+           the parts you want/need...platform modules are determined
+           automatically without the build system needing to intervene, so you
+           just have to #define the archivers, etc that you want.
 03082007 - Fixed a comment in physfs.h. Renamed win32.c to windows.c.
            Cleaned up whitespace/formatting in pocketpc.c. Updated PocketPC
            code to expect UTF-8 strings from the higher level. Changed

+ 42 - 20
CMakeLists.txt

@@ -6,7 +6,7 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
 
 PROJECT(PhysicsFS)
-SET(PHYSFS_VERSION 1.1.2)
+SET(PHYSFS_VERSION 1.1.1)
 SET(PHYSFS_SOVERSION 1)
 
 # I hate that they define "WIN32" ... we're about to move to Win64...I hope!
@@ -88,23 +88,46 @@ SET(LZMA_SRCS
     lzma/LzmaStateDecode.c
 )
 
+IF(BEOS)
+    # We add this explicitly, since we don't want CMake to think this
+    #  is a C++ project unless we're on BeOS.
+    SET(PHYSFS_BEOS_SRCS platform/beos.cpp)
+ENDIF(BEOS)
+
+# Almost everything is "compiled" here, but things that don't apply to the
+#  build are #ifdef'd out. This is to make it easy to embed PhysicsFS into
+#  another project or bring up a new build system: just compile all the source
+#  code and #define the things you want.
 SET(PHYSFS_SRCS
     physfs.c
     physfs_byteorder.c
     physfs_unicode.c
+    platform/macclassic.c
+    platform/os2.c
+    platform/pocketpc.c
+    platform/posix.c
+    platform/unix.c
+    platform/windows.c
     archivers/dir.c
+    archivers/grp.c
+    archivers/hog.c
+    archivers/lzma.c
+    archivers/mvl.c
+    archivers/qpak.c
+    archivers/wad.c
+    archivers/zip.c
+    ${PHYSFS_BEOS_SRCS}
 )
 
 
 # platform layers ...
 
 IF(UNIX)
-    SET(PHYSFS_SRCS ${PHYSFS_SRCS} platform/posix.c)
     IF(BEOS)
-        SET(PHYSFS_SRCS ${PHYSFS_SRCS} platform/beos.cpp)
         SET(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
+        SET(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
+        SET(HAVE_PTHREAD_H TRUE)
     ELSE(BEOS)
-        SET(PHYSFS_SRCS ${PHYSFS_SRCS} platform/unix.c)
         # !!! FIXME
         #  AC_DEFINE([PHYSFS_HAVE_LLSEEK], 1, [define if we have llseek])
         CHECK_INCLUDE_FILE(sys/ucred.h HAVE_UCRED_H)
@@ -118,21 +141,19 @@ IF(UNIX)
             ADD_DEFINITIONS(-DPHYSFS_HAVE_MNTENT_H=1)
             SET(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
         ENDIF(HAVE_MNTENT_H)
-    ENDIF(BEOS)
 
-    CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
-    IF(HAVE_PTHREAD_H)
-        SET(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
-    ELSE(HAVE_PTHREAD_H)
-        ADD_DEFINITIONS(-DPHYSFS_NO_PTHREADS_SUPPORT=1)
-    ENDIF(HAVE_PTHREAD_H)
+        CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
+        IF(HAVE_PTHREAD_H)
+            SET(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
+        ELSE(HAVE_PTHREAD_H)
+            ADD_DEFINITIONS(-DPHYSFS_NO_PTHREADS_SUPPORT=1)
+        ENDIF(HAVE_PTHREAD_H)
+    ENDIF(BEOS)
 ENDIF(UNIX)
 
 IF(WINDOWS)
-    SET(PHYSFS_SRCS ${PHYSFS_SRCS} platform/windows.c)
     SET(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
     SET(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
-    # !!! FIXME: platform/pocketpc.c ... ?
 ENDIF(WINDOWS)
 
 IF(NOT PHYSFS_HAVE_CDROM_SUPPORT)
@@ -158,12 +179,18 @@ ELSE(PHYSFS_HAVE_THREAD_SUPPORT)
     MESSAGE(WARNING " ***")
 ENDIF(PHYSFS_HAVE_THREAD_SUPPORT)
 
+CHECK_INCLUDE_FILE(assert.h HAVE_ASSERT_H)
+IF(HAVE_ASSERT_H)
+    ADD_DEFINITIONS(-DHAVE_ASSERT_H=1)
+ENDIF(HAVE_ASSERT_H)
+
+
+
 # Archivers ...
 
 OPTION(PHYSFS_ARCHIVE_ZIP "Enable ZIP support" TRUE)
 IF(PHYSFS_ARCHIVE_ZIP)
     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_ZIP=1)
-    SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/zip.c)
     SET(PHYSFS_NEED_ZLIB TRUE)
 ENDIF(PHYSFS_ARCHIVE_ZIP)
 
@@ -171,7 +198,7 @@ OPTION(PHYSFS_ARCHIVE_7Z "Enable 7zip support" TRUE)
 IF(PHYSFS_ARCHIVE_7Z)
     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_7Z=1)
     # !!! FIXME: rename to 7z.c?
-    SET(PHYSFS_SRCS ${PHYSFS_SRCS} ${LZMA_SRCS} archivers/lzma.c)
+    SET(PHYSFS_SRCS ${PHYSFS_SRCS} ${LZMA_SRCS})
     INCLUDE_DIRECTORIES(lzma)
     ADD_DEFINITIONS(-D_LZMA_IN_CB=1)
     ADD_DEFINITIONS(-D_LZMA_PROB32=1)
@@ -182,31 +209,26 @@ ENDIF(PHYSFS_ARCHIVE_7Z)
 OPTION(PHYSFS_ARCHIVE_GRP "Enable Build Engine GRP support" TRUE)
 IF(PHYSFS_ARCHIVE_GRP)
     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_GRP=1)
-    SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/grp.c)
 ENDIF(PHYSFS_ARCHIVE_GRP)
 
 OPTION(PHYSFS_ARCHIVE_WAD "Enable Doom WAD support" TRUE)
 IF(PHYSFS_ARCHIVE_WAD)
     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_WAD=1)
-    SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/wad.c)
 ENDIF(PHYSFS_ARCHIVE_WAD)
 
 OPTION(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
 IF(PHYSFS_ARCHIVE_HOG)
     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_HOG=1)
-    SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/hog.c)
 ENDIF(PHYSFS_ARCHIVE_HOG)
 
 OPTION(PHYSFS_ARCHIVE_MVL "Enable Descent I/II MVL support" TRUE)
 IF(PHYSFS_ARCHIVE_MVL)
     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_MVL=1)
-    SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/mvl.c)
 ENDIF(PHYSFS_ARCHIVE_MVL)
 
 OPTION(PHYSFS_ARCHIVE_QPAK "Enable Quake I/II QPAK support" TRUE)
 IF(PHYSFS_ARCHIVE_QPAK)
     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_QPAK=1)
-    SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/qpak.c)
 ENDIF(PHYSFS_ARCHIVE_QPAK)
 
 

+ 38 - 0
physfs_platforms.h

@@ -0,0 +1,38 @@
+#ifndef _INCL_PHYSFS_PLATFORMS
+#define _INCL_PHYSFS_PLATFORMS
+
+#ifndef __PHYSICSFS_INTERNAL__
+#error Do not include this header from your applications.
+#endif
+
+/*
+ * These only define the platforms to determine which files in the platforms
+ *  directory should be compiled. For example, technically BeOS can be called
+ *  a "unix" system, but since it doesn't use unix.c, we don't define
+ *  PHYSFS_PLATFORM_UNIX on that system.
+ */
+
+#if ((defined __BEOS__) || (defined __beos__))
+#  define PHYSFS_PLATFORM_BEOS
+#  define PHYSFS_PLATFORM_POSIX
+#elif (defined _WIN32_WCE) || (defined _WIN64_WCE)
+#  define PHYSFS_PLATFORM_POCKETPC
+#elif (((defined _WIN32) || (defined _WIN64)) && (!defined __CYGWIN__))
+#  define PHYSFS_PLATFORM_WINDOWS
+#elif (defined OS2)
+#  define PHYSFS_PLATFORM_OS2
+#elif ((defined __MACH__) && (defined __APPLE__))
+#  define PHYSFS_PLATFORM_MACOSX
+#  define PHYSFS_PLATFORM_UNIX
+#  define PHYSFS_PLATFORM_POSIX
+#elif defined(macintosh)
+#  define PHYSFS_PLATFORM_MACCLASSIC
+#elif defined(unix)
+#  define PHYSFS_PLATFORM_UNIX
+#  define PHYSFS_PLATFORM_POSIX
+#else
+#  error Unknown platform.
+#endif
+
+#endif  /* include-once blocker. */
+

+ 5 - 3
platform/beos.cpp

@@ -6,7 +6,10 @@
  *  This file written by Ryan C. Gordon.
  */
 
-#ifdef __BEOS__
+#define __PHYSICSFS_INTERNAL__
+#include "physfs_platforms.h"
+
+#ifdef PHYSFS_PLATFORM_BEOS
 
 #include <be/kernel/OS.h>
 #include <be/app/Roster.h>
@@ -24,7 +27,6 @@
 #include <errno.h>
 #include <unistd.h>
 
-#define __PHYSICSFS_INTERNAL__
 #include "physfs_internal.h"
 
 
@@ -244,7 +246,7 @@ void __PHYSFS_platformReleaseMutex(void *mutex)
     release_sem(*((sem_id *) mutex));
 } /* __PHYSFS_platformReleaseMutex */
 
-#endif
+#endif  /* PHYSFS_PLATFORM_BEOS */
 
 /* end of beos.cpp ... */
 

+ 7 - 12
platform/macclassic.c

@@ -6,6 +6,11 @@
  *  This file written by Ryan C. Gordon.
  */
 
+#define __PHYSICSFS_INTERNAL__
+#include "physfs_platforms.h"
+
+#ifdef PHYSFS_PLATFORM_MACCLASSIC
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -31,15 +36,6 @@
  */
 
 
-/*
- * Please note that I haven't tried this code with CarbonLib or under
- *  Mac OS X at all. The code in unix.c is known to work with Darwin,
- *  and you may or may not be better off using that, especially since
- *  mutexes are no-ops in this file. Patches welcome.
- */
-#ifdef __PHYSFS_CARBONIZED__  /* this is currently not defined anywhere. */
-#include <Carbon.h>
-#else
 #include <OSUtils.h>
 #include <Processes.h>
 #include <Files.h>
@@ -49,12 +45,9 @@
 #include <Events.h>
 #include <DriverGestalt.h>
 #include <Aliases.h>
-#endif
 
-#define __PHYSICSFS_INTERNAL__
 #include "physfs_internal.h"
 
-
 const char *__PHYSFS_platformDirSeparator = ":";
 
 
@@ -960,5 +953,7 @@ void __PHYSFS_platformAllocatorFree(void *ptr)
     free(ptr);
 } /* __PHYSFS_platformAllocatorFree */
 
+#endif  /* PHYSFS_PLATFORM_MACCLASSIC */
+
 /* end of macclassic.c ... */
 

+ 5 - 3
platform/os2.c

@@ -6,7 +6,10 @@
  *  This file written by Ryan C. Gordon.
  */
 
-#if (defined OS2)
+#define __PHYSICSFS_INTERNAL__
+#include "physfs_platforms.h"
+
+#ifdef PHYSFS_PLATFORM_OS2
 
 #define INCL_DOSSEMAPHORES
 #define INCL_DOSDATETIME
@@ -26,7 +29,6 @@
 #include <time.h>
 #include <ctype.h>
 
-#define __PHYSICSFS_INTERNAL__
 #include "physfs_internal.h"
 
 const char *__PHYSFS_platformDirSeparator = "\\";
@@ -773,7 +775,7 @@ void __PHYSFS_platformAllocatorFree(void *ptr)
     free(ptr);
 } /* __PHYSFS_platformAllocatorFree */
 
-#endif  /* defined OS2 */
+#endif  /* PHYSFS_PLATFORM_OS2 */
 
 /* end of os2.c ... */
 

+ 7 - 1
platform/pocketpc.c

@@ -6,10 +6,14 @@
  *  This file written by Ryan C. Gordon.
  */
 
+#define __PHYSICSFS_INTERNAL__
+#include "physfs_platforms.h"
+
+#ifdef PHYSFS_PLATFORM_POCKETPC
+
 #include <stdio.h>
 #include <windows.h>
 
-#define __PHYSICSFS_INTERNAL__
 #include "physfs_internal.h"
 
 #define INVALID_FILE_ATTRIBUTES  0xFFFFFFFF
@@ -624,5 +628,7 @@ void __PHYSFS_platformAllocatorFree(void *ptr)
     free(ptr);
 } /* __PHYSFS_platformAllocatorFree */
 
+#endif  /* PHYSFS_PLATFORM_POCKETPC */
+
 /* end of pocketpc.c ... */
 

+ 5 - 3
platform/posix.c

@@ -6,7 +6,10 @@
  *  This file written by Ryan C. Gordon.
  */
 
-#if ((!defined WIN32) && (!defined OS2))
+#define __PHYSICSFS_INTERNAL__
+#include "physfs_platforms.h"
+
+#ifdef PHYSFS_PLATFORM_POSIX
 
 #if (defined __STRICT_ANSI__)
 #define __PHYSFS_DOING_STRICT_ANSI__
@@ -44,7 +47,6 @@
 #include <linux/unistd.h>
 #endif
 
-#define __PHYSICSFS_INTERNAL__
 #include "physfs_internal.h"
 
 
@@ -533,7 +535,7 @@ void __PHYSFS_platformAllocatorFree(void *ptr)
     free(ptr);
 } /* __PHYSFS_platformAllocatorFree */
 
-#endif /* !defined WIN32 */
+#endif  /* PHYSFS_PLATFORM_POSIX */
 
 /* end of posix.c ... */
 

+ 8 - 3
platform/skeleton.c

@@ -6,12 +6,14 @@
  *  This file written by Ryan C. Gordon.
  */
 
-#define __PHYSICSFS_INTERNAL__
-#include "physfs_internal.h"
+#error DO NOT COMPILE THIS. IT IS JUST A SKELETON EXAMPLE FILE.
 
+#define __PHYSICSFS_INTERNAL__
+#include "physfs_platforms.h"
 
-#error DO NOT COMPILE THIS. IT IS JUST A SKELETON EXAMPLE FILE.
+#ifdef PHYSFS_PLATFORM_SKELETON
 
+#include "physfs_internal.h"
 
 const char *__PHYSFS_platformDirSeparator = ":";
 
@@ -265,5 +267,8 @@ void __PHYSFS_platformAllocatorFree(void *ptr)
     free(ptr);
 } /* __PHYSFS_platformAllocatorFree */
 
+#endif  /* PHYSFS_PLATFORM_SKELETON */
+
+
 /* end of skeleton.c ... */
 

+ 14 - 17
platform/unix.c

@@ -6,8 +6,10 @@
  *  This file written by Ryan C. Gordon.
  */
 
-/* BeOS uses beos.cpp and posix.c ... Cygwin and such use windows.c ... */
-#if ((!defined __BEOS__) && (!defined WIN32))
+#define __PHYSICSFS_INTERNAL__
+#include "physfs_platforms.h"
+
+#ifdef PHYSFS_PLATFORM_UNIX
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -23,16 +25,13 @@
 #include <errno.h>
 #include <sys/mount.h>
 
-#ifndef PHYSFS_DARWIN
-#  if defined(__MACH__) && defined(__APPLE__)
-#    define PHYSFS_DARWIN 1
-#    include <CoreFoundation/CoreFoundation.h>
-#    include <CoreServices/CoreServices.h>
-#    include <IOKit/IOKitLib.h>
-#    include <IOKit/storage/IOMedia.h>
-#    include <IOKit/storage/IOCDMedia.h>
-#    include <IOKit/storage/IODVDMedia.h>
-#  endif
+#ifdef PHYSFS_PLATFORM_MACOSX
+#  include <CoreFoundation/CoreFoundation.h>
+#  include <CoreServices/CoreServices.h>
+#  include <IOKit/IOKitLib.h>
+#  include <IOKit/storage/IOMedia.h>
+#  include <IOKit/storage/IOCDMedia.h>
+#  include <IOKit/storage/IODVDMedia.h>
 #endif
 
 #if (!defined PHYSFS_NO_PTHREADS_SUPPORT)
@@ -50,7 +49,6 @@
 #include <mntent.h>
 #endif
 
-#define __PHYSICSFS_INTERNAL__
 #include "physfs_internal.h"
 
 /* Seems to get defined in some system header... */
@@ -81,7 +79,7 @@ void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
 } /* __PHYSFS_platformDetectAvailableCDs */
 
 
-#elif (defined PHYSFS_DARWIN)  /* "Big Nasty." */
+#elif (defined PHYSFS_PLATFORM_MACOSX)  /* "Big Nasty." */
 /*
  * Code based on sample from Apple Developer Connection:
  *  http://developer.apple.com/samplecode/Sample_Code/Devices_and_Hardware/Disks/VolumeToBSDNode/VolumeToBSDNode.c.htm
@@ -332,7 +330,7 @@ void __PHYSFS_platformTimeslice(void)
 } /* __PHYSFS_platformTimeslice */
 
 
-#if PHYSFS_DARWIN
+#if PHYSFS_PLATFORM_MACOSX
 /* 
  * This function is only for OSX. The problem is that Apple's applications
  * can actually be directory structures with the actual executable nested
@@ -552,8 +550,7 @@ void __PHYSFS_platformReleaseMutex(void *mutex)
 
 #endif /* !PHYSFS_NO_PTHREADS_SUPPORT */
 
-
-#endif /* !defined __BEOS__ && !defined WIN32 */
+#endif /* PHYSFS_PLATFORM_UNIX */
 
 /* end of unix.c ... */
 

+ 6 - 3
platform/windows.c

@@ -6,7 +6,10 @@
  *  This file written by Ryan C. Gordon, and made sane by Gregory S. Read.
  */
 
-#ifdef WIN32
+#define __PHYSICSFS_INTERNAL__
+#include "physfs_platforms.h"
+
+#ifdef PHYSFS_PLATFORM_WINDOWS
 
 #include <windows.h>
 #include <stdio.h>
@@ -16,7 +19,6 @@
 #include <ctype.h>
 #include <time.h>
 
-#define __PHYSICSFS_INTERNAL__
 #include "physfs_internal.h"
 
 #if (defined _MSC_VER)
@@ -1141,7 +1143,8 @@ void __PHYSFS_platformAllocatorFree(void *ptr)
     free(ptr);
 } /* __PHYSFS_platformAllocatorFree */
 
-#endif
+#endif  /* PHYSFS_PLATFORM_WINDOWS */
 
 /* end of windows.c ... */
 
+