1b33c96954667ba382fa595baf7b31290bfdd517vboxsynccmake_minimum_required(VERSION 2.4.4)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncset(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncproject(zlib C)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(NOT DEFINED BUILD_SHARED_LIBS)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync option(BUILD_SHARED_LIBS "Build a shared library form of zlib" ON)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncinclude(CheckTypeSize)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncinclude(CheckFunctionExists)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncinclude(CheckIncludeFile)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncinclude(CheckCSourceCompiles)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncenable_testing()
1b33c96954667ba382fa595baf7b31290bfdd517vboxsynccheck_include_file(sys/types.h HAVE_SYS_TYPES_H)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsynccheck_include_file(stdint.h HAVE_STDINT_H)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsynccheck_include_file(stddef.h HAVE_STDDEF_H)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# Check to see if we have large file support
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncset(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# We add these other definitions here because CheckTypeSize.cmake
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# in CMake 2.4.x does not automatically do so and we want
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# compatibility with CMake 2.4.x.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(HAVE_SYS_TYPES_H)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(HAVE_STDINT_H)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(HAVE_STDDEF_H)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsynccheck_type_size(off64_t OFF64_T)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(HAVE_OFF64_T)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync add_definitions(-D_LARGEFILE64_SOURCE=1)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncset(CMAKE_REQUIRED_DEFINITIONS) # clear variable
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# Check for fseeko
1b33c96954667ba382fa595baf7b31290bfdd517vboxsynccheck_function_exists(fseeko HAVE_FSEEKO)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(NOT HAVE_FSEEKO)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync add_definitions(-DNO_FSEEKO)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsynccheck_include_file(unistd.h Z_HAVE_UNISTD_H)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync set(CMAKE_DEBUG_POSTFIX "d")
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync # If we're doing an out of source build and the user has a zconf.h
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync # in their source tree...
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync message(FATAL_ERROR
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync "You must remove ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h "
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync "from the source tree. This file is included with zlib "
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync "but CMake generates this file for you automatically "
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync "in the build directory.")
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncinclude_directories(${CMAKE_CURRENT_BINARY_DIR})
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync#============================================================================
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync#============================================================================
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncset(ZLIB_PUBLIC_HDRS
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncset(ZLIB_PRIVATE_HDRS
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncset(ZLIB_SRCS
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(NOT MINGW)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync set(ZLIB_SRCS ${ZLIB_SRCS}
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync win32/zlib1.rc # If present will override custom build rule below.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncfile(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncstring(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([0-9A-Za-z.]+)\".*"
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync # This gets us DLL resource information when compiling on MinGW.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync if(NOT CMAKE_RC_COMPILER)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync SET(CMAKE_RC_COMPILER windres.exe)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync COMMAND ${CMAKE_RC_COMPILER}
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync -D GCC_WINDRES
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync -I ${CMAKE_CURRENT_SOURCE_DIR}
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync -I ${CMAKE_CURRENT_BINARY_DIR}
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync set(ZLIB_SRCS ${ZLIB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncendif(MINGW)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncadd_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncset_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncset_target_properties(zlib PROPERTIES SOVERSION 1)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(NOT CYGWIN)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync # This property causes shared libraries on Linux to have the full version
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync # encoded into their final filename. We disable this on Cygwin because
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync # seems to be the default.
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync # This has no effect with MSVC, on that platform the version info for
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync # the DLL comes from the resource file win32/zlib1.rc
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync # On unix-like platforms the library is almost always called libz
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncelseif(BUILD_SHARED_LIBS AND WIN32)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync # Creates zlib1.dll when building shared library version
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync install(TARGETS zlib
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync RUNTIME DESTINATION bin
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync ARCHIVE DESTINATION lib
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync LIBRARY DESTINATION lib )
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync install(FILES zlib.3 DESTINATION share/man/man3)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync#============================================================================
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync# Example binaries
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync#============================================================================
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncadd_executable(example test/example.c)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsynctarget_link_libraries(example zlib)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncadd_test(example example)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncadd_executable(minigzip test/minigzip.c)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsynctarget_link_libraries(minigzip zlib)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsyncif(HAVE_OFF64_T)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync add_executable(example64 test/example.c)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync target_link_libraries(example64 zlib)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync add_test(example64 example64)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync add_executable(minigzip64 test/minigzip.c)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync target_link_libraries(minigzip64 zlib)
1b33c96954667ba382fa595baf7b31290bfdd517vboxsync set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")