From d2435ba81cc98244ba845142a798fd913c172c89 Mon Sep 17 00:00:00 2001 From: Liu Yiqun Date: Tue, 29 Aug 2017 20:08:00 +0800 Subject: [PATCH] Disable the finding of python, swig related packages completely when WITH_PYTHON and WITH_SWIG_PY are set to OFF. --- cmake/external/python.cmake | 27 ++++++++++++--------------- cmake/external/swig.cmake | 4 ++++ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cmake/external/python.cmake b/cmake/external/python.cmake index 53ef7cd29..46c68cce3 100644 --- a/cmake/external/python.cmake +++ b/cmake/external/python.cmake @@ -12,16 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -INCLUDE(ExternalProject) +IF(NOT WITH_PYTHON) + return() +ENDIF() + INCLUDE(python_module) -FIND_HOST_PACKAGE(PythonInterp 2.7) -IF(WITH_PYTHON) - FIND_HOST_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}) -ENDIF(WITH_PYTHON) +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}) SET(py_env "") IF(PYTHONINTERP_FOUND) @@ -29,16 +30,12 @@ IF(PYTHONINTERP_FOUND) find_python_module(numpy REQUIRED) find_python_module(wheel REQUIRED) find_python_module(google.protobuf REQUIRED) - FIND_HOST_PACKAGE(NumPy REQUIRED) + FIND_PACKAGE(NumPy REQUIRED) IF(${PY_GOOGLE.PROTOBUF_VERSION} AND ${PY_GOOGLE.PROTOBUF_VERSION} VERSION_LESS "3.0.0") MESSAGE(FATAL_ERROR "Found Python Protobuf ${PY_GOOGLE.PROTOBUF_VERSION} < 3.0.0, " "please use pip to upgrade protobuf. pip install -U protobuf") ENDIF() ENDIF(PYTHONINTERP_FOUND) -IF(WITH_PYTHON) - INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIR}) - INCLUDE_DIRECTORIES(${PYTHON_NUMPY_INCLUDE_DIR}) -ELSE() - SET(PYTHON_LIBRARIES "") -ENDIF() +INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIR}) +INCLUDE_DIRECTORIES(${PYTHON_NUMPY_INCLUDE_DIR}) diff --git a/cmake/external/swig.cmake b/cmake/external/swig.cmake index 744c766ee..ce088ae7e 100644 --- a/cmake/external/swig.cmake +++ b/cmake/external/swig.cmake @@ -12,6 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +IF(NOT WITH_SWIG_PY) + return() +ENDIF() + FIND_PACKAGE(SWIG) IF(NOT SWIG_FOUND) -- GitLab