Home | History | Annotate | Line # | Download | only in zlib
CMakeLists.txt revision 1.1.1.2
      1      1.1  christos cmake_minimum_required(VERSION 2.4.4)
      2      1.1  christos set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
      3      1.1  christos 
      4      1.1  christos project(zlib C)
      5      1.1  christos 
      6  1.1.1.2  christos set(VERSION "1.2.13")
      7      1.1  christos 
      8      1.1  christos set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
      9      1.1  christos set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
     10      1.1  christos set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
     11      1.1  christos set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
     12      1.1  christos set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
     13      1.1  christos 
     14      1.1  christos include(CheckTypeSize)
     15      1.1  christos include(CheckFunctionExists)
     16      1.1  christos include(CheckIncludeFile)
     17      1.1  christos include(CheckCSourceCompiles)
     18      1.1  christos enable_testing()
     19      1.1  christos 
     20      1.1  christos check_include_file(sys/types.h HAVE_SYS_TYPES_H)
     21      1.1  christos check_include_file(stdint.h    HAVE_STDINT_H)
     22      1.1  christos check_include_file(stddef.h    HAVE_STDDEF_H)
     23      1.1  christos 
     24      1.1  christos #
     25      1.1  christos # Check to see if we have large file support
     26      1.1  christos #
     27      1.1  christos set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
     28      1.1  christos # We add these other definitions here because CheckTypeSize.cmake
     29      1.1  christos # in CMake 2.4.x does not automatically do so and we want
     30      1.1  christos # compatibility with CMake 2.4.x.
     31      1.1  christos if(HAVE_SYS_TYPES_H)
     32      1.1  christos     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
     33      1.1  christos endif()
     34      1.1  christos if(HAVE_STDINT_H)
     35      1.1  christos     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
     36      1.1  christos endif()
     37      1.1  christos if(HAVE_STDDEF_H)
     38      1.1  christos     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
     39      1.1  christos endif()
     40      1.1  christos check_type_size(off64_t OFF64_T)
     41      1.1  christos if(HAVE_OFF64_T)
     42      1.1  christos    add_definitions(-D_LARGEFILE64_SOURCE=1)
     43      1.1  christos endif()
     44      1.1  christos set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
     45      1.1  christos 
     46      1.1  christos #
     47      1.1  christos # Check for fseeko
     48      1.1  christos #
     49      1.1  christos check_function_exists(fseeko HAVE_FSEEKO)
     50      1.1  christos if(NOT HAVE_FSEEKO)
     51      1.1  christos     add_definitions(-DNO_FSEEKO)
     52      1.1  christos endif()
     53      1.1  christos 
     54      1.1  christos #
     55      1.1  christos # Check for unistd.h
     56      1.1  christos #
     57      1.1  christos check_include_file(unistd.h Z_HAVE_UNISTD_H)
     58      1.1  christos 
     59      1.1  christos if(MSVC)
     60      1.1  christos     set(CMAKE_DEBUG_POSTFIX "d")
     61      1.1  christos     add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
     62      1.1  christos     add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
     63      1.1  christos     include_directories(${CMAKE_CURRENT_SOURCE_DIR})
     64      1.1  christos endif()
     65      1.1  christos 
     66      1.1  christos if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
     67      1.1  christos     # If we're doing an out of source build and the user has a zconf.h
     68      1.1  christos     # in their source tree...
     69      1.1  christos     if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
     70      1.1  christos         message(STATUS "Renaming")
     71      1.1  christos         message(STATUS "    ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h")
     72      1.1  christos         message(STATUS "to 'zconf.h.included' because this file is included with zlib")
     73      1.1  christos         message(STATUS "but CMake generates it automatically in the build directory.")
     74      1.1  christos         file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included)
     75      1.1  christos   endif()
     76      1.1  christos endif()
     77      1.1  christos 
     78      1.1  christos set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc)
     79      1.1  christos configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
     80      1.1  christos 		${ZLIB_PC} @ONLY)
     81      1.1  christos configure_file(	${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
     82      1.1  christos 		${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
     83      1.1  christos include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
     84      1.1  christos 
     85      1.1  christos 
     86      1.1  christos #============================================================================
     87      1.1  christos # zlib
     88      1.1  christos #============================================================================
     89      1.1  christos 
     90      1.1  christos set(ZLIB_PUBLIC_HDRS
     91      1.1  christos     ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
     92      1.1  christos     zlib.h
     93      1.1  christos )
     94      1.1  christos set(ZLIB_PRIVATE_HDRS
     95      1.1  christos     crc32.h
     96      1.1  christos     deflate.h
     97      1.1  christos     gzguts.h
     98      1.1  christos     inffast.h
     99      1.1  christos     inffixed.h
    100      1.1  christos     inflate.h
    101      1.1  christos     inftrees.h
    102      1.1  christos     trees.h
    103      1.1  christos     zutil.h
    104      1.1  christos )
    105      1.1  christos set(ZLIB_SRCS
    106      1.1  christos     adler32.c
    107      1.1  christos     compress.c
    108      1.1  christos     crc32.c
    109      1.1  christos     deflate.c
    110      1.1  christos     gzclose.c
    111      1.1  christos     gzlib.c
    112      1.1  christos     gzread.c
    113      1.1  christos     gzwrite.c
    114      1.1  christos     inflate.c
    115      1.1  christos     infback.c
    116      1.1  christos     inftrees.c
    117      1.1  christos     inffast.c
    118      1.1  christos     trees.c
    119      1.1  christos     uncompr.c
    120      1.1  christos     zutil.c
    121      1.1  christos )
    122      1.1  christos 
    123      1.1  christos if(NOT MINGW)
    124      1.1  christos     set(ZLIB_DLL_SRCS
    125      1.1  christos         win32/zlib1.rc # If present will override custom build rule below.
    126      1.1  christos     )
    127      1.1  christos endif()
    128      1.1  christos 
    129      1.1  christos # parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
    130      1.1  christos file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
    131      1.1  christos string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
    132      1.1  christos     "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
    133      1.1  christos 
    134      1.1  christos if(MINGW)
    135      1.1  christos     # This gets us DLL resource information when compiling on MinGW.
    136      1.1  christos     if(NOT CMAKE_RC_COMPILER)
    137      1.1  christos         set(CMAKE_RC_COMPILER windres.exe)
    138      1.1  christos     endif()
    139      1.1  christos 
    140      1.1  christos     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
    141      1.1  christos                        COMMAND ${CMAKE_RC_COMPILER}
    142      1.1  christos                             -D GCC_WINDRES
    143      1.1  christos                             -I ${CMAKE_CURRENT_SOURCE_DIR}
    144      1.1  christos                             -I ${CMAKE_CURRENT_BINARY_DIR}
    145      1.1  christos                             -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
    146      1.1  christos                             -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
    147      1.1  christos     set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
    148      1.1  christos endif(MINGW)
    149      1.1  christos 
    150  1.1.1.2  christos add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
    151  1.1.1.2  christos add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
    152      1.1  christos set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
    153      1.1  christos set_target_properties(zlib PROPERTIES SOVERSION 1)
    154      1.1  christos 
    155      1.1  christos if(NOT CYGWIN)
    156      1.1  christos     # This property causes shared libraries on Linux to have the full version
    157      1.1  christos     # encoded into their final filename.  We disable this on Cygwin because
    158      1.1  christos     # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
    159      1.1  christos     # seems to be the default.
    160      1.1  christos     #
    161      1.1  christos     # This has no effect with MSVC, on that platform the version info for
    162      1.1  christos     # the DLL comes from the resource file win32/zlib1.rc
    163      1.1  christos     set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
    164      1.1  christos endif()
    165      1.1  christos 
    166      1.1  christos if(UNIX)
    167      1.1  christos     # On unix-like platforms the library is almost always called libz
    168      1.1  christos    set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)
    169      1.1  christos    if(NOT APPLE)
    170      1.1  christos      set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"")
    171      1.1  christos    endif()
    172      1.1  christos elseif(BUILD_SHARED_LIBS AND WIN32)
    173      1.1  christos     # Creates zlib1.dll when building shared library version
    174      1.1  christos     set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
    175      1.1  christos endif()
    176      1.1  christos 
    177      1.1  christos if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
    178      1.1  christos     install(TARGETS zlib zlibstatic
    179      1.1  christos         RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
    180      1.1  christos         ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
    181      1.1  christos         LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
    182      1.1  christos endif()
    183      1.1  christos if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
    184      1.1  christos     install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}")
    185      1.1  christos endif()
    186      1.1  christos if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
    187      1.1  christos     install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3")
    188      1.1  christos endif()
    189      1.1  christos if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
    190      1.1  christos     install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
    191      1.1  christos endif()
    192      1.1  christos 
    193      1.1  christos #============================================================================
    194      1.1  christos # Example binaries
    195      1.1  christos #============================================================================
    196      1.1  christos 
    197      1.1  christos add_executable(example test/example.c)
    198      1.1  christos target_link_libraries(example zlib)
    199      1.1  christos add_test(example example)
    200      1.1  christos 
    201      1.1  christos add_executable(minigzip test/minigzip.c)
    202      1.1  christos target_link_libraries(minigzip zlib)
    203      1.1  christos 
    204      1.1  christos if(HAVE_OFF64_T)
    205      1.1  christos     add_executable(example64 test/example.c)
    206      1.1  christos     target_link_libraries(example64 zlib)
    207      1.1  christos     set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
    208      1.1  christos     add_test(example64 example64)
    209      1.1  christos 
    210      1.1  christos     add_executable(minigzip64 test/minigzip.c)
    211      1.1  christos     target_link_libraries(minigzip64 zlib)
    212      1.1  christos     set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
    213      1.1  christos endif()
    214