112 lines
4.5 KiB
CMake
112 lines
4.5 KiB
CMake
|
|
# This is a CMake example for Python
|
|
|
|
INCLUDE(NewUseSWIG)
|
|
|
|
if (PYTHONLIBS_FOUND)
|
|
|
|
include(FindPythonModule)
|
|
file(RELATIVE_PATH RELATIVE_SOURCE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
|
|
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
|
|
|
|
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/CXX")
|
|
|
|
SET_SOURCE_FILES_PROPERTIES(../yap.i PROPERTIES CPLUSPLUS ON)
|
|
SET_SOURCE_FILES_PROPERTIES(../yap.i PROPERTIES SWIG_FLAGS "-O;-py3")
|
|
SET_SOURCE_FILES_PROPERTIES(../yap.i PROPERTIES SWIG_MODULE_NAME yap)
|
|
SET_SOURCE_FILES_PROPERTIES(../yap.i PROPERTIES OUTPUT_NAME yap)
|
|
|
|
|
|
SWIG_ADD_LIBRARY(Py2YAP LANGUAGE python SHARED SOURCES ../yap.i )
|
|
if (WIN32)
|
|
SWIG_LINK_LIBRARIES(Py2YAP YAPPython libYap ${PYTHON_LIBRARIES} )
|
|
else()
|
|
SWIG_LINK_LIBRARIES( Py2YAP libYap YAP++ YAPPython ${PYTHON_LIBRARIES} )
|
|
endif()
|
|
set_target_properties ( ${SWIG_MODULE_Py2YAP_REAL_NAME}
|
|
PROPERTIES
|
|
NO_SONAME ON
|
|
OUTPUT_NAME _yap
|
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" )
|
|
# inform we are compiling YAP
|
|
# s used in MSYS
|
|
|
|
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print( sysconfig.get_path( 'platlib' ) )"
|
|
OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
configure_file("setup.py.cmake" ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
|
|
|
|
get_filename_component(ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE)
|
|
file(RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH})
|
|
#
|
|
# set ( PYTHON_MODULE_PATH
|
|
# ${ABS_PYTHON_MODULE_PATH}
|
|
# )
|
|
#
|
|
# INSTALL ( FILES ${CMAKE_CURRENT_BINARY_DIR}/yap.py DESTINATION ${PYTHON_MODULE_PATH} )
|
|
# INSTALL ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/yapi.py DESTINATION ${PYTHON_MODULE_PATH} )
|
|
# INSTALL ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/yapi.yap DESTINATION ${libpl} )
|
|
#
|
|
#
|
|
# INSTALL ( TARGETS ${SWIG_MODULE_Py2YAP_REAL_NAME}
|
|
# RUNTIME DESTINATION ${PYTHON_MODULE_PATH}
|
|
# ARCHIVE DESTINATION ${PYTHON_MODULE_PATH}
|
|
# LIBRARY DESTINATION ${PYTHON_MODULE_PATH}
|
|
# )
|
|
|
|
add_custom_target(Py2YAP ALL
|
|
DEPENDS ../yap.i libYap YAP++ YAPPython _Py2YAP
|
|
)
|
|
|
|
set (dlls $<TARGET_FILE:matrix>
|
|
$<TARGET_FILE:regexp>
|
|
$<TARGET_FILE:yap_rl>
|
|
$<TARGET_FILE:tries>
|
|
$<TARGET_FILE:itries>
|
|
$<TARGET_FILE:sys>
|
|
$<TARGET_FILE:yap_random>)
|
|
if (TARGET real)
|
|
list( APPEND dlls $<TARGET_FILE:real>
|
|
)
|
|
endif()
|
|
|
|
add_custom_command(TARGET Py2YAP
|
|
POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory yap4py/os
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory yap4py/pl
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py ${dlls} $<TARGET_FILE:libYap> $<TARGET_FILE:YAPPython> $<TARGET_FILE:YAP++> ${CMAKE_CURRENT_SOURCE_DIR}/yapi.yap ${pl_library} ${CMAKE_CURRENT_BINARY_DIR}/yap4py
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${pl_os_library} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/os
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${pl_boot_library} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/pl
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_CURRENT_SOURCE_DIR}/MANIFEST.in ${CMAKE_CURRENT_BINARY_DIR}
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/yapi.py ${CMAKE_CURRENT_BINARY_DIR}/yap4py
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} setup.py sdist bdist_wheel
|
|
VERBATIM
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
)
|
|
|
|
if (WITH_DOCS AND DOXYGEN_FOUND)
|
|
|
|
set(CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
|
|
|
|
# Run doxygen to only generate the xml
|
|
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/doc
|
|
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile.xml
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers}
|
|
)
|
|
|
|
# generate .i from doxygen .xml
|
|
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i
|
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n
|
|
${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml
|
|
${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i
|
|
DEPENDS ${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml
|
|
)
|
|
add_custom_target(doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i)
|
|
add_dependencies(${SWIG_MODULE_ftdi1_REAL_NAME} doc_i)
|
|
|
|
ENDIF ()
|
|
ENDIF ()
|