Home | History | Annotate | Download | only in python
      1 find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
      2 
      3 INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
      4 
      5 include_directories(
      6   ${CMAKE_CURRENT_SOURCE_DIR}/..
      7   ${PYTHON_INCLUDE_DIRS}
      8 )
      9 
     10 set_source_files_properties (mraa.i PROPERTIES CPLUSPLUS ON)
     11 set_source_files_properties (mraa.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src")
     12 swig_add_module (python-mraa python mraa.i ${mraa_LIB_SRCS})
     13 swig_link_libraries (python-mraa ${PYTHON_LIBRARIES} ${mraa_LIBS})
     14 
     15 if (DOXYGEN_FOUND)
     16   foreach (_file ${DOCCLASSES})
     17     add_dependencies (${SWIG_MODULE_python-mraa_REAL_NAME} ${_file}class_doc_i)
     18   endforeach ()
     19   add_dependencies (${SWIG_MODULE_python-mraa_REAL_NAME} common_hpp_doc_i)
     20 
     21   add_custom_target (pydoc
     22     pydoc -w ${CMAKE_CURRENT_BINARY_DIR}/mraa.py ${CMAKE_CURRENT_BINARY_DIR}/
     23     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
     24     COMMENT "Generating API documentation with pydoc" VERBATIM
     25   )
     26 endif ()
     27 
     28 set_target_properties (${SWIG_MODULE_python-mraa_REAL_NAME} PROPERTIES
     29   OUTPUT_NAME _mraa
     30   COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIGPYTHON=${SWIG_FOUND}"
     31 )
     32 
     33 execute_process (
     34    COMMAND ${PYTHON_EXECUTABLE} -c
     35        "import site, sys; sys.stdout.write(site.PREFIXES[-1])"
     36    OUTPUT_VARIABLE PYTHON_PREFIX
     37 )
     38 file (TO_CMAKE_PATH "${PYTHON_PREFIX}" PYTHON_PREFIX)
     39 execute_process (
     40    COMMAND ${PYTHON_EXECUTABLE} -c
     41        "import site, sys; sys.stdout.write(site.getusersitepackages().replace(site.getuserbase(), site.PREFIXES[-1]))"
     42    OUTPUT_VARIABLE PYTHON_SITE_DIR
     43 )
     44 file (TO_CMAKE_PATH "${PYTHON_SITE_DIR}" PYTHON_SITE_DIR)
     45 string (REGEX REPLACE "^${PYTHON_PREFIX}/" ""
     46    PYTHON_SITE_DIR "${PYTHON_SITE_DIR}")
     47 
     48 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_mraa.so
     49          ${CMAKE_CURRENT_BINARY_DIR}/mraa.py
     50          DESTINATION ${PYTHON_SITE_DIR})
     51 
     52 add_subdirectory (docs)
     53