| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- # PhysicsFS; a portable, flexible file i/o abstraction.
- #
- # Please see the file LICENSE.txt in the source's root directory.
- # The CMake project file is meant to get this compiling on all sorts of
- # platforms quickly, and serve as the way Unix platforms and Linux distros
- # package up official builds, but you don't _need_ to use this; we have
- # built PhysicsFS to (hopefully) be able to drop into your project and
- # compile, using preprocessor checks for platform-specific bits instead of
- # testing in here.
- set(PHYSFS_VERSION 3.3.0)
- cmake_minimum_required(VERSION 3.5...4.0)
- project(PhysicsFS VERSION ${PHYSFS_VERSION} LANGUAGES C )
- include(CMakeDependentOption)
- include(GNUInstallDirs)
- include("${PROJECT_SOURCE_DIR}/extras/GetGitRevisionDescription.cmake")
- include("${PROJECT_SOURCE_DIR}/extras/PrivateSdlFunctions.cmake")
- include("${PROJECT_SOURCE_DIR}/extras/sdlmanpages.cmake")
- # Increment this if/when we break backwards compatibility.
- set(PHYSFS_SOVERSION 1)
- set(PHYSFS_M_SRCS)
- set(PHYSFS_CPP_SRCS)
- if(WIN32)
- list(APPEND OPTIONAL_LIBRARY_LIBS advapi32 shell32)
- endif()
- if(APPLE)
- set(OTHER_LDFLAGS ${OTHER_LDFLAGS} "-framework IOKit -framework Foundation")
- list(APPEND PHYSFS_M_SRCS src/physfs_platform_apple.m)
- endif()
- if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
- add_compile_options(-Wall)
- endif()
- if(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
- add_definitions(-erroff=E_EMPTY_TRANSLATION_UNIT)
- add_definitions(-xldscope=hidden)
- endif()
- if(HAIKU)
- # We add this explicitly, since we don't want CMake to think this
- # is a C++ project unless we're on Haiku.
- list(APPEND PHYSFS_CPP_SRCS src/physfs_platform_haiku.cpp)
- find_library(BE_LIBRARY be)
- find_library(ROOT_LIBRARY root)
- list(APPEND OPTIONAL_LIBRARY_LIBS ${BE_LIBRARY} ${ROOT_LIBRARY})
- endif()
- if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" OR CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
- set(WINRT TRUE)
- endif()
- if(WINRT)
- list(APPEND PHYSFS_CPP_SRCS src/physfs_platform_winrt.cpp)
- endif()
- if(UNIX AND NOT WIN32 AND NOT APPLE) # (MingW and such might be UNIX _and_ WINDOWS!)
- find_library(PTHREAD_LIBRARY pthread)
- if(PTHREAD_LIBRARY)
- list(APPEND OPTIONAL_LIBRARY_LIBS ${PTHREAD_LIBRARY})
- endif()
- endif()
- if(PHYSFS_CPP_SRCS)
- enable_language(CXX)
- endif()
- # 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
- src/physfs.c
- src/physfs_byteorder.c
- src/physfs_unicode.c
- src/physfs_platform_posix.c
- src/physfs_platform_unix.c
- src/physfs_platform_windows.c
- src/physfs_platform_ogc.c
- src/physfs_platform_os2.c
- src/physfs_platform_qnx.c
- src/physfs_platform_android.c
- src/physfs_platform_libretro.c
- src/physfs_platform_playdate.c
- src/physfs_archiver_dir.c
- src/physfs_archiver_unpacked.c
- src/physfs_archiver_grp.c
- src/physfs_archiver_hog.c
- src/physfs_archiver_7z.c
- src/physfs_archiver_mvl.c
- src/physfs_archiver_qpak.c
- src/physfs_archiver_wad.c
- src/physfs_archiver_csm.c
- src/physfs_archiver_zip.c
- src/physfs_archiver_slb.c
- src/physfs_archiver_iso9660.c
- src/physfs_archiver_vdf.c
- src/physfs_archiver_lec3d.c
- src/physfs_version.rc
- ${PHYSFS_CPP_SRCS}
- ${PHYSFS_M_SRCS}
- )
- # Archivers ...
- # These are (mostly) on by default now, so these options are only useful for
- # disabling them.
- option(PHYSFS_ARCHIVE_ZIP "Enable ZIP support" TRUE)
- if(NOT PHYSFS_ARCHIVE_ZIP)
- add_definitions(-DPHYSFS_SUPPORTS_ZIP=0)
- endif()
- option(PHYSFS_ARCHIVE_7Z "Enable 7zip support" TRUE)
- if(NOT PHYSFS_ARCHIVE_7Z)
- add_definitions(-DPHYSFS_SUPPORTS_7Z=0)
- endif()
- option(PHYSFS_ARCHIVE_GRP "Enable Build Engine GRP support" TRUE)
- if(NOT PHYSFS_ARCHIVE_GRP)
- add_definitions(-DPHYSFS_SUPPORTS_GRP=0)
- endif()
- option(PHYSFS_ARCHIVE_WAD "Enable Doom WAD support" TRUE)
- if(NOT PHYSFS_ARCHIVE_WAD)
- add_definitions(-DPHYSFS_SUPPORTS_WAD=0)
- endif()
- option(PHYSFS_ARCHIVE_CSM "Enable Chasm: The Rift CSM.BIN support" TRUE)
- if(NOT PHYSFS_ARCHIVE_CSM)
- add_definitions(-DPHYSFS_SUPPORTS_CSM=0)
- endif()
- option(PHYSFS_ARCHIVE_HOG "Enable Descent I/II HOG support" TRUE)
- if(NOT PHYSFS_ARCHIVE_HOG)
- add_definitions(-DPHYSFS_SUPPORTS_HOG=0)
- endif()
- option(PHYSFS_ARCHIVE_MVL "Enable Descent I/II MVL support" TRUE)
- if(NOT PHYSFS_ARCHIVE_MVL)
- add_definitions(-DPHYSFS_SUPPORTS_MVL=0)
- endif()
- option(PHYSFS_ARCHIVE_QPAK "Enable Quake I/II QPAK support" TRUE)
- if(NOT PHYSFS_ARCHIVE_QPAK)
- add_definitions(-DPHYSFS_SUPPORTS_QPAK=0)
- endif()
- option(PHYSFS_ARCHIVE_SLB "Enable I-War / Independence War SLB support" TRUE)
- if(NOT PHYSFS_ARCHIVE_SLB)
- add_definitions(-DPHYSFS_SUPPORTS_SLB=0)
- endif()
- option(PHYSFS_ARCHIVE_ISO9660 "Enable ISO9660 support" TRUE)
- if(NOT PHYSFS_ARCHIVE_ISO9660)
- add_definitions(-DPHYSFS_SUPPORTS_ISO9660=0)
- endif()
- option(PHYSFS_ARCHIVE_VDF "Enable Gothic I/II VDF archive support" TRUE)
- if(NOT PHYSFS_ARCHIVE_VDF)
- add_definitions(-DPHYSFS_SUPPORTS_VDF=0)
- endif()
- option(PHYSFS_ARCHIVE_LECARCHIVES "Enable LucasArts GOB/LAB/LFD Archive support" TRUE)
- if(NOT PHYSFS_ARCHIVE_LECARCHIVES)
- add_definitions(-DPHYSFS_SUPPORTS_LECARCHIVES=0)
- endif()
- option(PHYSFS_BUILD_STATIC "Build static library" TRUE)
- if(PHYSFS_BUILD_STATIC)
- add_library(physfs-static STATIC ${PHYSFS_SRCS})
- add_library(PhysFS::PhysFS-static ALIAS physfs-static)
- set_property(TARGET physfs-static PROPERTY EXPORT_NAME PhysFS-static)
- # Don't rename this on Windows, since DLLs will also produce an import
- # library named "physfs.lib" which would conflict; Unix tend to like the
- # same library name with a different extension for static libs, but
- # Windows can just have a separate name.
- if(NOT MSVC)
- set_property(TARGET physfs-static PROPERTY OUTPUT_NAME "physfs")
- endif()
- if(WINRT)
- # Ignore LNK4264 warnings; we don't author any WinRT components, just consume them, so we're okay in a static library.
- set_property(TARGET physfs-static PROPERTY VS_WINRT_COMPONENT TRUE)
- set_property(TARGET physfs-static PROPERTY STATIC_LIBRARY_FLAGS "/ignore:4264")
- endif()
- if(WIN32 OR WINRT OR OS2)
- # no dll exports from the static library
- target_compile_definitions(physfs-static PRIVATE "PHYSFS_STATIC")
- endif()
- target_include_directories(physfs-static PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
- target_link_libraries(physfs-static PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
- list(APPEND PHYSFS_INSTALL_TARGETS "physfs-static")
- endif()
- option(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
- if(PHYSFS_BUILD_SHARED)
- add_library(physfs-shared SHARED ${PHYSFS_SRCS})
- add_library(PhysFS::PhysFS-shared ALIAS physfs-shared)
- set_property(TARGET physfs-shared PROPERTY OUTPUT_NAME "physfs")
- set_property(TARGET physfs-shared PROPERTY MACOSX_RPATH 1)
- set_property(TARGET physfs-shared PROPERTY VERSION ${PHYSFS_VERSION})
- set_property(TARGET physfs-shared PROPERTY SOVERSION ${PHYSFS_SOVERSION})
- set_property(TARGET physfs-shared PROPERTY EXPORT_NAME PhysFS-shared)
- if(WIN32)
- set_property(TARGET physfs-shared PROPERTY PREFIX "")
- endif()
- if(MINGW)
- target_link_options(physfs-shared PRIVATE -static-libgcc)
- endif()
- if(WINRT)
- set_property(TARGET physfs-shared PROPERTY VS_WINRT_COMPONENT TRUE)
- endif()
- target_include_directories(physfs-shared PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
- target_link_libraries(physfs-shared PRIVATE ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
- list(APPEND PHYSFS_INSTALL_TARGETS "physfs-shared")
- endif()
- if(NOT PHYSFS_BUILD_SHARED AND NOT PHYSFS_BUILD_STATIC)
- message(FATAL "Both shared and static libraries are disabled!")
- endif()
- if(TARGET physfs-shared)
- add_library(PhysFS::PhysFS ALIAS physfs-shared)
- elseif(TARGET PhysFS::PhysFS-static)
- add_library(PhysFS::PhysFS ALIAS physfs-static)
- endif()
- option(PHYSFS_BUILD_TEST "Build stdio test program." TRUE)
- mark_as_advanced(PHYSFS_BUILD_TEST)
- if(PHYSFS_BUILD_TEST)
- add_executable(test_physfs test/test_physfs.c)
- target_link_libraries(test_physfs PRIVATE PhysFS::PhysFS ${OTHER_LDFLAGS})
- find_path(READLINE_H readline/readline.h)
- find_path(HISTORY_H readline/history.h)
- find_library(READLINE_LIBRARY readline)
- find_package(Curses)
- if(READLINE_H AND HISTORY_H AND READLINE_LIBRARY AND CURSES_FOUND)
- set(HAVE_SYSTEM_READLINE TRUE)
- target_link_libraries(test_physfs PRIVATE ${READLINE_LIBRARY} ${CURSES_LIBRARIES})
- target_include_directories(test_physfs SYSTEM PRIVATE ${READLINE_H} ${HISTORY_H})
- target_compile_definitions(test_physfs PRIVATE PHYSFS_HAVE_READLINE=1)
- endif()
- list(APPEND PHYSFS_INSTALL_TARGETS test_physfs)
- if(UNIX)
- add_executable(physfshttpd extras/physfshttpd.c)
- target_link_libraries(physfshttpd PRIVATE PhysFS::PhysFS)
- sdl_add_warning_options(physfshttpd WARNING_AS_ERROR ${PHYSFS_WERROR})
- endif()
- endif()
- option(PHYSFS_INSTALL "Enable PhysFS installation" ON)
- cmake_dependent_option(PHYSFS_INSTALL_MAN "Install man pages for PhysicsFS" OFF "PHYSFS_INSTALL" OFF)
- if(PHYSFS_INSTALL)
- if(MSVC)
- set(PHYSFS_INSTALL_CMAKEDIR "cmake")
- else()
- set(PHYSFS_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/PhysFS")
- endif()
- if(TARGET physfs-shared)
- install(TARGETS physfs-shared EXPORT physfs-shared-exports
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
- install(EXPORT physfs-shared-exports
- DESTINATION "${PHYSFS_INSTALL_CMAKEDIR}"
- FILE PhysFS-shared-targets.cmake
- NAMESPACE PhysFS::
- )
- export(TARGETS physfs-shared NAMESPACE PhysFS:: FILE PhysFS-shared-targets.cmake)
- endif()
- if(TARGET physfs-static)
- install(TARGETS physfs-static EXPORT physfs-static-exports
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
- install(EXPORT physfs-static-exports
- DESTINATION "${PHYSFS_INSTALL_CMAKEDIR}"
- FILE PhysFS-static-targets.cmake
- NAMESPACE PhysFS::
- )
- export(TARGETS physfs-static NAMESPACE PhysFS:: FILE PhysFS-static-targets.cmake)
- endif()
- if(TARGET test_physfs)
- install(TARGETS test_physfs RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
- endif()
- install(FILES src/physfs.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
- include(CMakePackageConfigHelpers)
- configure_package_config_file(extras/PhysFSConfig.cmake.in PhysFSConfig.cmake
- NO_SET_AND_CHECK_MACRO
- PATH_VARS CMAKE_INSTALL_PREFIX
- INSTALL_DESTINATION "${PHYSFS_INSTALL_CMAKEDIR}"
- )
- write_basic_package_version_file(PhysFSConfigVersion.cmake
- COMPATIBILITY SameMajorVersion
- )
- install(FILES
- "${CMAKE_CURRENT_BINARY_DIR}/PhysFSConfig.cmake"
- "${CMAKE_CURRENT_BINARY_DIR}/PhysFSConfigVersion.cmake"
- DESTINATION "${PHYSFS_INSTALL_CMAKEDIR}"
- )
- install(FILES LICENSE.txt
- DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/PhysicsFS${PROJECT_VERSION_MAJOR}")
- configure_file(extras/cmake_uninstall.cmake.in cmake_uninstall.cmake IMMEDIATE @ONLY)
- add_custom_target(uninstall-physfs
- COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
- if(NOT MSVC)
- configure_file(
- "extras/physfs.pc.in"
- "extras/physfs.pc"
- @ONLY
- )
- install(
- FILES "${CMAKE_CURRENT_BINARY_DIR}/extras/physfs.pc"
- DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
- )
- endif()
- if(PHYSFS_INSTALL_MAN)
- sdl_get_git_revision_hash(PHYSFS_REVISION)
- SDL_generate_manpages(
- HEADERS_DIR "${PROJECT_SOURCE_DIR}/src/physfs.h"
- SYMBOL "PHYSFS_init"
- WIKIHEADERS_PL_PATH "${PROJECT_SOURCE_DIR}/extras/wikiheaders.pl"
- REVISION "${PHYSFS_REVISION}"
- )
- endif()
- endif()
- option(PHYSFS_BUILD_DOCS "Build doxygen based documentation" TRUE)
- if(PHYSFS_BUILD_DOCS)
- find_package(Doxygen)
- if(DOXYGEN_FOUND)
- set(PHYSFS_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
- configure_file(
- "${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile"
- "${PHYSFS_OUTPUT_DOXYFILE}"
- COPYONLY
- )
- file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n\n# Below auto-generated by cmake...\n\n")
- file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "PROJECT_NUMBER = \"${PHYSFS_VERSION}\"\n")
- file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "OUTPUT_DIRECTORY = \"${CMAKE_CURRENT_BINARY_DIR}/docs\"\n")
- file(APPEND "${PHYSFS_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n")
- set(PHYSFS_TARGETNAME_DOCS "docs" CACHE STRING "Name of 'docs' build target")
- add_custom_target(
- ${PHYSFS_TARGETNAME_DOCS}
- ${DOXYGEN_EXECUTABLE} "${PHYSFS_OUTPUT_DOXYFILE}"
- WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
- COMMENT "Building documentation in 'docs' directory..."
- )
- else()
- message(STATUS "Doxygen not found. You won't be able to build documentation.")
- endif()
- endif()
- if(UNIX)
- set(PHYSFS_TARBALL "${CMAKE_CURRENT_SOURCE_DIR}/../physfs-${PHYSFS_VERSION}.tar.gz")
- set(PHYSFS_TARGETNAME_DIST "dist" CACHE STRING "Name of 'dist' build target")
- add_custom_target(
- ${PHYSFS_TARGETNAME_DIST}
- git archive --prefix="physfs-${PHYSFS_VERSION}/" --output="${PHYSFS_TARBALL}" HEAD
- WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
- COMMENT "Building source tarball '${PHYSFS_TARBALL}'..."
- )
- endif()
- macro(message_bool_option _NAME _VALUE)
- if(${_VALUE})
- message(STATUS " ${_NAME}: enabled")
- else()
- message(STATUS " ${_NAME}: disabled")
- endif()
- endmacro()
- message(STATUS "PhysicsFS will build with the following options:")
- message_bool_option("ZIP support" PHYSFS_ARCHIVE_ZIP)
- message_bool_option("7zip support" PHYSFS_ARCHIVE_7Z)
- message_bool_option("GRP support" PHYSFS_ARCHIVE_GRP)
- message_bool_option("WAD support" PHYSFS_ARCHIVE_WAD)
- message_bool_option("CSM support" PHYSFS_ARCHIVE_CSM)
- message_bool_option("HOG support" PHYSFS_ARCHIVE_HOG)
- message_bool_option("MVL support" PHYSFS_ARCHIVE_MVL)
- message_bool_option("QPAK support" PHYSFS_ARCHIVE_QPAK)
- message_bool_option("SLB support" PHYSFS_ARCHIVE_SLB)
- message_bool_option("VDF support" PHYSFS_ARCHIVE_VDF)
- message_bool_option("ISO9660 support" PHYSFS_ARCHIVE_ISO9660)
- message_bool_option("GOB/LAB/LFD support" PHYSFS_ARCHIVE_LECARCHIVES)
- message_bool_option("Build static library" PHYSFS_BUILD_STATIC)
- message_bool_option("Build shared library" PHYSFS_BUILD_SHARED)
- message_bool_option("Build stdio test program" PHYSFS_BUILD_TEST)
- message_bool_option("Build Doxygen documentation" PHYSFS_BUILD_DOCS)
- if(PHYSFS_BUILD_TEST)
- message_bool_option(" Use readline in test program" HAVE_SYSTEM_READLINE)
- endif()
- # end of CMakeLists.txt ...
|