python.cmake 1.6 KB
Newer Older
L
liaogang 已提交
1
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
X
xuwei06 已提交
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
X
xuwei06 已提交
6
#
L
liaogang 已提交
7
# http://www.apache.org/licenses/LICENSE-2.0
X
xuwei06 已提交
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.

L
liaogang 已提交
15
INCLUDE(ExternalProject)
16 17 18
INCLUDE(python_module)

FIND_PACKAGE(PythonInterp 2.7)
19 20
IF(WITH_PYTHON)
    FIND_PACKAGE(PythonLibs 2.7)
21 22 23
    # Fixme: Maybe find a static library. Get SHARED/STATIC by FIND_PACKAGE.
    ADD_LIBRARY(python SHARED IMPORTED GLOBAL)
    SET_PROPERTY(TARGET python PROPERTY IMPORTED_LOCATION ${PYTHON_LIBRARIES})
24
ENDIF(WITH_PYTHON)
25

L
liaogang 已提交
26
SET(py_env "")
27
IF(PYTHONINTERP_FOUND)
28 29 30 31 32
    find_python_module(pip REQUIRED)
    find_python_module(numpy REQUIRED)
    find_python_module(wheel REQUIRED)
    find_python_module(google.protobuf REQUIRED)
    FIND_PACKAGE(NumPy REQUIRED)
R
reyoung 已提交
33
    IF(${PY_GOOGLE.PROTOBUF_VERSION} AND ${PY_GOOGLE.PROTOBUF_VERSION} VERSION_LESS "3.0.0")
L
liaogang 已提交
34
        MESSAGE(FATAL_ERROR "Found Python Protobuf ${PY_GOOGLE.PROTOBUF_VERSION} < 3.0.0, "
R
reyoung 已提交
35 36
        "please use pip to upgrade protobuf. pip install -U protobuf")
    ENDIF()
37
ENDIF(PYTHONINTERP_FOUND)
L
liaogang 已提交
38

39 40 41 42
IF(WITH_PYTHON)
    INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIR})
    INCLUDE_DIRECTORIES(${PYTHON_NUMPY_INCLUDE_DIR})
ELSE()
L
liaogang 已提交
43
    SET(PYTHON_LIBRARIES "")
L
liaogang 已提交
44
ENDIF()