From dcba7a63165d4ca6c0b104ce073356a4f38867e9 Mon Sep 17 00:00:00 2001 From: Mikhail Paulyshka Date: Sun, 12 Oct 2014 16:50:39 +0300 Subject: [PATCH] move minizip detection to module --- CMakeLists.txt | 19 +++------ cmake_modules/FindMinizip.cmake | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 cmake_modules/FindMinizip.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 96045d441..8d1d15d51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,7 @@ project(vcmi) cmake_minimum_required(VERSION 2.8.12) # TODO: -# 1) Detection of system version of minizip and use it instead of local -# 2) Detection of Qt5 and compilation of launcher, unless explicitly disabled +# 1) Detection of Qt5 and compilation of launcher, unless explicitly disabled # where to look for cmake modules set(CMAKE_MODULE_PATH ${CMAKE_HOME_DIRECTORY}/cmake_modules) @@ -117,6 +116,10 @@ set(FFmpeg_FIND_COMPONENTS AVFORMAT SWSCALE) find_package(Boost 1.48.0 COMPONENTS filesystem locale program_options system thread REQUIRED) find_package(ZLIB REQUIRED) find_package(FFmpeg REQUIRED) +find_package(Minizip) +if (MINIZIP_FOUND) + add_definitions(-DUSE_SYSTEM_MINIZIP) +endif() if (ENABLE_SDL2) find_package(SDL2 REQUIRED) @@ -211,18 +214,6 @@ SET(PCH_PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "StdInc.h" ) -find_path(MINIZIP_INCLUDE_PATH NAMES minizip/unzip.h) -find_library(MINIZIP_LIB NAMES minizip PATH_SUFFIXES dynamic) -mark_as_advanced(MINIZIP_INCLUDE_PATH MINIZIP_LIB) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(MINIZIP MINIZIP_INCLUDE_PATH MINIZIP_LIB) -if (MINIZIP_FOUND) - set(MINIZIP_INCLUDE_DIR ${MINIZIP_INCLUDE_PATH}) - set(MINIZIP_LIBRARIES ${MINIZIP_LIB}) - add_definitions(-DUSE_SYSTEM_MINIZIP) -endif() - if (ENABLE_ERM) add_subdirectory(scripting/erm) endif() diff --git a/cmake_modules/FindMinizip.cmake b/cmake_modules/FindMinizip.cmake new file mode 100644 index 000000000..641191826 --- /dev/null +++ b/cmake_modules/FindMinizip.cmake @@ -0,0 +1,72 @@ +#.rst: +# FindMINIZIP +# -------- +# +# Locate Minizip library +# +# This module defines +# +# :: +# +# MINIZIP_LIBRARY, the name of the library to link against +# MINIZIP_FOUND, if false, do not try to link to Minizip +# MINIZIP_INCLUDE_DIR, where to find unzip.h +# MINIZIP_VERSION_STRING, human-readable string containing the version of Minizip +# +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# Copyright 2012 Benjamin Eikel +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file kitware license.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(VC_LIB_PATH_SUFFIX lib/x64) +else() + set(VC_LIB_PATH_SUFFIX lib/x86) +endif() + +if (NOT WIN32) + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules(_MINIZIP minizip) + set(MINIZIP_VERSION_STRING ${_MINIZIP_VERSION}) + endif () +endif () + +find_path(MINIZIP_INCLUDE_DIR + minizip/unzip.h + HINTS + ${_MINIZIP_INCLUDEDIR} + ENV MINIZIPDIR + PATH_SUFFIXES + MINIZIP + include +) + +find_library(MINIZIP_LIBRARY + NAMES + minizip + HINTS + ${_MINIZIP_LIBDIR} + ENV MINIZIPDIR + PATH_SUFFIXES + lib + ${VC_LIB_PATH_SUFFIX} +) + +set(MINIZIP_LIBRARIES ${MINIZIP_LIBRARY}) +set(MINIZIP_INCLUDE_DIRS ${MINIZIP_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(MINIZIP + REQUIRED_VARS MINIZIP_LIBRARY MINIZIP_INCLUDE_DIR + VERSION_VAR MINIZIP_VERSION_STRING) \ No newline at end of file