1. Add cmake module for finding minizip in system
2. Check that system installed minizip recent enough for us
3. As right minizip exists only for MSYS2 (mingw), use our embedded version on all other platforms
4. Correctly include minizip as <minizip/unzip.h> if it is found from system (make it compatible to current build system, so by default all should stay same)
5. Remove one unused include of unzip.h
This commit is contained in:
Vladimir Timofeev 2014-11-16 22:41:37 +03:00
parent b7521dcbae
commit 1e8aeb7fd2
8 changed files with 94 additions and 16 deletions

View File

@ -211,6 +211,27 @@ message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}")
find_package(ZLIB REQUIRED)
message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}")
# minizip (we try to migrate to minizip from https://github.com/nmoinvaz/minizip)
# only msys2 currently provides package for this variant, all other
# dists have packages from zlib, thats very old for us.
# moreover our embedded version modified to quick provide
# functionality needed by cocos.
if(USE_PREBUILT_LIBS OR NOT MINGW)
add_subdirectory(external/unzip)
set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/unzip)
set(MINIZIP_LIBRARIES unzip)
else()
find_package(MINIZIP REQUIRED)
# double check that we have needed functions
include(CheckLibaryExists)
check_library_exists(${MINIZIP_LIBRARIES} "unzGoToFirstFile2" "" MINIZIP_HAS_GOTOFIRSTFILE2)
if(NOT MINIZIP_HAS_GOTOFIRSTFILE2)
message(FATAL_ERROR "Minizip library on you system very old. Please use recent version from https://github.com/nmoinvaz/minizip or enable USE_PREBUILT_LIBS")
endif()
add_definitions(-DMINIZIP_FROM_SYSTEM)
endif()
message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}")
find_package(PNG REQUIRED)
message(STATUS "PNG include dirs: ${PNG_INCLUDE_DIRS}")
@ -243,7 +264,6 @@ message(STATUS "Protobuf include dirs: ${PROTOBUF_INCLUDE_DIRS}")
# build for 3rd party libraries
if(LINUX OR APPLE)
add_subdirectory(external/unzip)
add_subdirectory(external/xxhash)
endif()

View File

@ -0,0 +1,51 @@
#.rst:
# FindMINIZIP
# ------------
#
# Locate minizip library (from zlib package)
#
# This module defines
#
# ::
#
# MINIZIP_LIBRARIES, the library to link against
# MINIZIP_FOUND, if false, do not try to link to fmodex
# MINIZIP_INCLUDE_DIRS, where to find headers.
#
find_path(MINIZIP_INCLUDE_DIR minizip/unzip.h
HINTS ENV MINIZIP_DIR
PATH_SUFFIXES include
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
find_library(MINIZIP_LIBRARY NAMES miniunzip libminiunzip
HINTS ENV MINIZIP_DIR
PATH_SUFFIXES lib
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
set(MINIZIP_INCLUDE_DIRS "${MINIZIP_INCLUDE_DIR}")
set(MINIZIP_LIBRARIES "${MINIZIP_LIBRARY}")
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(MINIZIP DEFAULT_MSG MINIZIP_LIBRARIES MINIZIP_INCLUDE_DIRS)
mark_as_advanced(MINIZIP_INCLUDE_DIR MINIZIP_LIBRARY)

View File

@ -81,16 +81,6 @@ set(COCOS_SRC cocos2d.cpp
${COCOS_EXTENSIONS_SRC}
)
if(NOT MINGW)
#todo: provide prebuild versions of minizip for android ios mac and msvc
#done: prebuilt version for mingw-w64 (linux distros should have them also)
# check for opensuse the buildbot system arch and ubuntu
include_directories( ../external/unzip )
endif()
#todo: provide prebuild versions of the xx libs for all platforms
include_directories(
../external/xxhash
@ -144,6 +134,7 @@ add_definitions(${PNG_DEFINITIONS})
include_directories(
${ZLIB_INCLUDE_DIRS}
${MINIZIP_INCLUDE_DIRS}
${JPEG_INCLUDE_DIRS}
${PNG_INCLUDE_DIRS}
${TIFF_INCLUDE_DIRS}
@ -153,8 +144,9 @@ include_directories(
${PROTOBUF_INCLUDE_DIRS}
)
target_link_libraries(cocos2d
unzip xxhash
xxhash
${ZLIB_LIBRARIES}
${MINIZIP_LIBRARIES}
${JPEG_LIBRARIES}
${PNG_LIBRARIES}
${TIFF_LIBRARIES}

View File

@ -24,7 +24,12 @@
****************************************************************************/
// FIXME: hack, must be included before ziputils
#ifdef MINIZIP_FROM_SYSTEM
#include <minizip/unzip.h>
#else // from our embedded sources
#include "unzip.h"
#endif
#include "base/ZipUtils.h"
#include <zlib.h>
@ -37,7 +42,7 @@
#include <map>
// FIXME: Other platforms should use upstream minizip like mingw-w64
#ifdef __MINGW32__
#ifdef MINIZIP_FROM_SYSTEM
#define unzGoToFirstFile64(A,B,C,D) unzGoToFirstFile2(A,B,C,D, NULL, 0, NULL, 0)
#define unzGoToNextFile64(A,B,C,D) unzGoToNextFile2(A,B,C,D, NULL, 0, NULL, 0)
#endif

View File

@ -34,7 +34,11 @@ THE SOFTWARE.
#include "base/ccUtils.h"
#include "tinyxml2.h"
#ifdef MINIZIP_FROM_SYSTEM
#include <minizip/unzip.h>
#else // from our embedded sources
#include "unzip.h"
#endif
#include <sys/stat.h>
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
@ -653,7 +657,7 @@ unsigned char* FileUtils::getFileDataFromZip(const std::string& zipFilePath, con
CC_BREAK_IF(!file);
// FIXME: Other platforms should use upstream minizip like mingw-w64
#ifdef __MINGW32__
#ifdef MINIZIP_FROM_SYSTEM
int ret = unzLocateFile(file, filename.c_str(), NULL);
#else
int ret = unzLocateFile(file, filename.c_str(), 1);

View File

@ -35,8 +35,6 @@ THE SOFTWARE.
#include "deprecated/CCDictionary.h"
#include "platform/CCFileUtils.h"
#include "platform/CCSAXParser.h"
#include "unzip.h"
NS_CC_BEGIN

View File

@ -41,7 +41,11 @@
#include "base/CCUserDefault.h"
#include "platform/CCFileUtils.h"
#ifdef MINIZIP_FROM_SYSTEM
#include <minizip/unzip.h>
#else // from our embedded sources
#include "unzip.h"
#endif
using namespace cocos2d;
using namespace std;

View File

@ -30,7 +30,11 @@
#include <curl/easy.h>
#include <stdio.h>
#ifdef MINIZIP_FROM_SYSTEM
#include <minizip/unzip.h>
#else // from our embedded sources
#include "unzip.h"
#endif
using namespace cocos2d;
using namespace std;