CMakeLists.txt
changeset 798 18455baab480
child 799 7012c0e130d0
equal deleted inserted replaced
797:c575b78bf2fe 798:18455baab480
       
     1 # PhysicsFS; a portable, flexible file i/o abstraction.
       
     2 # Copyright (C) 2007  Ryan C. Gordon.
       
     3 #
       
     4 # Please see the file LICENSE in the source's root directory.
       
     5 
       
     6 PROJECT(PhysicsFS)
       
     7 SET(PHYSFS_VERSION 1.1.2)
       
     8 
       
     9 # I hate that they define "WIN32" ... we're about to move to Win64...I hope!
       
    10 IF(WIN32 AND NOT WINDOWS)
       
    11     SET(WINDOWS TRUE)
       
    12 ENDIF(WIN32 AND NOT WINDOWS)
       
    13 
       
    14 # Bleh, let's do it for "APPLE" too.
       
    15 IF(APPLE AND NOT MACOSX)
       
    16     SET(MACOSX TRUE)
       
    17 ENDIF(APPLE AND NOT MACOSX)
       
    18 
       
    19 INCLUDE(CheckIncludeFile)
       
    20 INCLUDE(CheckLibraryExists)
       
    21 INCLUDE(CheckCSourceCompiles)
       
    22 
       
    23 INCLUDE_DIRECTORIES(.)
       
    24 #INCLUDE_DIRECTORIES(platform)
       
    25 #INCLUDE_DIRECTORIES(archivers)
       
    26 
       
    27 # Fallback to older Mac OS X on PowerPC to support a wider range of systems...
       
    28 IF(MACOSX)
       
    29     IF(CMAKE_OSX_ARCHITECTURES MATCHES ppc)
       
    30         ADD_DEFINITIONS(-DMAC_OS_X_VERSION_MIN_REQUIRED=1020 -fno-common)
       
    31         SET(OTHER_LDFLAGS ${OTHER_LDFLAGS} "-mmacosx-version-min=10.2 -framework Carbon -framework IOKit")
       
    32     ENDIF(CMAKE_OSX_ARCHITECTURES MATCHES ppc)
       
    33 ENDIF(MACOSX)
       
    34 
       
    35 # Add some gcc-specific command lines.
       
    36 IF(CMAKE_COMPILER_IS_GNUCC)
       
    37     # Always build with debug symbols...you can strip it later.
       
    38     ADD_DEFINITIONS(-g -pipe -Wall -Werror -fsigned-char)
       
    39 
       
    40     CHECK_C_SOURCE_COMPILES("
       
    41         #if ((defined(__GNUC__)) && (__GNUC__ >= 4))
       
    42         int main(int argc, char **argv) { int is_gcc4 = 1; return 0; }
       
    43         #else
       
    44         #error This is not gcc4.
       
    45         #endif
       
    46     " PHYSFS_IS_GCC4)
       
    47 
       
    48     IF(PHYSFS_IS_GCC4)
       
    49         ADD_DEFINITIONS(-fvisibility=hidden)
       
    50     ENDIF(PHYSFS_IS_GCC4)
       
    51 ENDIF(CMAKE_COMPILER_IS_GNUCC)
       
    52 
       
    53 
       
    54 # Basic chunks of source code ...
       
    55 
       
    56 SET(ZLIB_SRCS
       
    57     zlib123/adler32.c
       
    58     zlib123/compress.c
       
    59     zlib123/crc32.c
       
    60     zlib123/deflate.c
       
    61     zlib123/gzio.c
       
    62     zlib123/infback.c
       
    63     zlib123/inffast.c
       
    64     zlib123/inflate.c
       
    65     zlib123/inftrees.c
       
    66     zlib123/trees.c
       
    67     zlib123/uncompr.c
       
    68     zlib123/zutil.c
       
    69 )
       
    70 
       
    71 SET(LZMA_SRCS
       
    72     lzma/7zBuffer.c
       
    73     lzma/7zCrc.c
       
    74     lzma/7zDecode.c
       
    75     lzma/7zExtract.c
       
    76     lzma/7zHeader.c
       
    77     lzma/7zIn.c
       
    78     lzma/7zItem.c
       
    79     lzma/7zMethodID.c
       
    80     lzma/LzmaDecode.c
       
    81     lzma/LzmaStateDecode.c
       
    82 )
       
    83 
       
    84 SET(PHYSFS_SRCS
       
    85     physfs.c
       
    86     physfs_byteorder.c
       
    87     physfs_unicode.c
       
    88     archivers/dir.c
       
    89 )
       
    90 
       
    91 
       
    92 # platform layers ...
       
    93 
       
    94 IF(UNIX)
       
    95     SET(PHYSFS_SRCS ${PHYSFS_SRCS} platform/posix.c)
       
    96     IF(BEOS)
       
    97         SET(PHYSFS_SRCS ${PHYSFS_SRCS} platform/beos.cpp)
       
    98         SET(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
       
    99     ELSE(BEOS)
       
   100         SET(PHYSFS_SRCS ${PHYSFS_SRCS} platform/unix.c)
       
   101         # !!! FIXME
       
   102         #  AC_DEFINE([PHYSFS_HAVE_LLSEEK], 1, [define if we have llseek])
       
   103         CHECK_INCLUDE_FILE(sys/ucred.h HAVE_UCRED_H)
       
   104         IF(HAVE_UCRED_H)
       
   105             ADD_DEFINITIONS(-DPHYSFS_HAVE_SYS_UCRED_H=1)
       
   106             SET(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
       
   107         ENDIF(HAVE_UCRED_H)
       
   108 
       
   109         CHECK_INCLUDE_FILE(mntent.h HAVE_MNTENT_H)
       
   110         IF(HAVE_MNTENT_H)
       
   111             ADD_DEFINITIONS(-DPHYSFS_HAVE_MNTENT_H=1)
       
   112             SET(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
       
   113         ENDIF(HAVE_MNTENT_H)
       
   114     ENDIF(BEOS)
       
   115 
       
   116     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
       
   117     IF(HAVE_PTHREAD_H)
       
   118         SET(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
       
   119     ELSE(HAVE_PTHREAD_H)
       
   120         ADD_DEFINITIONS(-DPHYSFS_NO_PTHREADS_SUPPORT=1)
       
   121     ENDIF(HAVE_PTHREAD_H)
       
   122 ENDIF(UNIX)
       
   123 
       
   124 IF(WINDOWS)
       
   125     SET(PHYSFS_SRCS ${PHYSFS_SRCS} platform/windows.c)
       
   126     SET(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
       
   127     SET(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
       
   128     # !!! FIXME: platform/pocketpc.c ... ?
       
   129 ENDIF(WINDOWS)
       
   130 
       
   131 IF(NOT PHYSFS_HAVE_CDROM_SUPPORT)
       
   132     ADD_DEFINITIONS(-DPHYSFS_NO_CDROM_SUPPORT=1)
       
   133     MESSAGE(WARNING " ***")
       
   134     MESSAGE(WARNING " *** There is no CD-ROM support in this build!")
       
   135     MESSAGE(WARNING " *** PhysicsFS will just pretend there are no discs.")
       
   136     MESSAGE(WARNING " *** This may be fine, depending on how PhysicsFS is used,")
       
   137     MESSAGE(WARNING " ***   but is this what you REALLY wanted?")
       
   138     MESSAGE(WARNING " *** (Maybe fix CMakeLists.txt, or write a platform driver?)")
       
   139     MESSAGE(WARNING " ***")
       
   140 ENDIF(NOT PHYSFS_HAVE_CDROM_SUPPORT)
       
   141 
       
   142 IF(PHYSFS_HAVE_THREAD_SUPPORT)
       
   143     ADD_DEFINITIONS(-D_REENTRANT -D_THREAD_SAFE)
       
   144 ELSE(PHYSFS_HAVE_THREAD_SUPPORT)
       
   145     MESSAGE(WARNING " ***")
       
   146     MESSAGE(WARNING " *** There is no thread support in this build!")
       
   147     MESSAGE(WARNING " *** PhysicsFS will NOT be reentrant!")
       
   148     MESSAGE(WARNING " *** This may be fine, depending on how PhysicsFS is used,")
       
   149     MESSAGE(WARNING " ***   but is this what you REALLY wanted?")
       
   150     MESSAGE(WARNING " *** (Maybe fix CMakeLists.txt, or write a platform driver?)")
       
   151     MESSAGE(WARNING " ***")
       
   152 ENDIF(PHYSFS_HAVE_THREAD_SUPPORT)
       
   153 
       
   154 # Archivers ...
       
   155 
       
   156 OPTION(PHYSFS_ARCHIVE_ZIP "Enable ZIP support" TRUE)
       
   157 IF(PHYSFS_ARCHIVE_ZIP)
       
   158     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_ZIP=1)
       
   159     SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/zip.c)
       
   160     SET(PHYSFS_NEED_ZLIB TRUE)
       
   161 ENDIF(PHYSFS_ARCHIVE_ZIP)
       
   162 
       
   163 OPTION(PHYSFS_ARCHIVE_7Z "Enable 7zip support" TRUE)
       
   164 IF(PHYSFS_ARCHIVE_7Z)
       
   165     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_7Z=1)
       
   166     # !!! FIXME: rename to 7z.c?
       
   167     SET(PHYSFS_SRCS ${PHYSFS_SRCS} ${LZMA_SRCS} archivers/lzma.c)
       
   168     INCLUDE_DIRECTORIES(lzma)
       
   169     ADD_DEFINITIONS(-D_LZMA_IN_CB=1)
       
   170     ADD_DEFINITIONS(-D_LZMA_PROB32=1)
       
   171     ADD_DEFINITIONS(-D_LZMA_SYSTEM_SIZE_T=1)
       
   172     ADD_DEFINITIONS(-D_SZ_ONE_DIRECTORY=1)
       
   173 ENDIF(PHYSFS_ARCHIVE_7Z)
       
   174 
       
   175 OPTION(PHYSFS_ARCHIVE_GRP "Enable Build Engine GRP support" TRUE)
       
   176 IF(PHYSFS_ARCHIVE_GRP)
       
   177     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_GRP=1)
       
   178     SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/grp.c)
       
   179 ENDIF(PHYSFS_ARCHIVE_GRP)
       
   180 
       
   181 OPTION(PHYSFS_ARCHIVE_WAD "Enable Doom WAD support" TRUE)
       
   182 IF(PHYSFS_ARCHIVE_WAD)
       
   183     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_WAD=1)
       
   184     SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/wad.c)
       
   185 ENDIF(PHYSFS_ARCHIVE_WAD)
       
   186 
       
   187 OPTION(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
       
   188 IF(PHYSFS_ARCHIVE_HOG)
       
   189     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_HOG=1)
       
   190     SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/hog.c)
       
   191 ENDIF(PHYSFS_ARCHIVE_HOG)
       
   192 
       
   193 OPTION(PHYSFS_ARCHIVE_MVL "Enable Descent I/II MVL support" TRUE)
       
   194 IF(PHYSFS_ARCHIVE_MVL)
       
   195     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_MVL=1)
       
   196     SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/mvl.c)
       
   197 ENDIF(PHYSFS_ARCHIVE_MVL)
       
   198 
       
   199 OPTION(PHYSFS_ARCHIVE_QPAK "Enable Quake I/II QPAK support" TRUE)
       
   200 IF(PHYSFS_ARCHIVE_QPAK)
       
   201     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_QPAK=1)
       
   202     SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/qpak.c)
       
   203 ENDIF(PHYSFS_ARCHIVE_QPAK)
       
   204 
       
   205 OPTION(PHYSFS_ARCHIVE_MIX "Enable Westwood MIX support" FALSE)
       
   206 IF(PHYSFS_ARCHIVE_MIX)
       
   207     ADD_DEFINITIONS(-DPHYSFS_SUPPORTS_MIX=1)
       
   208     SET(PHYSFS_SRCS ${PHYSFS_SRCS} archivers/mix.c)
       
   209 ENDIF(PHYSFS_ARCHIVE_MIX)
       
   210 
       
   211 
       
   212 # See if some archiver required zlib, and see about using system version.
       
   213 
       
   214 IF(PHYSFS_NEED_ZLIB)
       
   215     CHECK_INCLUDE_FILE(zlib.h HAVE_ZLIB_H)
       
   216     IF(HAVE_ZLIB_H)
       
   217         CHECK_LIBRARY_EXISTS("z" "inflate" "" HAVE_LIBZ)
       
   218         IF(HAVE_LIBZ)
       
   219             SET(HAVE_SYSTEM_ZLIB TRUE)
       
   220         ENDIF(HAVE_LIBZ)
       
   221     ENDIF(HAVE_ZLIB_H)
       
   222 
       
   223     IF(HAVE_SYSTEM_ZLIB)
       
   224         OPTION(PHYSFS_INTERNAL_ZLIB "Link own zlib instead of system library" FALSE)
       
   225     ELSE(HAVE_SYSTEM_ZLIB)
       
   226         SET(PHYSFS_INTERNAL_ZLIB TRUE)
       
   227     ENDIF(HAVE_SYSTEM_ZLIB)
       
   228 
       
   229     IF(PHYSFS_INTERNAL_ZLIB)
       
   230         INCLUDE_DIRECTORIES(zlib123)
       
   231         ADD_DEFINITIONS(-DZ_PREFIX=1)
       
   232         SET(PHYSFS_SRCS ${PHYSFS_SRCS} ${ZLIB_SRCS})
       
   233     ELSE(PHYSFS_INTERNAL_ZLIB)
       
   234         SET(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} z)
       
   235     ENDIF(PHYSFS_INTERNAL_ZLIB)
       
   236 ENDIF(PHYSFS_NEED_ZLIB)
       
   237 
       
   238 
       
   239 
       
   240 ADD_LIBRARY(physfs SHARED ${PHYSFS_SRCS})
       
   241 TARGET_LINK_LIBRARIES(physfs ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
       
   242 
       
   243 OPTION(PHYSFS_BUILD_TEST "Build test program." TRUE)
       
   244 MARK_AS_ADVANCED(PHYSFS_BUILD_TEST)
       
   245 IF(PHYSFS_BUILD_TEST)
       
   246     CHECK_INCLUDE_FILE(readline/readline.h HAVE_READLINE_H)
       
   247     CHECK_INCLUDE_FILE(readline/history.h HAVE_HISTORY_H)
       
   248     IF(HAVE_READLINE_H AND HAVE_HISTORY_H)
       
   249         SET(CMAKE_REQUIRED_LIBRARIES curses)
       
   250         CHECK_LIBRARY_EXISTS("readline" "readline" "" HAVE_LIBREADLINE)
       
   251         CHECK_LIBRARY_EXISTS("readline" "history" "" HAVE_LIBHISTORY)
       
   252         IF(HAVE_LIBREADLINE AND HAVE_LIBHISTORY)
       
   253             SET(HAVE_SYSTEM_READLINE TRUE)
       
   254             SET(TEST_PHYSFS_LIBS ${TEST_PHYSFS_LIBS} " " readline curses)
       
   255             ADD_DEFINITIONS(-DPHYSFS_HAVE_READLINE=1)
       
   256         ENDIF(HAVE_LIBREADLINE AND HAVE_LIBHISTORY)
       
   257     ENDIF(HAVE_READLINE_H AND HAVE_HISTORY_H)
       
   258     ADD_EXECUTABLE(test_physfs test/test_physfs.c)
       
   259     TARGET_LINK_LIBRARIES(test_physfs physfs ${TEST_PHYSFS_LIBS} ${OTHER_LDFLAGS})
       
   260 ENDIF(PHYSFS_BUILD_TEST)
       
   261 
       
   262 FIND_PACKAGE(Doxygen)
       
   263 IF(DOXYGEN_FOUND)
       
   264     ADD_CUSTOM_TARGET(docs ${DOXYGEN_EXECUTABLE} COMMENT "Building documentation")
       
   265 ELSE(DOXYGEN_FOUND)
       
   266     MESSAGE(STATUS "Doxygen not found. You won't be able to build documentation.")
       
   267 ENDIF(DOXYGEN_FOUND)
       
   268 
       
   269 
       
   270 MACRO(MESSAGE_BOOL_OPTION _NAME _VALUE)
       
   271     IF(${_VALUE})
       
   272         MESSAGE(STATUS "  ${_NAME}: enabled")
       
   273     ELSE(${_VALUE})
       
   274         MESSAGE(STATUS "  ${_NAME}: disabled")
       
   275     ENDIF(${_VALUE})
       
   276 ENDMACRO(MESSAGE_BOOL_OPTION)
       
   277 
       
   278 MESSAGE(STATUS "PhysicsFS will build with the following options:")
       
   279 MESSAGE_BOOL_OPTION("ZIP support" PHYSFS_ARCHIVE_ZIP)
       
   280 MESSAGE_BOOL_OPTION("7zip support" PHYSFS_ARCHIVE_7Z)
       
   281 MESSAGE_BOOL_OPTION("GRP support" PHYSFS_ARCHIVE_GRP)
       
   282 MESSAGE_BOOL_OPTION("WAD support" PHYSFS_ARCHIVE_WAD)
       
   283 MESSAGE_BOOL_OPTION("HOG support" PHYSFS_ARCHIVE_HOG)
       
   284 MESSAGE_BOOL_OPTION("MVL support" PHYSFS_ARCHIVE_MVL)
       
   285 MESSAGE_BOOL_OPTION("QPAK support" PHYSFS_ARCHIVE_QPAK)
       
   286 MESSAGE_BOOL_OPTION("MIX support" PHYSFS_ARCHIVE_MIX)
       
   287 MESSAGE_BOOL_OPTION("CD-ROM drive support" PHYSFS_HAVE_CDROM_SUPPORT)
       
   288 MESSAGE_BOOL_OPTION("Thread safety" PHYSFS_HAVE_THREAD_SUPPORT)
       
   289 MESSAGE_BOOL_OPTION("Build own zlib" PHYSFS_INTERNAL_ZLIB)
       
   290 MESSAGE_BOOL_OPTION("Build test program" PHYSFS_BUILD_TEST)
       
   291 IF(PHYSFS_BUILD_TEST)
       
   292     MESSAGE_BOOL_OPTION("  Use readline in test program" HAVE_SYSTEM_READLINE)
       
   293 ENDIF(PHYSFS_BUILD_TEST)
       
   294 
       
   295 # end of CMakeLists.txt ...
       
   296