summaryrefslogtreecommitdiff
path: root/src/api/python/CMakeLists.txt
diff options
context:
space:
mode:
authormakaimann <makaim@stanford.edu>2021-05-21 00:20:30 -0400
committerGitHub <noreply@github.com>2021-05-21 04:20:30 +0000
commit84fdf87a74a7104a0eccaf7a817597b086c3afa9 (patch)
treebf082fc1d5636bff214ab47eb8d5b3fb1d082720 /src/api/python/CMakeLists.txt
parent4268c75087e2bb68dbb2257d99e062a8cc897f8c (diff)
Use scikit-build CMake files for pycvc5 (#6543)
This PR removes copied CMake files for the pycvc5 Cython target, and instead adds a dependency on scikit-build (where those CMake files originated anyway). This keeps us up to date with fixes. Furthermore, the PR switches from distutils to the more modern setuptools. This does add another dependency but it's a fairly reasonable one. setuptools is not part of the base Python distribution, but my understanding is that it is now the de facto standard, and most package managers install it automatically with Python. The main motivation for switching is in preparation for building wheels. This PR is a piece of this old one (#5657) which I am closing and splitting up.
Diffstat (limited to 'src/api/python/CMakeLists.txt')
-rw-r--r--src/api/python/CMakeLists.txt38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/api/python/CMakeLists.txt b/src/api/python/CMakeLists.txt
index c6686e32b..27e36f538 100644
--- a/src/api/python/CMakeLists.txt
+++ b/src/api/python/CMakeLists.txt
@@ -19,6 +19,36 @@ if(POLICY CMP0057)
cmake_policy(SET CMP0057 NEW)
endif()
+# Check that scikit-build is installed
+# Provides CMake files for Python bindings
+check_python_module("skbuild" "scikit-build")
+
+# setuptools for installing the module
+check_python_module("setuptools")
+
+# Find cmake modules distributed with scikit-build
+# They are distributed under <scikit-build directory>/resources/cmake
+execute_process(
+ COMMAND
+ ${PYTHON_EXECUTABLE} -c "from __future__ import print_function; \
+ import os; import skbuild; \
+ cmake_module_path=os.path.join(os.path.dirname(skbuild.__file__), \
+ 'resources', 'cmake'); print(cmake_module_path, end='')"
+ OUTPUT_VARIABLE
+ SKBUILD_CMAKE_MODULE_PATH
+ RESULT_VARIABLE
+ RET_SKBUILD_CMAKE_MODULE_PATH
+)
+
+if (NOT EXISTS ${SKBUILD_CMAKE_MODULE_PATH})
+ message(FATAL_ERROR "Expected CMake module path from
+ scikit-build at ${SKBUILD_CMAKE_MODULE_PATH}")
+endif()
+
+# Add scikit-build cmake files to cmake module path
+# Required for Cython target below
+list(APPEND CMAKE_MODULE_PATH ${SKBUILD_CMAKE_MODULE_PATH})
+
find_package(PythonExtensions REQUIRED)
find_package(Cython 0.29 REQUIRED)
@@ -98,8 +128,14 @@ print('YES' if 'VIRTUAL_ENV' in os.environ else 'NO', end='')")
set(INSTALL_CMD
"${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install")
# if we're in a virtualenv, we install it in the virtualenv lib location
+# otherwise install in site-packages
+# option --single-version-externally-managed prevents it from being
+# an .egg distribution and --record records the list of installed files
if ("${IN_VIRTUALENV}" STREQUAL "NO")
- set(INSTALL_CMD "${INSTALL_CMD} --prefix=${CMAKE_INSTALL_PREFIX}")
+ set(INSTALL_CMD "${INSTALL_CMD}
+ --prefix=${CMAKE_INSTALL_PREFIX}
+ --single-version-externally-managed
+ --record=pycvc5-installed-files.txt")
endif()
message("Python bindings install command: ${INSTALL_CMD}")
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback