summaryrefslogtreecommitdiff
path: root/swig/python/CMakeLists.txt
blob: 3abf3134bf360bffa9ea6e7fb73d751f7fddfe76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#
# CMakeLists.txt for libzypp-bindings/swig/python
#
# !!Attn!!: This creates two files
#  1. zypp.so
#  2. zypp.py
# and the .py file gets imported.
#

ENABLE_TESTING()
ADD_SUBDIRECTORY(tests)

# SWIG_OUPUT is per-target

SET( SWIG_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libzypp_python.cc" )

FIND_PACKAGE(PythonInterp REQUIRED)
IF (NOT PYTHON3_SITEDIR)
  EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "from sys import stdout; import sysconfig; stdout.write(sysconfig.get_path('platlib'))" OUTPUT_VARIABLE PYTHON3_SITEDIR)
ENDIF (NOT PYTHON3_SITEDIR)

MESSAGE(STATUS "Python executable:   ${PYTHON_EXECUTABLE}")
MESSAGE(STATUS "Python include path: ${PYTHON_INCLUDE_PATH}")
MESSAGE(STATUS "Python site dir:     ${PYTHON3_SITEDIR}")

ADD_CUSTOM_COMMAND (
   OUTPUT  ${SWIG_OUTPUT}
   COMMAND ${CMAKE_COMMAND} -E echo_append "Creating wrapper code for python..."
   COMMAND ${SWIG_EXECUTABLE} -v ${SWIG_DEFINITIONS} -c++ -python  -o ${SWIG_OUTPUT} -I${ZYPP_INCLUDE_DIR} ${SWIG_INPUT}
   COMMAND ${CMAKE_COMMAND} -E echo "Done."
   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../*.i ${CMAKE_CURRENT_SOURCE_DIR}/../*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.i
)

ADD_LIBRARY( zypp_python SHARED ${SWIG_OUTPUT} )
SET_TARGET_PROPERTIES( zypp_python
  PROPERTIES
    PREFIX ""
    OUTPUT_NAME _zypp
)

INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_PATH} )
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/swig )
INCLUDE_DIRECTORIES( ${ZYPP_INCLUDE_DIR} )
TARGET_LINK_LIBRARIES( zypp_python ${ZYPP_LIBRARY} )

INSTALL(TARGETS zypp_python LIBRARY DESTINATION ${PYTHON3_SITEDIR})
INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/zypp.py DESTINATION ${PYTHON3_SITEDIR})