summaryrefslogtreecommitdiff
path: root/src/api/python/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/python/CMakeLists.txt')
-rw-r--r--src/api/python/CMakeLists.txt37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/api/python/CMakeLists.txt b/src/api/python/CMakeLists.txt
index 166a728de..1998954e5 100644
--- a/src/api/python/CMakeLists.txt
+++ b/src/api/python/CMakeLists.txt
@@ -23,7 +23,7 @@ add_custom_target(
"${PYTHON_EXECUTABLE}"
"${CMAKE_CURRENT_LIST_DIR}/genkinds.py"
--kinds-header "${PROJECT_SOURCE_DIR}/src/api/cvc4cppkind.h"
- --kinds-file-prefix "cvc4kinds"
+ --kinds-file-prefix "${CMAKE_CURRENT_BINARY_DIR}/cvc4kinds"
DEPENDS
genkinds.py
COMMENT
@@ -39,4 +39,37 @@ add_library(pycvc4
target_link_libraries(pycvc4 cvc4 ${PYTHON_LIBRARIES})
python_extension_module(pycvc4)
-install(TARGETS pycvc4 DESTINATION lib)
+
+# Installation based on https://bloerg.net/2012/11/10/cmake-and-distutils.html
+# Create a wrapper python directory and generate a distutils setup.py file
+configure_file(setup.py.in setup.py)
+set(PYCVC4_MODULE "${CMAKE_CURRENT_BINARY_DIR}/pycvc4")
+file(MAKE_DIRECTORY "${PYCVC4_MODULE}")
+file(WRITE ${PYCVC4_MODULE}/__init__.py
+"import sys
+from .pycvc4 import *
+# fake a submodule for dotted imports, e.g. from pycvc4.kinds import *
+sys.modules['%s.%s'%(__name__, kinds.__name__)] = kinds")
+
+set(PYCVC4_LOC "${PYCVC4_MODULE}/$<TARGET_FILE_NAME:pycvc4>")
+add_custom_command(TARGET pycvc4 POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_FILE:pycvc4> ${PYCVC4_LOC}
+)
+
+# figure out if we're in a virtualenv
+execute_process(OUTPUT_VARIABLE IN_VIRTUALENV
+ COMMAND
+ "${PYTHON_EXECUTABLE}"
+ -c
+ "from __future__ import print_function; import os;
+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
+if ("${IN_VIRTUALENV}" STREQUAL "NO")
+ set(INSTALL_CMD "${INSTALL_CMD} --prefix=${CMAKE_INSTALL_PREFIX}")
+endif()
+
+message("Python bindings install command: ${INSTALL_CMD}")
+
+install(CODE "execute_process(COMMAND ${INSTALL_CMD})" FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback