ThirdPartyScotch.cmake 4.08 KB
Newer Older
Dave Moxey's avatar
Dave Moxey committed
1 2 3 4 5 6 7 8
########################################################################
#
# ThirdParty configuration for Nektar++
#
# Scotch partitioner
#
########################################################################

9 10 11 12
IF (NOT WIN32)
    OPTION(NEKTAR_USE_SCOTCH
        "Use Scotch library for performing mesh partitioning." OFF)
ENDIF(NOT WIN32)
13

Dave Moxey's avatar
Dave Moxey committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
IF (NEKTAR_USE_SCOTCH)
    # First search for system TinyXML installs. Hint /opt/local for MacPorts.
    FIND_LIBRARY(SCOTCH_LIBRARY    NAMES scotch PATHS /opt/local/lib)
    FIND_LIBRARY(SCOTCHERR_LIBRARY NAMES scotcherr PATHS /opt/local/lib)
    FIND_PATH   (SCOTCH_INCLUDE_DIR scotch.h PATHS /opt/local/include)

    IF (SCOTCH_LIBRARY AND SCOTCHERR_LIBRARY AND SCOTCH_INCLUDE_DIR)
        SET(BUILD_SCOTCH OFF)
    ELSE()
        SET(BUILD_SCOTCH ON)
    ENDIF ()

    CMAKE_DEPENDENT_OPTION(THIRDPARTY_BUILD_SCOTCH
        "Build Scotch library from ThirdParty" ${BUILD_SCOTCH}
        "NEKTAR_USE_SCOTCH" OFF)
29 30

    IF (THIRDPARTY_BUILD_SCOTCH)
31 32 33 34 35 36
        UNSET(FLEX CACHE)
        FIND_PROGRAM(FLEX flex)
        IF(NOT FLEX)
            MESSAGE(FATAL_ERROR
                "'flex' lexical parser not found. Cannot build scotch.")
        ENDIF(NOT FLEX)
37
        MARK_AS_ADVANCED(FLEX)
38

39 40 41
        # Note that scotch is compiled in the source-tree, so we unpack the
        # source code in the ThirdParty builds directory.
        SET(SCOTCH_SRC ${TPBUILD}/scotch-6.0.0/src)
42

Dave Moxey's avatar
Dave Moxey committed
43 44 45
        IF (APPLE)
            SET(SCOTCH_MAKE Makefile.inc.i686_mac_darwin8)
            SET(SCOTCH_LDFLAGS "")
Dave Moxey's avatar
Dave Moxey committed
46
            SET(SCOTCH_CFLAGS "-O3 -Drestrict=__restrict -DCOMMON_PTHREAD -DCOMMON_RANDOM_FIXED_SEED -DCOMMON_TIMING_OLD -DSCOTCH_PTHREAD -DSCOTCH_RENAME -DCOMMON_PTHREAD_BARRIER")
47
        ELSE ()
Dave Moxey's avatar
Dave Moxey committed
48 49
            IF (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
                SET(SCOTCH_MAKE Makefile.inc.x86-64_pc_linux2)
Dave Moxey's avatar
Dave Moxey committed
50
                SET(SCOTCH_CFLAGS "-O3 -DCOMMON_FILE_COMPRESS_GZ -DCOMMON_PTHREAD -DCOMMON_RANDOM_FIXED_SEED -DSCOTCH_RENAME -DSCOTCH_PTHREAD -Drestrict=__restrict -DIDXSIZE64")
Dave Moxey's avatar
Dave Moxey committed
51 52
            ELSE ()
                SET(SCOTCH_MAKE Makefile.inc.i686_pc_linux2)
Dave Moxey's avatar
Dave Moxey committed
53
                SET(SCOTCH_CFLAGS "-O3 -DCOMMON_FILE_COMPRESS_GZ -DCOMMON_PTHREAD -DCOMMON_RANDOM_FIXED_SEED -DSCOTCH_RENAME -DSCOTCH_PTHREAD -Drestrict=__restrict")
Dave Moxey's avatar
Dave Moxey committed
54 55
            ENDIF ()
            SET(SCOTCH_LDFLAGS "-lz -lm -lrt -lpthread")
56 57
        ENDIF ()

58 59 60 61 62
        INCLUDE(ExternalProject)
        EXTERNALPROJECT_ADD(
            scotch-6.0.0
            PREFIX ${TPSRC}
            URL ${TPURL}/scotch_6.0.0.tar.gz
63
            URL_MD5 "ba117428c0a6cd97d0c93e8b872bb3fe"
64
            STAMP_DIR ${TPBUILD}/stamp
65
            DOWNLOAD_DIR ${TPSRC}
66 67 68 69
            SOURCE_DIR ${TPBUILD}/scotch-6.0.0
            BINARY_DIR ${TPBUILD}/scotch-6.0.0
            TMP_DIR ${TPBUILD}/scotch-6.0.0-tmp
            INSTALL_DIR ${TPDIST}
70 71 72 73
            CONFIGURE_COMMAND rm -f ${SCOTCH_SRC}/Makefile.inc
                COMMAND ln -s
                ${SCOTCH_SRC}/Make.inc/${SCOTCH_MAKE}
                ${SCOTCH_SRC}/Makefile.inc
74
            BUILD_COMMAND $(MAKE) -C ${SCOTCH_SRC}
Dave Moxey's avatar
Dave Moxey committed
75
                "CFLAGS=${SCOTCH_CFLAGS}"
Dave Moxey's avatar
Dave Moxey committed
76
                "LDFLAGS=${SCOTCH_LDFLAGS}"
77
                "CLIBFLAGS=-fPIC" scotch
78 79
            INSTALL_COMMAND $(MAKE) -C ${SCOTCH_SRC}
                prefix=${TPDIST} install
80
        )
Dave Moxey's avatar
Dave Moxey committed
81 82

        SET(SCOTCH_LIBRARY scotch CACHE FILEPATH
83
            "Scotch library" FORCE)
Dave Moxey's avatar
Dave Moxey committed
84
        SET(SCOTCHERR_LIBRARY scotcherr CACHE FILEPATH
85
            "Scotch error library" FORCE)
Dave Moxey's avatar
Dave Moxey committed
86 87 88
        SET(SCOTCH_INCLUDE_DIR ${TPDIST}/include CACHE FILEPATH
            "Scotch include directory" FORCE)

89
        LINK_DIRECTORIES(${TPDIST}/lib)
Dave Moxey's avatar
Dave Moxey committed
90 91 92

        MESSAGE(STATUS "Build Scotch: ${TPDIST}/lib/lib${SCOTCH_LIBRARY}.a")
        SET(SCOTCH_CONFIG_INCLUDE_DIR ${TPINC})
93
    ELSE (THIRDPARTY_BUILD_SCOTCH)
94
        ADD_CUSTOM_TARGET(scotch-6.0.0 ALL)
Dave Moxey's avatar
Dave Moxey committed
95 96
        MESSAGE(STATUS "Found Scotch: ${SCOTCH_LIBRARY}")
        SET(SCOTCH_CONFIG_INCLUDE_DIR ${SCOTCH_INCLUDE_DIR})
97
    ENDIF (THIRDPARTY_BUILD_SCOTCH)
Dave Moxey's avatar
Dave Moxey committed
98 99 100 101 102 103 104

    INCLUDE_DIRECTORIES(${SCOTCH_INCLUDE_DIR})

    MARK_AS_ADVANCED(SCOTCH_LIBRARY)
    MARK_AS_ADVANCED(SCOTCHERR_LIBRARY)
    MARK_AS_ADVANCED(SCOTCH_INCLUDE_DIR)
ENDIF()