From d5a475f24486ac7313fbb1f68baf6c530bbf61f1 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Mon, 3 Apr 2017 21:43:12 +0200 Subject: [PATCH] ARROW-763: C++: Use to find libpythonX.X.dylib --- cpp/cmake_modules/FindPythonLibsNew.cmake | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cpp/cmake_modules/FindPythonLibsNew.cmake b/cpp/cmake_modules/FindPythonLibsNew.cmake index 3e248a93342c..dfe5661b015b 100644 --- a/cpp/cmake_modules/FindPythonLibsNew.cmake +++ b/cpp/cmake_modules/FindPythonLibsNew.cmake @@ -148,10 +148,20 @@ if(CMAKE_HOST_WIN32) set(PYTHON_LIBRARY "${PYTHON_PREFIX}/libs/libpython${PYTHON_LIBRARY_SUFFIX}.a") endif() elseif(APPLE) - # In Python C extensions on OS X, the flag "-undefined dynamic_lookup" can - # avoid certain kinds of dynamic linking issues with portable binaries, so - # you should avoid targeting libpython at link time if at all possible - set(PYTHON_LIBRARY "${PYTHON_PREFIX}/lib/libpython${PYTHON_LIBRARY_SUFFIX}.dylib") + # In some cases libpythonX.X.dylib is not part of the PYTHON_PREFIX and we + # need to call `python-config --prefix` to determine the correct location. + + find_program(PYTHON_CONFIG python-config + NO_CMAKE_SYSTEM_PATH) + if (PYTHON_CONFIG) + execute_process( + COMMAND "${PYTHON_CONFIG}" "--prefix" + OUTPUT_VARIABLE PYTHON_CONFIG_PREFIX + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(PYTHON_LIBRARY "${PYTHON_CONFIG_PREFIX}/lib/libpython${PYTHON_LIBRARY_SUFFIX}.dylib") + else() + set(PYTHON_LIBRARY "${PYTHON_PREFIX}/lib/libpython${PYTHON_LIBRARY_SUFFIX}.dylib") + endif() else() if(${PYTHON_SIZEOF_VOID_P} MATCHES 8) set(_PYTHON_LIBS_SEARCH "${PYTHON_PREFIX}/lib64" "${PYTHON_PREFIX}/lib" "${PYTHON_LIBRARY_PATH}")