Skip to content

Commit 590072c

Browse files
committed
[system] Find Python libs for OSX with python-config
1 parent 4ff2a87 commit 590072c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ EXEC_PROGRAM(
3939
)
4040

4141
IF (SC_GLOBAL_PYTHON_WRAPPER)
42-
FIND_PACKAGE(PythonLibs REQUIRED)
42+
IF (APPLE)
43+
FIND_PACKAGE(PythonLibsApple REQUIRED)
44+
ELSE (APPLE)
45+
FIND_PACKAGE(PythonLibs REQUIRED)
46+
ENDIF (APPLE)
4347
FIND_PACKAGE(PythonInterp REQUIRED)
4448
ENDIF (SC_GLOBAL_PYTHON_WRAPPER)
4549

@@ -85,7 +89,7 @@ IF (APPLE AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
8589
ELSEIF (UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
8690
SET (LINUX 1)
8791
ENDIF (APPLE AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
88-
92+
8993
# If gcc is installed add -wall and -pedantic to the commandline
9094
#
9195
IF (CMAKE_COMPILER_IS_GNUCC)

Modules/FindPythonLibsApple.cmake

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# the idea comes from here: https://github.com/commontk/PythonQt/issues/24#issuecomment-127639573
2+
# this overwrite is needed to avoid collision if python version an mac if homebrew python is used
3+
find_program(PYTHON_CONFIG_EXECUTABLE python-config)
4+
if (NOT PYTHON_CONFIG_EXECUTABLE)
5+
message(SEND_ERROR "python-config executable not found, but python is required.")
6+
endif()
7+
# using "python-config --prefix" so that cmake always uses
8+
# the python that is
9+
# in the user's path, this is a fix for homebrew on Mac:
10+
# https://github.com/Homebrew/homebrew/issues/25118
11+
execute_process(COMMAND ${PYTHON_CONFIG_EXECUTABLE} --prefix OUTPUT_VARIABLE python_prefix OUTPUT_STRIP_TRAILING_WHITESPACE)
12+
set(PYTHON_INCLUDE_DIR ${python_prefix}/include/python2.7 CACHE PATH "Path to where Python.h is found" FORCE)
13+
set(PYTHON_LIBRARY ${python_prefix}/lib/libpython2.7${CMAKE_SHARED_LIBRARY_SUFFIX} CACHE PATH "Path to where libpython2.7.dylib is found" FORCE)

0 commit comments

Comments
 (0)