From 69598e49ab5ec55e9d96ce99f206aa15bfd559e5 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 11 Mar 2007 22:50:53 +0000 Subject: [PATCH] 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. --- CHANGELOG.txt | 7 +++++ CMakeLists.txt | 62 +++++++++++++++++++++++++++++-------------- physfs_platforms.h | 38 ++++++++++++++++++++++++++ platform/beos.cpp | 8 +++--- platform/macclassic.c | 19 +++++-------- platform/os2.c | 8 +++--- platform/pocketpc.c | 8 +++++- platform/posix.c | 8 +++--- platform/skeleton.c | 11 +++++--- platform/unix.c | 31 ++++++++++------------ platform/windows.c | 9 ++++--- 11 files changed, 144 insertions(+), 65 deletions(-) create mode 100644 physfs_platforms.h diff --git a/CHANGELOG.txt b/CHANGELOG.txt index b8377890..278b2072 100644 --- a/CHANGELOG.txt +++ b/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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1adcee4d..39ec6379 100644 --- a/CMakeLists.txt +++ b/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) diff --git a/physfs_platforms.h b/physfs_platforms.h new file mode 100644 index 00000000..75d2f0a9 --- /dev/null +++ b/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. */ + diff --git a/platform/beos.cpp b/platform/beos.cpp index 6a29fcbd..c0ec4b17 100644 --- a/platform/beos.cpp +++ b/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 #include @@ -24,7 +27,6 @@ #include #include -#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 ... */ diff --git a/platform/macclassic.c b/platform/macclassic.c index 4d1829ba..d083e376 100644 --- a/platform/macclassic.c +++ b/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 #include #include @@ -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 -#else #include #include #include @@ -49,12 +45,9 @@ #include #include #include -#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 ... */ diff --git a/platform/os2.c b/platform/os2.c index a2af5ffc..f4184c67 100644 --- a/platform/os2.c +++ b/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 #include -#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 ... */ diff --git a/platform/pocketpc.c b/platform/pocketpc.c index 29469c57..7aa68135 100644 --- a/platform/pocketpc.c +++ b/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 #include -#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 ... */ diff --git a/platform/posix.c b/platform/posix.c index 9123f803..ea7cd5e4 100644 --- a/platform/posix.c +++ b/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 #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 ... */ diff --git a/platform/skeleton.c b/platform/skeleton.c index ec0472bb..57210ea1 100644 --- a/platform/skeleton.c +++ b/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 ... */ diff --git a/platform/unix.c b/platform/unix.c index 1ea52840..5a5630d5 100644 --- a/platform/unix.c +++ b/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 #include @@ -23,16 +25,13 @@ #include #include -#ifndef PHYSFS_DARWIN -# if defined(__MACH__) && defined(__APPLE__) -# define PHYSFS_DARWIN 1 -# include -# include -# include -# include -# include -# include -# endif +#ifdef PHYSFS_PLATFORM_MACOSX +# include +# include +# include +# include +# include +# include #endif #if (!defined PHYSFS_NO_PTHREADS_SUPPORT) @@ -50,7 +49,6 @@ #include #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 ... */ diff --git a/platform/windows.c b/platform/windows.c index 312cb5cd..01a4a1e9 100644 --- a/platform/windows.c +++ b/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 #include @@ -16,7 +19,6 @@ #include #include -#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 ... */ +