blob: 01d919ece7dfd069f716ff3c8d74110d51326708 [file] [log] [blame]
#
# CMakeLists.txt for openwsman/bindings/python
#
#
# !!Attn!!: This creates two files
# 1. _pywsman.so
# 2. pywsman.py
# and the .py file gets imported. See bindings/python/tests.
#
enable_testing()
add_subdirectory(tests)
IF( BUILD_PYTHON3 )
set(Python_ADDITIONAL_VERSIONS 3.6 3.5 3.4)
ELSE( BUILD_PYTHON3 )
set(Python_ADDITIONAL_VERSIONS 2.7 2.6)
ENDIF( BUILD_PYTHON3 )
FIND_PACKAGE(PythonLibs)
IF (PYTHON_LIBRARY)
FIND_PACKAGE(PythonInterp REQUIRED)
#MESSAGE(STATUS "Found PythonLibs...")
FIND_PACKAGE(PythonLinkLibs)
#IF (PYTHON_LINK_LIBS)
# MESSAGE(STATUS "Building Python...")
#ENDIF (PYTHON_LINK_LIBS)
ELSE (PYTHON_LIBRARY)
MESSAGE(STATUS "No Python found")
ENDIF (PYTHON_LIBRARY)
EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))" OUTPUT_VARIABLE PYTHON_LIB_DIR)
STRING(REPLACE "\n" "" PYTHON_LIB_DIR "${PYTHON_LIB_DIR}")
MESSAGE(STATUS "Python executable: ${PYTHON_EXECUTABLE}")
MESSAGE(STATUS "Python lib dir: ${PYTHON_LIB_DIR}")
SET( SWIG_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/openwsman_wrap.c" )
ADD_CUSTOM_COMMAND (
OUTPUT ${SWIG_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E echo_append "Creating wrapper code for Python ..."
COMMAND ${SWIG_EXECUTABLE} -python -features autodoc -features autodoc -I${CMAKE_BINARY_DIR}/bindings -I${CMAKE_SOURCE_DIR}/bindings -I${CMAKE_SOURCE_DIR}/include -o ${SWIG_OUTPUT} ${SWIG_INPUT}
COMMAND ${CMAKE_COMMAND} -E echo "Done."
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../*.i
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.h
)
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" )
SET(pywsman_SRCS ${SWIG_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/../openwsman.c)
ADD_LIBRARY( pywsman ${pywsman_SRCS} )
SET_TARGET_PROPERTIES( pywsman PROPERTIES PREFIX "_" )
INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_DIRS} )
# RHEL5 needs this:
INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_PATH} )
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} )
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/bindings ${CMAKE_SOURCE_DIR}/include )
TARGET_LINK_LIBRARIES( pywsman wsman )
TARGET_LINK_LIBRARIES( pywsman wsman_client )
INSTALL(TARGETS pywsman LIBRARY DESTINATION ${PYTHON_LIB_DIR})
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/pywsman.py DESTINATION ${PYTHON_LIB_DIR} )