From 1133315746eb3661abf1fdf7853ce4dd9e201387 Mon Sep 17 00:00:00 2001 From: Robert Nishihara Date: Mon, 11 Jul 2016 12:16:10 -0700 Subject: [PATCH] help cmake find right python interpreter on mac (#251) --- CMakeLists.txt | 22 ++++++++++++---------- cmake/Modules/FindNumPy.cmake | 6 +++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20ccd7733..c5921f72d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,15 +8,17 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules) set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/thirdparty/grpc/bins/opt/" ${CMAKE_PREFIX_PATH}) -find_package(PythonInterp REQUIRED) - if(NOT APPLE) + find_package(PythonInterp REQUIRED) find_package(PythonLibs REQUIRED) -else(NOT APPLE) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c - "import sys; skip = 2 if sys.platform.startswith('win') else 1; print 'python' + sys.version[0:3:skip]" + set(CUSTOM_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) +else() + find_program(CUSTOM_PYTHON_EXECUTABLE python) + message("-- Found Python program: ${CUSTOM_PYTHON_EXECUTABLE}") + execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c + "import sys; print 'python' + sys.version[0:3]" OUTPUT_VARIABLE PYTHON_LIBRARY_NAME OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c + execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "import sys; print sys.exec_prefix" OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE) FIND_LIBRARY(PYTHON_LIBRARIES @@ -24,18 +26,18 @@ else(NOT APPLE) HINTS "${PYTHON_PREFIX}" PATH_SUFFIXES "lib" "libs" NO_DEFAULT_PATH) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c + execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print get_python_inc()" OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE) if(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS) SET(PYTHONLIBS_FOUND TRUE) message("-- Found PythonLibs: " ${PYTHON_LIBRARIES}) message("-- -- Used custom search path") - else(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS) + else() find_package(PythonLibs REQUIRED) message("-- -- Used find_package(PythonLibs)") - endif(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS) -endif(NOT APPLE) + endif() +endif() find_package(NumPy REQUIRED) find_package(Boost REQUIRED) diff --git a/cmake/Modules/FindNumPy.cmake b/cmake/Modules/FindNumPy.cmake index 6e1f3c415..0b9fb3e5c 100644 --- a/cmake/Modules/FindNumPy.cmake +++ b/cmake/Modules/FindNumPy.cmake @@ -14,8 +14,8 @@ unset(NUMPY_VERSION) unset(NUMPY_INCLUDE_DIR) -if(PYTHONINTERP_FOUND) - execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" +if(NOT "${CUSTOM_PYTHON_EXECUTABLE}" STREQUAL "CUSTOM_PYTHON_EXECUTABLE-NOTFOUND") + execute_process(COMMAND "${CUSTOM_PYTHON_EXECUTABLE}" "-c" "import numpy as n; print(n.__version__); print(n.get_include());" RESULT_VARIABLE __result OUTPUT_VARIABLE __output @@ -42,7 +42,7 @@ if(PYTHONINTERP_FOUND) endif() endif() else() - message(STATUS "To find NumPy Python interpretator is required to be found.") + message(STATUS "To find NumPy Python executable is required to be found.") endif() include(FindPackageHandleStandardArgs)