misc/physfs/CMakeLists.txt
branchwebgl
changeset 8833 c13ebed437cb
parent 8450 404ddce27b23
parent 8830 343d3f0d6a86
child 8836 7a474fcc343d
equal deleted inserted replaced
8450:404ddce27b23 8833:c13ebed437cb
     1 # PhysicsFS; a portable, flexible file i/o abstraction.
       
     2 # Copyright (C) 2007  Ryan C. Gordon.
       
     3 #
       
     4 # Please see the file LICENSE.txt in the source's root directory.
       
     5 
       
     6 ## lines starting with '##' are lines overridden/modified/added by Hedgewars configuration
       
     7 ##CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
       
     8 ##PROJECT(PhysicsFS)
       
     9 set(PHYSFS_VERSION 2.1.0)
       
    10 
       
    11 # Increment this if/when we break backwards compatibility.
       
    12 set(PHYSFS_SOVERSION 1)
       
    13 
       
    14 # I hate that they define "WIN32" ... we're about to move to Win64...I hope!
       
    15 if(WIN32 AND NOT WINDOWS)
       
    16     set(WINDOWS TRUE)
       
    17 endif(WIN32 AND NOT WINDOWS)
       
    18 
       
    19 # Bleh, let's do it for "APPLE" too.
       
    20 if(APPLE AND NOT MACOSX)
       
    21     set(MACOSX TRUE)
       
    22 endif(APPLE AND NOT MACOSX)
       
    23 
       
    24 # For now, Haiku and BeOS are the same, as far as the build system cares.
       
    25 if(HAIKU AND NOT BEOS)
       
    26     set(BEOS TRUE)
       
    27 endif(HAIKU AND NOT BEOS)
       
    28 
       
    29 if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
       
    30     set(SOLARIS TRUE)
       
    31 endif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
       
    32 
       
    33 include(CheckIncludeFile)
       
    34 include(CheckLibraryExists)
       
    35 include(CheckCSourceCompiles)
       
    36 
       
    37 ## SDL is needed by extra
       
    38 find_package(SDL REQUIRED)
       
    39 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) ##
       
    40 include_directories(${SDL_INCLUDE_DIR}) ##
       
    41 include_directories(${LUA_INCLUDE_DIR}) ##
       
    42 
       
    43 if(MACOSX)
       
    44     # Fallback to older OS X on PowerPC to support wider range of systems...
       
    45     if(CMAKE_OSX_ARCHITECTURES MATCHES ppc)
       
    46         add_definitions(-DMAC_OS_X_VERSION_MIN_REQUIRED=1020)
       
    47         set(OTHER_LDFLAGS ${OTHER_LDFLAGS} " -mmacosx-version-min=10.2")
       
    48     endif(CMAKE_OSX_ARCHITECTURES MATCHES ppc)
       
    49 
       
    50     # Need these everywhere...
       
    51     add_definitions(-fno-common)
       
    52     find_library(iokit_framework NAMES IOKit)
       
    53     list(APPEND OTHER_LDFLAGS ${iokit_framework})
       
    54 endif(MACOSX)
       
    55 
       
    56 # Add some gcc-specific command lines.
       
    57 if(CMAKE_COMPILER_IS_GNUCC)
       
    58     # Always build with debug symbols...you can strip it later.
       
    59     add_definitions(-g -pipe -Werror -fsigned-char)
       
    60 
       
    61     # Stupid BeOS generates warnings in the system headers.
       
    62     if(NOT BEOS)
       
    63         add_definitions(-Wall)
       
    64     endif(NOT BEOS)
       
    65 
       
    66     CHECK_C_SOURCE_COMPILES("
       
    67         #if ((defined(__GNUC__)) && (__GNUC__ >= 4))
       
    68         int main(int argc, char **argv) { int is_gcc4 = 1; return 0; }
       
    69         #else
       
    70         #error This is not gcc4.
       
    71         #endif
       
    72     " PHYSFS_IS_GCC4)
       
    73 
       
    74     if(PHYSFS_IS_GCC4)
       
    75         # Not supported on several operating systems at this time.
       
    76         if(NOT SOLARIS AND NOT WINDOWS)
       
    77             add_definitions(-fvisibility=hidden)
       
    78         endif(NOT SOLARIS AND NOT WINDOWS)
       
    79     endif(PHYSFS_IS_GCC4)
       
    80 
       
    81     # Don't use -rpath.
       
    82     set(CMAKE_SKIP_RPATH ON CACHE BOOL "Skip RPATH" FORCE)
       
    83 endif(CMAKE_COMPILER_IS_GNUCC)
       
    84 
       
    85 if(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
       
    86     add_definitions(-erroff=E_EMPTY_TRANSLATION_UNIT)
       
    87     add_definitions(-xldscope=hidden)
       
    88 endif(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
       
    89 
       
    90 if(MSVC)
       
    91     # VS.NET 8.0 got really really anal about strcpy, etc, which even if we
       
    92     #  cleaned up our code, zlib, etc still use...so disable the warning.
       
    93     add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
       
    94 endif(MSVC)
       
    95 
       
    96 
       
    97 # Basic chunks of source code ...
       
    98 set(LZMA_SRCS
       
    99     src/lzma/C/7zCrc.c
       
   100     src/lzma/C/Archive/7z/7zBuffer.c
       
   101     src/lzma/C/Archive/7z/7zDecode.c
       
   102     src/lzma/C/Archive/7z/7zExtract.c
       
   103     src/lzma/C/Archive/7z/7zHeader.c
       
   104     src/lzma/C/Archive/7z/7zIn.c
       
   105     src/lzma/C/Archive/7z/7zItem.c
       
   106     src/lzma/C/Archive/7z/7zMethodID.c
       
   107     src/lzma/C/Compress/Branch/BranchX86.c
       
   108     src/lzma/C/Compress/Branch/BranchX86_2.c
       
   109     src/lzma/C/Compress/Lzma/LzmaDecode.c
       
   110 )
       
   111 
       
   112 if(BEOS)
       
   113     # We add this explicitly, since we don't want CMake to think this
       
   114     #  is a C++ project unless we're on BeOS.
       
   115     set(PHYSFS_BEOS_SRCS src/platform_beos.cpp)
       
   116     find_library(BE_LIBRARY be)
       
   117     find_library(ROOT_LIBRARY root)
       
   118     set(optionAL_LIBRARY_LIBS ${optionAL_LIBRARY_LIBS} ${BE_LIBRARY} ${ROOT_LIBRARY})
       
   119 endif(BEOS)
       
   120 
       
   121 ## extra functions needed by Hedgewars
       
   122 ## TODO: maybe it's better to have them in a separate library?
       
   123 set(PHYSFS_HEDGE_SRCS
       
   124     extras/physfsrwops.c
       
   125     extras/physfslualoader.c
       
   126     extras/hwpacksmounter.c
       
   127 )
       
   128 
       
   129 # Almost everything is "compiled" here, but things that don't apply to the
       
   130 #  build are #ifdef'd out. This is to make it easy to embed PhysicsFS into
       
   131 #  another project or bring up a new build system: just compile all the source
       
   132 #  code and #define the things you want.
       
   133 set(PHYSFS_SRCS
       
   134     src/physfs.c
       
   135     src/physfs_byteorder.c
       
   136     src/physfs_unicode.c
       
   137     src/platform_posix.c
       
   138     src/platform_unix.c
       
   139     src/platform_macosx.c
       
   140     src/platform_windows.c
       
   141     src/archiver_dir.c
       
   142     src/archiver_unpacked.c
       
   143     src/archiver_grp.c
       
   144     src/archiver_hog.c
       
   145     src/archiver_lzma.c
       
   146     src/archiver_mvl.c
       
   147     src/archiver_qpak.c
       
   148     src/archiver_wad.c
       
   149     src/archiver_zip.c
       
   150     src/archiver_iso9660.c
       
   151     ${PHYSFS_BEOS_SRCS}
       
   152     ${PHYSFS_HEDGE_SRCS} ##
       
   153 )
       
   154 
       
   155 
       
   156 # platform layers ...
       
   157 
       
   158 if(UNIX)
       
   159     if(BEOS)
       
   160         set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
       
   161         set(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
       
   162         set(HAVE_PTHREAD_H TRUE)
       
   163     else(BEOS)
       
   164         CHECK_INCLUDE_FILE(sys/ucred.h HAVE_UCRED_H)
       
   165         if(HAVE_UCRED_H)
       
   166             add_definitions(-DPHYSFS_HAVE_SYS_UCRED_H=1)
       
   167             set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
       
   168         endif(HAVE_UCRED_H)
       
   169 
       
   170         CHECK_INCLUDE_FILE(mntent.h HAVE_MNTENT_H)
       
   171         if(HAVE_MNTENT_H)
       
   172             add_definitions(-DPHYSFS_HAVE_MNTENT_H=1)
       
   173             set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
       
   174         endif(HAVE_MNTENT_H)
       
   175 
       
   176         # !!! FIXME: Solaris fails this, because mnttab.h implicitly
       
   177         # !!! FIXME:  depends on other system headers.  :(
       
   178         #CHECK_INCLUDE_FILE(sys/mnttab.h HAVE_SYS_MNTTAB_H)
       
   179         CHECK_C_SOURCE_COMPILES("
       
   180             #include <stdio.h>
       
   181             #include <sys/mnttab.h>
       
   182             int main(int argc, char **argv) { return 0; }
       
   183         " HAVE_SYS_MNTTAB_H)
       
   184 
       
   185         if(HAVE_SYS_MNTTAB_H)
       
   186             add_definitions(-DPHYSFS_HAVE_SYS_MNTTAB_H=1)
       
   187             set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
       
   188         endif(HAVE_SYS_MNTTAB_H)
       
   189 
       
   190         CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
       
   191         if(HAVE_PTHREAD_H)
       
   192             set(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
       
   193         endif(HAVE_PTHREAD_H)
       
   194     endif(BEOS)
       
   195 endif(UNIX)
       
   196 
       
   197 if(WINDOWS)
       
   198     set(PHYSFS_HAVE_CDROM_SUPPORT TRUE)
       
   199     set(PHYSFS_HAVE_THREAD_SUPPORT TRUE)
       
   200 endif(WINDOWS)
       
   201 
       
   202 if(NOT PHYSFS_HAVE_CDROM_SUPPORT)
       
   203     add_definitions(-DPHYSFS_NO_CDROM_SUPPORT=1)
       
   204     message(WARNING " ***")
       
   205     message(WARNING " *** There is no CD-ROM support in this build!")
       
   206     message(WARNING " *** PhysicsFS will just pretend there are no discs.")
       
   207     message(WARNING " *** This may be fine, depending on how PhysicsFS is used,")
       
   208     message(WARNING " ***   but is this what you REALLY wanted?")
       
   209     message(WARNING " *** (Maybe fix CMakeLists.txt, or write a platform driver?)")
       
   210     message(WARNING " ***")
       
   211 endif(NOT PHYSFS_HAVE_CDROM_SUPPORT)
       
   212 
       
   213 if(PHYSFS_HAVE_THREAD_SUPPORT)
       
   214     add_definitions(-D_REENTRANT -D_THREAD_SAFE)
       
   215 else(PHYSFS_HAVE_THREAD_SUPPORT)
       
   216     add_definitions(-DPHYSFS_NO_THREAD_SUPPORT=1)
       
   217     message(WARNING " ***")
       
   218     message(WARNING " *** There is no thread support in this build!")
       
   219     message(WARNING " *** PhysicsFS will NOT be reentrant!")
       
   220     message(WARNING " *** This may be fine, depending on how PhysicsFS is used,")
       
   221     message(WARNING " ***   but is this what you REALLY wanted?")
       
   222     message(WARNING " *** (Maybe fix CMakeLists.txt, or write a platform driver?)")
       
   223     message(WARNING " ***")
       
   224 endif(PHYSFS_HAVE_THREAD_SUPPORT)
       
   225 
       
   226 
       
   227 # Archivers ...
       
   228 
       
   229 option(PHYSFS_ARCHIVE_ZIP "Enable ZIP support" TRUE)
       
   230 if(PHYSFS_ARCHIVE_ZIP)
       
   231     add_definitions(-DPHYSFS_SUPPORTS_ZIP=1)
       
   232     set(PHYSFS_FEATURES "ZIP")
       
   233 endif(PHYSFS_ARCHIVE_ZIP)
       
   234 
       
   235 option(PHYSFS_ARCHIVE_7Z "Enable 7zip support" FALSE)
       
   236 if(PHYSFS_ARCHIVE_7Z)
       
   237     add_definitions(-DPHYSFS_SUPPORTS_7Z=1)
       
   238     list(APPEND PHYSFS_SRCS ${LZMA_SRCS})
       
   239     set(PHYSFS_FEATURES "${PHYSFS_FEATURES} 7zip")
       
   240 endif(PHYSFS_ARCHIVE_7Z)
       
   241 
       
   242 option(PHYSFS_ARCHIVE_GRP "Enable Build Engine GRP support" TRUE)
       
   243 if(PHYSFS_ARCHIVE_GRP)
       
   244     add_definitions(-DPHYSFS_SUPPORTS_GRP=1)
       
   245     set(PHYSFS_FEATURES "${PHYSFS_FEATURES} GRP")
       
   246 endif(PHYSFS_ARCHIVE_GRP)
       
   247 
       
   248 option(PHYSFS_ARCHIVE_WAD "Enable Doom WAD support" TRUE)
       
   249 if(PHYSFS_ARCHIVE_WAD)
       
   250     add_definitions(-DPHYSFS_SUPPORTS_WAD=1)
       
   251     set(PHYSFS_FEATURES "${PHYSFS_FEATURES} WAD")
       
   252 endif(PHYSFS_ARCHIVE_WAD)
       
   253 
       
   254 option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
       
   255 if(PHYSFS_ARCHIVE_HOG)
       
   256     add_definitions(-DPHYSFS_SUPPORTS_HOG=1)
       
   257     set(PHYSFS_FEATURES "${PHYSFS_FEATURES} HOG")
       
   258 endif(PHYSFS_ARCHIVE_HOG)
       
   259 
       
   260 option(PHYSFS_ARCHIVE_MVL "Enable Descent I/II MVL support" TRUE)
       
   261 if(PHYSFS_ARCHIVE_MVL)
       
   262     add_definitions(-DPHYSFS_SUPPORTS_MVL=1)
       
   263     set(PHYSFS_FEATURES "${PHYSFS_FEATURES} MVL")
       
   264 endif(PHYSFS_ARCHIVE_MVL)
       
   265 
       
   266 option(PHYSFS_ARCHIVE_QPAK "Enable Quake I/II QPAK support" TRUE)
       
   267 if(PHYSFS_ARCHIVE_QPAK)
       
   268     add_definitions(-DPHYSFS_SUPPORTS_QPAK=1)
       
   269     set(PHYSFS_FEATURES "${PHYSFS_FEATURES} QPAK")
       
   270 endif(PHYSFS_ARCHIVE_QPAK)
       
   271 
       
   272 option(PHYSFS_ARCHIVE_ISO9660 "Enable ISO9660 support" TRUE)
       
   273 if(PHYSFS_ARCHIVE_ISO9660)
       
   274     add_definitions(-DPHYSFS_SUPPORTS_ISO9660=1)
       
   275     set(PHYSFS_FEATURES "${PHYSFS_FEATURES} CD-ROM")
       
   276 endif(PHYSFS_ARCHIVE_ISO9660)
       
   277 
       
   278 ##as needed by Hedgewars configuration
       
   279 if(WINDOWS)
       
   280     option(PHYSFS_BUILD_STATIC "Build static library" FALSE)
       
   281     option(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
       
   282     list(APPEND OTHER_LDFLAGS ${SDL_LIBRARY})
       
   283 else(WINDOWS)
       
   284     option(PHYSFS_BUILD_STATIC "Build static library" TRUE)
       
   285     option(PHYSFS_BUILD_SHARED "Build shared library" FALSE)
       
   286 endif(WINDOWS)
       
   287 
       
   288 if(PHYSFS_BUILD_STATIC)
       
   289     add_library(physfs STATIC ${PHYSFS_SRCS})
       
   290     set_target_properties(physfs PROPERTIES OUTPUT_NAME "physfs")
       
   291 endif(PHYSFS_BUILD_STATIC)
       
   292 
       
   293 if(PHYSFS_BUILD_SHARED)
       
   294     add_library(physfs SHARED ${PHYSFS_SRCS})
       
   295     set_target_properties(physfs PROPERTIES VERSION ${PHYSFS_VERSION})
       
   296     set_target_properties(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION})
       
   297     target_link_libraries(physfs ${optionAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
       
   298     install(TARGETS physfs RUNTIME DESTINATION ${target_library_install_dir}) ##
       
   299 endif(PHYSFS_BUILD_SHARED)
       
   300 
       
   301 if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
       
   302     message(FATAL "Both shared and static libraries are disabled!")
       
   303 endif(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
       
   304 
       
   305 # CMake FAQ says I need this...
       
   306 if(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC)
       
   307     set_target_properties(physfs PROPERTIES CLEAN_DIRECT_OUTPUT 1)
       
   308 endif(PHYSFS_BUILD_SHARED AND PHYSFS_BUILD_STATIC)
       
   309 
       
   310 
       
   311 ## removed install, language bindings and test program
       
   312 ## simplified configuration output
       
   313 
       
   314 message(STATUS "PhysicsFS will build with ${PHYSFS_FEATURES} support")
       
   315