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)

M
minqiyang 已提交
21 22 23
FIND_PACKAGE(PythonInterp ${PY_VERSION})
FIND_PACKAGE(PythonLibs ${PY_VERSION})

24 25 26
# 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})
27

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

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