cmake_minimum_required(VERSION 2.8)
#project(minizip)

include(../../../conanbuildinfo.cmake)
conan_basic_setup()

set(SOURCES ioapi.c mztools.c unzip.c zip.c)
set(PUBLIC_HEADERS ioapi.h mztools.h unzip.h zip.h minizip_extern.h)
# crypt.h is internal-only and should be no-install
set(HEADERS crypt.h ${PUBLIC_HEADERS})

if(WIN32)
  set(SOURCES ${SOURCES} iowin32.c)
  set(HEADERS ${HEADERS} iowin32.h)
  set(PUBLIC_HEADERS ${PUBLIC_HEADERS} iowin32.h)

  if(BUILD_SHARED_LIBS)
    set(SOURCES ${SOURCES} minizip1.rc)
  endif()
endif()

add_library(minizip ${SOURCES} ${HEADERS})
target_include_directories(minizip PRIVATE
  ${CMAKE_CURRENT_SOURCE_DIR}/../..
  ${CMAKE_CURRENT_SOURCE_DIR}/../../_build
  ${CMAKE_CURRENT_SOURCE_DIR}/../../_build/source_subfolder)

find_library(ZLIB_LIBRARY NAMES z zlib zlibd zlibstatic zlibstaticd PATHS
  ${CMAKE_CURRENT_SOURCE_DIR}/../../_build
  ${CMAKE_CURRENT_SOURCE_DIR}/../../_build/lib)

target_link_libraries(minizip PRIVATE ${ZLIB_LIBRARY})
target_compile_definitions(minizip PRIVATE MINIZIP_BUILDING)
if(BUILD_SHARED_LIBS)
  set_target_properties(minizip PROPERTIES INSTALL_RPATH "$ORIGIN" BUILD_WITH_INSTALL_RPATH True)
  target_compile_definitions(minizip PRIVATE MINIZIP_DLL ZLIB_DLL)

  if(WIN32)
    set_target_properties(minizip PROPERTIES SUFFIX "1.dll")
  endif()
endif()

set_target_properties(minizip PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
set_target_properties(minizip PROPERTIES SOVERSION 1)
set_target_properties(minizip PROPERTIES VERSION "1.1.0")

install(TARGETS minizip
  ARCHIVE DESTINATION "lib"
  LIBRARY DESTINATION "lib"
  RUNTIME DESTINATION "bin"
  PUBLIC_HEADER DESTINATION "include"
  COMPONENT library
)
