swig.cmake 2.5 KB
Newer Older
L
liaogang 已提交
1
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
2
#
L
liaogang 已提交
3 4 5
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
6
#
L
liaogang 已提交
7
# http://www.apache.org/licenses/LICENSE-2.0
8
#
L
liaogang 已提交
9 10 11 12 13 14
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

15 16 17 18
IF(NOT WITH_SWIG_PY)
    return()
ENDIF()

L
liaogang 已提交
19
FIND_PACKAGE(SWIG)
L
liaogang 已提交
20

L
liaogang 已提交
21 22 23
IF(NOT SWIG_FOUND)
    # build swig as an external project
    INCLUDE(ExternalProject)
L
liaogang 已提交
24

Y
Yu Yang 已提交
25 26
    SET(SWIG_SOURCES_DIR ${THIRD_PARTY_PATH}/swig)
    SET(SWIG_INSTALL_DIR ${THIRD_PARTY_PATH}/install/swig)
L
liaogang 已提交
27 28 29
    SET(SWIG_TARGET_VERSION "3.0.2")
    SET(SWIG_DOWNLOAD_SRC_MD5 "62f9b0d010cef36a13a010dc530d0d41")
    SET(SWIG_DOWNLOAD_WIN_MD5 "3f18de4fc09ab9abb0d3be37c11fbc8f")
L
liaogang 已提交
30

L
liaogang 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    IF(WIN32)
        # swig.exe available as pre-built binary on Windows:
        ExternalProject_Add(swig
            URL                 http://prdownloads.sourceforge.net/swig/swigwin-${SWIG_TARGET_VERSION}.zip
            URL_MD5             ${SWIG_DOWNLOAD_WIN_MD5}
            SOURCE_DIR          ${SWIG_SOURCES_DIR}
            CONFIGURE_COMMAND   ""
            BUILD_COMMAND       ""
            INSTALL_COMMAND     ""
            UPDATE_COMMAND      ""
        )
        SET(SWIG_DIR ${SWIG_SOURCES_DIR} CACHE FILEPATH "SWIG Directory" FORCE)
        SET(SWIG_EXECUTABLE ${SWIG_SOURCES_DIR}/swig.exe  CACHE FILEPATH "SWIG Executable" FORCE)
    ELSE(WIN32)
        # swig uses bison find it by cmake and pass it down
        FIND_PACKAGE(BISON)
L
liaogang 已提交
47

L
liaogang 已提交
48 49 50 51 52
        # From SWIG configure
        ExternalProject_Add(swig
            GIT_REPOSITORY      https://github.com/swig/swig.git
            GIT_TAG             rel-3.0.10
            PREFIX              ${SWIG_SOURCES_DIR}
L
liaogang 已提交
53 54 55 56 57
            CONFIGURE_COMMAND   cd <SOURCE_DIR> && ./autogen.sh && ./configure
                                --prefix=${SWIG_INSTALL_DIR} --without-pcre
            BUILD_COMMAND       cd <SOURCE_DIR> && make
            INSTALL_COMMAND     cd <SOURCE_DIR> && make install
            UPDATE_COMMAND      ""
L
liaogang 已提交
58
        )
L
liaogang 已提交
59

L
liaogang 已提交
60 61 62 63 64 65
        SET(SWIG_DIR ${SWIG_INSTALL_DIR}/share/swig/${SWIG_TARGET_VERSION})
        SET(SWIG_EXECUTABLE ${SWIG_INSTALL_DIR}/bin/swig)
    ENDIF(WIN32)

    LIST(APPEND external_project_dependencies swig)
ENDIF(NOT SWIG_FOUND)