python.cmake 1.5 KB
Newer Older
1
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
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.

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

19 20
INCLUDE(python_module)

21 22 23 24 25
FIND_PACKAGE(PythonInterp 2.7)
FIND_PACKAGE(PythonLibs 2.7)
# 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})
26

L
liaogang 已提交
27
SET(py_env "")
28
IF(PYTHONINTERP_FOUND)
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)
33
    FIND_PACKAGE(NumPy REQUIRED)
R
reyoung 已提交
34
    IF(${PY_GOOGLE.PROTOBUF_VERSION} AND ${PY_GOOGLE.PROTOBUF_VERSION} VERSION_LESS "3.0.0")
L
liaogang 已提交
35
        MESSAGE(FATAL_ERROR "Found Python Protobuf ${PY_GOOGLE.PROTOBUF_VERSION} < 3.0.0, "
R
reyoung 已提交
36 37
        "please use pip to upgrade protobuf. pip install -U protobuf")
    ENDIF()
38
ENDIF(PYTHONINTERP_FOUND)
L
liaogang 已提交
39

40 41
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${PYTHON_NUMPY_INCLUDE_DIR})