Skip to content

Commit

Permalink
(#9169) add physfs/3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored Feb 7, 2022
1 parent 129b634 commit 41cce31
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/physfs/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup(KEEP_RPATHS)

add_subdirectory(source_subfolder)
10 changes: 10 additions & 0 deletions recipes/physfs/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
"3.0.2":
url: "https://icculus.org/physfs/downloads/physfs-3.0.2.tar.bz2"
sha256: "304df76206d633df5360e738b138c94e82ccf086e50ba84f456d3f8432f9f863"
patches:
"3.0.2":
- patch_file: "patches/0001-fix-export-import-symbols.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-cmake-doc-option.patch"
base_path: "source_subfolder"
156 changes: 156 additions & 0 deletions recipes/physfs/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
from conans import ConanFile, CMake, tools
import os
import textwrap

required_conan_version = ">=1.43.0"


class PhysfsConan(ConanFile):
name = "physfs"
description = (
"PhysicsFS is a library to provide abstract access to various "
"archives. It is intended for use in video games."
)
license = "Zlib"
topics = ("physfs", "physicsfs", "file", "filesystem", "io")
homepage = "https://icculus.org/physfs"
url = "https://github.com/conan-io/conan-center-index"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"zip": [True, False],
"sevenzip": [True, False],
"grp": [True, False],
"wad": [True, False],
"hog": [True, False],
"mvl": [True, False],
"qpak": [True, False],
"slb": [True, False],
"iso9660": [True, False],
"vdf": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"zip": True,
"sevenzip": True,
"grp": True,
"wad": True,
"hog": True,
"mvl": True,
"qpak": True,
"slb": True,
"iso9660": True,
"vdf": True,
}

generators = "cmake"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["PHYSFS_ARCHIVE_ZIP"] = self.options.zip
self._cmake.definitions["PHYSFS_ARCHIVE_7Z"] = self.options.sevenzip
self._cmake.definitions["PHYSFS_ARCHIVE_GRP"] = self.options.grp
self._cmake.definitions["PHYSFS_ARCHIVE_WAD"] = self.options.wad
self._cmake.definitions["PHYSFS_ARCHIVE_HOG"] = self.options.hog
self._cmake.definitions["PHYSFS_ARCHIVE_MVL"] = self.options.mvl
self._cmake.definitions["PHYSFS_ARCHIVE_QPAK"] = self.options.qpak
self._cmake.definitions["PHYSFS_ARCHIVE_SLB"] = self.options.slb
self._cmake.definitions["PHYSFS_ARCHIVE_ISO9660"] = self.options.iso9660
self._cmake.definitions["PHYSFS_ARCHIVE_VDF"] = self.options.vdf
self._cmake.definitions["PHYSFS_BUILD_STATIC"] = not self.options.shared
self._cmake.definitions["PHYSFS_BUILD_SHARED"] = self.options.shared
self._cmake.definitions["PHYSFS_BUILD_TEST"] = False
self._cmake.definitions["PHYSFS_BUILD_DOCS"] = False
self._cmake.configure()
return self._cmake

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("LICENSE.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{self._physfs_target: "physfs::physfs"}
)

@staticmethod
def _create_cmake_module_alias_targets(module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""".format(alias=alias, aliased=aliased))
tools.save(module_file, content)

@property
def _module_file_rel_path(self):
return os.path.join("lib", "cmake", "conan-official-{}-targets.cmake".format(self.name))

@property
def _physfs_target(self):
return "physfs" if self.options.shared else "physfs-static"

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "PhysFS")
self.cpp_info.set_property("cmake_target_name", self._physfs_target)
self.cpp_info.set_property("pkg_config_name", "physfs")
suffix = "-static" if self._is_msvc and not self.options.shared else ""
self.cpp_info.libs = ["physfs{}".format(suffix)]
if self.options.shared:
self.cpp_info.defines.append("PHYSFS_SHARED")
else:
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("pthread")
elif tools.is_apple_os(self.settings.os):
self.cpp_info.frameworks.extend(["Foundation", "IOKit"])

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.filenames["cmake_find_package"] = "PhysFS"
self.cpp_info.filenames["cmake_find_package_multi"] = "PhysFS"
self.cpp_info.build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
41 changes: 41 additions & 0 deletions recipes/physfs/all/patches/0001-fix-export-import-symbols.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
see https://github.com/icculus/physfs/pull/15

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -171,6 +171,7 @@ endif()
option(PHYSFS_BUILD_SHARED "Build shared library" TRUE)
if(PHYSFS_BUILD_SHARED)
add_library(physfs SHARED ${PHYSFS_SRCS})
+ target_compile_definitions(physfs PRIVATE PHYSFS_BUILD_SHARED PUBLIC PHYSFS_SHARED)
set_target_properties(physfs PROPERTIES MACOSX_RPATH 1)
set_target_properties(physfs PROPERTIES VERSION ${PHYSFS_VERSION})
set_target_properties(physfs PROPERTIES SOVERSION ${PHYSFS_SOVERSION})
--- a/src/physfs.h
+++ b/src/physfs.h
@@ -223,10 +223,13 @@
extern "C" {
#endif

-#if defined(PHYSFS_DECL)
-/* do nothing. */
-#elif defined(_MSC_VER)
+#ifdef PHYSFS_SHARED
+#ifdef _MSC_VER
+#ifdef PHYSFS_BUILD_SHARED
#define PHYSFS_DECL __declspec(dllexport)
+#else
+#define PHYSFS_DECL __declspec(dllimport)
+#endif
#elif defined(__SUNPRO_C)
#define PHYSFS_DECL __global
#elif ((__GNUC__ >= 3) && (!defined(__EMX__)) && (!defined(sun)))
@@ -234,6 +237,9 @@ extern "C" {
#else
#define PHYSFS_DECL
#endif
+#else
+#define PHYSFS_DECL
+#endif

#if defined(PHYSFS_DEPRECATED)
/* do nothing. */
20 changes: 20 additions & 0 deletions recipes/physfs/all/patches/0002-cmake-doc-option.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from https://github.com/icculus/physfs/pull/10

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -220,6 +220,7 @@ install(TARGETS ${PHYSFS_INSTALL_TARGETS}
ARCHIVE DESTINATION lib${LIB_SUFFIX})
install(FILES src/physfs.h DESTINATION include)

+if(PHYSFS_BUILD_DOCS)
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(PHYSFS_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
@@ -243,6 +244,7 @@ if(DOXYGEN_FOUND)
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.bz2")
14 changes: 14 additions & 0 deletions recipes/physfs/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.12)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(PhysFS REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
if(TARGET physfs-static)
target_link_libraries(${PROJECT_NAME} physfs-static)
else()
target_link_libraries(${PROJECT_NAME} physfs)
endif()
17 changes: 17 additions & 0 deletions recipes/physfs/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
10 changes: 10 additions & 0 deletions recipes/physfs/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <physfs.h>

#include <stdio.h>

int main() {
struct PHYSFS_Version physfs_version;
PHYSFS_getLinkedVersion(&physfs_version);
printf("PhysicsFS version %i.%i.%i", physfs_version.major, physfs_version.minor, physfs_version.patch);
return 0;
}
3 changes: 3 additions & 0 deletions recipes/physfs/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"3.0.2":
folder: all

0 comments on commit 41cce31

Please sign in to comment.