ThirdPartyZlib.cmake 3.19 KB
Newer Older
1 2 3 4 5 6 7
########################################################################
#
# ThirdParty configuration for Nektar++
#
# ZLib
#
########################################################################
8

Dave Moxey's avatar
Dave Moxey committed
9 10 11 12 13 14
# Attempt to identify Macports libraries, if they exist and we didn't override
# ZLIB_ROOT on the command line or in ccmake. This prevents cmake warnings later
# on.
IF (NOT DEFINED ZLIB_ROOT)
    SET(ZLIB_ROOT /opt/local/)
ENDIF()
15

Dave Moxey's avatar
Dave Moxey committed
16 17 18 19 20 21 22
# Find a system ZLIB library. If not found enable the THIRDPARTY_BUILD_ZLIB
# option.
SET(ZLIB_FIND_QUIETLY ON)
FIND_PACKAGE(ZLIB)
IF (ZLIB_FOUND AND NOT ZLIB_VERSION_PATCH LESS 7)
    SET(ZLIB_LIBRARY ${ZLIB_LIBRARIES} CACHE FILEPATH
        "Zlib library" FORCE)
23 24 25 26 27
    SET(ZLIB_LIBRARY_DEBUG ${ZLIB_LIBRARIES} CACHE FILEPATH
        "Zlib library" FORCE)
    SET(ZLIB_LIBRARY_RELEASE ${ZLIB_LIBRARIES} CACHE FILEPATH
        "Zlib library" FORCE)
    MARK_AS_ADVANCED(ZLIB_LIBRARY ZLIB_LIBRARY_DEBUG ZLIB_LIBRARY_RELEASE)
Dave Moxey's avatar
Dave Moxey committed
28 29 30
    SET(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIRS} CACHE PATH
        "Zlib include" FORCE)
    SET(BUILD_ZLIB OFF)
31
ELSE ()
Dave Moxey's avatar
Dave Moxey committed
32
    SET(BUILD_ZLIB ON)
33 34
ENDIF()

Dave Moxey's avatar
Dave Moxey committed
35 36
OPTION(THIRDPARTY_BUILD_ZLIB "Build ZLib library" ${BUILD_ZLIB})

37
# If we or the user
38
IF (THIRDPARTY_BUILD_ZLIB)
Dave Moxey's avatar
Dave Moxey committed
39
    INCLUDE(ExternalProject)
40
    EXTERNALPROJECT_ADD(
41
        zlib-1.2.7
42
        URL ${TPURL}/zlib-1.2.7.tar.gz
43
        URL_MD5 "4a162e0f643232e7e278d59a0603ceb0"
44
        STAMP_DIR ${TPBUILD}/stamp
45
        DOWNLOAD_DIR ${TPSRC}
46 47 48 49
        SOURCE_DIR ${TPSRC}/zlib-1.2.7
        BINARY_DIR ${TPBUILD}/zlib-1.2.7
        TMP_DIR ${TPBUILD}/zlib-1.2.7-tmp
        INSTALL_DIR ${TPDIST}
50
        CONFIGURE_COMMAND ${CMAKE_COMMAND}
51
            -G ${CMAKE_GENERATOR}
52
            -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
53
            -DCMAKE_INSTALL_PREFIX:PATH=${TPDIST}
54
            -DCMAKE_C_FLAGS:STRING=-fPIC
55
            ${TPSRC}/zlib-1.2.7
Dave Moxey's avatar
Dave Moxey committed
56 57
        )

Dave Moxey's avatar
Dave Moxey committed
58 59
    IF (APPLE)
        EXTERNALPROJECT_ADD_STEP(zlib-1.2.7 patch-install-path
Dave Moxey's avatar
Dave Moxey committed
60
            COMMAND ${CMAKE_INSTALL_NAME_TOOL} -id ${CMAKE_INSTALL_PREFIX}/${NEKTAR_LIB_DIR}/libz.1.2.7.dylib ${TPDIST}/lib/libz.1.2.7.dylib
Dave Moxey's avatar
Dave Moxey committed
61 62 63
            DEPENDEES install)
    ENDIF ()

64
    IF (WIN32)
Dave Moxey's avatar
Dave Moxey committed
65 66
        SET(ZLIB_LIBRARY zlib CACHE FILEPATH
            "Zlib library" FORCE)
67 68 69 70
        SET(ZLIB_LIBRARY_DEBUG zlibd CACHE FILEPATH
            "Zlib library" FORCE)
        SET(ZLIB_LIBRARY_RELEASE zlib CACHE FILEPATH
            "Zlib library" FORCE)
71
        MESSAGE(STATUS "Build Zlib: ${TPDIST}/${LIB_DIR}/${ZLIB_LIBRARY}.dll")
Dave Moxey's avatar
Dave Moxey committed
72 73 74
    ELSE ()
        SET(ZLIB_LIBRARY z CACHE FILEPATH
            "Zlib library" FORCE)
75 76 77 78
        SET(ZLIB_LIBRARY_DEBUG z CACHE FILEPATH
            "Zlib library" FORCE)
        SET(ZLIB_LIBRARY_RELEASE z CACHE FILEPATH
            "Zlib library" FORCE)
79
        MESSAGE(STATUS "Build Zlib: ${TPDIST}/${LIB_DIR}/lib${ZLIB_LIBRARY}.a")
Dave Moxey's avatar
Dave Moxey committed
80 81
    ENDIF ()

82
    SET(ZLIB_INCLUDE_DIR ${TPDIST}/include CACHE PATH "Zlib include" FORCE)
Dave Moxey's avatar
Dave Moxey committed
83 84
    LINK_DIRECTORIES(${TPDIST}/lib)
    SET(ZLIB_CONFIG_INCLUDE_DIR ${TPINC})
85 86
ELSE (THIRDPARTY_BUILD_ZLIB)
    ADD_CUSTOM_TARGET(zlib-1.2.7 ALL)
Dave Moxey's avatar
Dave Moxey committed
87 88
    MESSAGE(STATUS "Found Zlib: ${ZLIB_LIBRARY} (version ${ZLIB_VERSION_STRING})")
    SET(ZLIB_CONFIG_INCLUDE_DIR ${ZLIB_INCLUDE_DIR})
89 90
ENDIF (THIRDPARTY_BUILD_ZLIB)

Dave Moxey's avatar
Dave Moxey committed
91
INCLUDE_DIRECTORIES(SYSTEM ${ZLIB_INCLUDE_DIR})