From 9c6e91b97a63c8085263c3e5e0513ec133763884 Mon Sep 17 00:00:00 2001 From: Andres Noetzli Date: Wed, 4 May 2022 13:54:41 -0700 Subject: [PATCH] Improve finding Python library/includes (#8718) On macOS, find_package(PythonLibs ...) does not find the Python include directory or library when they were installed via homebrew. find_package(Python ...) is more robust, but only available on newer versions of CMake. If we are compiling cvc5 on macOS and we have a newer version of CMake available, this tries to use find_package(Python ...) to find the paths. --- src/api/python/CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/api/python/CMakeLists.txt b/src/api/python/CMakeLists.txt index b5c7b917b..eb9d6ec31 100644 --- a/src/api/python/CMakeLists.txt +++ b/src/api/python/CMakeLists.txt @@ -44,6 +44,20 @@ endif() list(APPEND CMAKE_MODULE_PATH ${SKBUILD_CMAKE_MODULE_PATH}) find_package(PythonExtensions REQUIRED) + +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND + CMAKE_VERSION VERSION_GREATER_EQUAL "3.12") + # On macOS, find_package(PythonLibs ...) does not find the Python include + # directory or library when they were installed via homebrew. + # find_package(Python ...) is more robust, but only available on newer + # versions of CMake. If we are compiling cvc5 on macOS and we have a newer + # version of CMake available, we try to use find_package(Python ...) to find + # the paths. + find_package(Python COMPONENTS Development) + set(PYTHON_INCLUDE_DIRS "${Python_INCLUDE_DIRS}") + set(PYTHON_LIBRARY "${Python_LIBRARIES}") +endif() + find_package(Cython 0.29 REQUIRED) set(CYTHON_FLAGS "-X embedsignature=True") -- 2.30.2