ThirdPartyZlib.cmake 2.7 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
# Find a system ZLIB library. If not found enable the THIRDPARTY_BUILD_ZLIB
# option.
11 12 13 14 15
# On Windows, we want to force the use of third party zlib
# since this will be used with the boost build if boost is being
# built as a third party lib
IF(WIN32)
    MESSAGE(STATUS "On a WIN32 platform, zlib will be built as a third party library...")
Dave Moxey's avatar
Dave Moxey committed
16
    SET(BUILD_ZLIB ON)
17 18 19 20 21 22 23
ELSE()
    FIND_PACKAGE(ZLIB QUIET)
    IF (ZLIB_FOUND AND NOT ZLIB_VERSION_PATCH LESS 7)
        SET(BUILD_ZLIB OFF)
    ELSE ()
        SET(BUILD_ZLIB ON)
    ENDIF()
24 25
ENDIF()

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

28
# If we or the user
29
IF (THIRDPARTY_BUILD_ZLIB)
Dave Moxey's avatar
Dave Moxey committed
30
    INCLUDE(ExternalProject)
31
    EXTERNALPROJECT_ADD(
32
        zlib-1.2.7
33
        URL ${TPURL}/zlib-1.2.7.tar.gz
34
        URL_MD5 "4a162e0f643232e7e278d59a0603ceb0"
35
        STAMP_DIR ${TPBUILD}/stamp
36
        DOWNLOAD_DIR ${TPSRC}
37 38 39 40
        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}
41
        CONFIGURE_COMMAND ${CMAKE_COMMAND}
42
            -G ${CMAKE_GENERATOR}
43
            -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
44
            -DCMAKE_INSTALL_PREFIX:PATH=${TPDIST}
45
            -DCMAKE_C_FLAGS:STRING=-fPIC
46
            ${TPSRC}/zlib-1.2.7
Dave Moxey's avatar
Dave Moxey committed
47 48
        )

Dave Moxey's avatar
Dave Moxey committed
49 50
    IF (APPLE)
        EXTERNALPROJECT_ADD_STEP(zlib-1.2.7 patch-install-path
Dave Moxey's avatar
Dave Moxey committed
51
            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
52 53 54
            DEPENDEES install)
    ENDIF ()

55
    IF (WIN32)
56 57
        SET(ZLIB_NAME zlib)
        SET(ZLIB_NAME_DEBUG zlibd)
Dave Moxey's avatar
Dave Moxey committed
58
    ELSE ()
59 60
        SET(ZLIB_NAME z)
        SET(ZLIB_NAME_DEBUG z)
Dave Moxey's avatar
Dave Moxey committed
61
    ENDIF ()
62 63
    THIRDPARTY_LIBRARY(ZLIB_LIBRARIES SHARED ${ZLIB_NAME} DESCRIPTION "Zlib library")
    THIRDPARTY_LIBRARY(ZLIB_LIBRARIES_DEBUG SHARED ${ZLIB_NAME_DEBUG} DESCRIPTION "Zlib library")
Dave Moxey's avatar
Dave Moxey committed
64

65 66 67
    MESSAGE(STATUS "Build Zlib: ")
    MESSAGE(STATUS " -- Optimized: ${ZLIB_LIBRARIES}")
    MESSAGE(STATUS " -- Debug:     ${ZLIB_LIBRARIES_DEBUG}")
68
    SET(ZLIB_INCLUDE_DIR ${TPDIST}/include CACHE PATH "Zlib include" FORCE)
Dave Moxey's avatar
Dave Moxey committed
69
    SET(ZLIB_CONFIG_INCLUDE_DIR ${TPINC})
70 71
ELSE (THIRDPARTY_BUILD_ZLIB)
    ADD_CUSTOM_TARGET(zlib-1.2.7 ALL)
Michael Turner's avatar
Michael Turner committed
72
    MESSAGE(STATUS "Found Zlib: ${ZLIB_LIBRARIES} (version ${ZLIB_VERSION_STRING})")
73 74 75 76

    # We use the found library also for debug builds.
    SET(ZLIB_LIBRARIES_DEBUG ${ZLIB_LIBRARIES})

Michael Turner's avatar
Michael Turner committed
77
    SET(ZLIB_CONFIG_INCLUDE_DIR ${ZLIB_INCLUDE_DIRS})
78 79
ENDIF (THIRDPARTY_BUILD_ZLIB)

Michael Turner's avatar
Michael Turner committed
80
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})