Skip to content

Commit

Permalink
Now compiles everything whether we need it or not, removing whole fil…
Browse files Browse the repository at this point in the history
…es 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.
  • Loading branch information
icculus committed Mar 11, 2007
1 parent 839f733 commit 69598e4
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 65 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.txt
Expand Up @@ -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
Expand Down
62 changes: 42 additions & 20 deletions CMakeLists.txt
Expand Up @@ -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!
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -158,20 +179,26 @@ 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)

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)
Expand All @@ -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)


Expand Down
38 changes: 38 additions & 0 deletions 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. */

8 changes: 5 additions & 3 deletions platform/beos.cpp
Expand Up @@ -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>
Expand All @@ -24,7 +27,6 @@
#include <errno.h>
#include <unistd.h>

#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"


Expand Down Expand Up @@ -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 ... */

19 changes: 7 additions & 12 deletions platform/macclassic.c
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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 = ":";


Expand Down Expand Up @@ -960,5 +953,7 @@ void __PHYSFS_platformAllocatorFree(void *ptr)
free(ptr);
} /* __PHYSFS_platformAllocatorFree */

#endif /* PHYSFS_PLATFORM_MACCLASSIC */

/* end of macclassic.c ... */

8 changes: 5 additions & 3 deletions platform/os2.c
Expand Up @@ -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
Expand All @@ -26,7 +29,6 @@
#include <time.h>
#include <ctype.h>

#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"

const char *__PHYSFS_platformDirSeparator = "\\";
Expand Down Expand Up @@ -773,7 +775,7 @@ void __PHYSFS_platformAllocatorFree(void *ptr)
free(ptr);
} /* __PHYSFS_platformAllocatorFree */

#endif /* defined OS2 */
#endif /* PHYSFS_PLATFORM_OS2 */

/* end of os2.c ... */

8 changes: 7 additions & 1 deletion platform/pocketpc.c
Expand Up @@ -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
Expand Down Expand Up @@ -624,5 +628,7 @@ void __PHYSFS_platformAllocatorFree(void *ptr)
free(ptr);
} /* __PHYSFS_platformAllocatorFree */

#endif /* PHYSFS_PLATFORM_POCKETPC */

/* end of pocketpc.c ... */

8 changes: 5 additions & 3 deletions platform/posix.c
Expand Up @@ -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__
Expand Down Expand Up @@ -44,7 +47,6 @@
#include <linux/unistd.h>
#endif

#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"


Expand Down Expand Up @@ -533,7 +535,7 @@ void __PHYSFS_platformAllocatorFree(void *ptr)
free(ptr);
} /* __PHYSFS_platformAllocatorFree */

#endif /* !defined WIN32 */
#endif /* PHYSFS_PLATFORM_POSIX */

/* end of posix.c ... */

11 changes: 8 additions & 3 deletions platform/skeleton.c
Expand Up @@ -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 = ":";

Expand Down Expand Up @@ -265,5 +267,8 @@ void __PHYSFS_platformAllocatorFree(void *ptr)
free(ptr);
} /* __PHYSFS_platformAllocatorFree */

#endif /* PHYSFS_PLATFORM_SKELETON */


/* end of skeleton.c ... */

0 comments on commit 69598e4

Please sign in to comment.