summaryrefslogtreecommitdiff
path: root/swig/python/CMakeLists.txt
blob: 284bcb09ce373d9a53a8f7de49865d451c84152f (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 PYTHON_SITEDIR)
  EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "from sys import stdout; from distutils import sysconfig; stdout.write(sysconfig.get_python_lib(1))" OUTPUT_VARIABLE PYTHON_SITEDIR)
ENDIF (NOT PYTHON_SITEDIR)

MESSAGE(STATUS "Python executable:   ${PYTHON_EXECUTABLE}")
MESSAGE(STATUS "Python include path: ${PYTHON_INCLUDE_PATH}")
MESSAGE(STATUS "Python site dir:     ${PYTHON_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 ${PYTHON_SITEDIR})
INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/zypp.py DESTINATION ${PYTHON_SITEDIR})