Warning, /games/kajongg/cmake-modules/KDEPython.cmake is written in an unsupported language. File is not indexed.
0001 # KDE_Python 0002 # 0003 # defines macros for installing python files in a KDE project: 0004 # * KDE_INSTALL_PYTHON_FILES 0005 # * KDE_ADD_PYTHON_EXECUTABLE 0006 # 0007 # By Wolfgang Rohdewald <wolfgang@rohdewald.de> 0008 # 0009 # copied and adapted from 0010 # FindPyKDE4.cmake by Simon Edwards <simon@simonzone.com> 0011 # PythonMacros.cmake by Simon Edwards and others 0012 # 0013 # removed support for windows and Python2 0014 0015 0016 ########################################################################### 0017 # PYTHON_INSTALL (SOURCE_FILE DESTINATION_DIR) 0018 # 0019 # Install the SOURCE_FILE, which is a Python .py file, into the 0020 # destination directory during install. The file will be byte compiled 0021 # and both the .py file and the file in __pycache__ will be installed. 0022 # Neither Windows nor Python2 is supported. 0023 0024 set(PYTHON_MACROS_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) 0025 0026 macro(PYTHON_INSTALL SOURCE_FILE DESTINATION_DIR) 0027 0028 find_file(_python_compile_py PythonCompile.py PATHS ${CMAKE_MODULE_PATH}) 0029 0030 # Install the source file. 0031 install(FILES ${SOURCE_FILE} DESTINATION ${DESTINATION_DIR}) 0032 0033 # Byte compile and install the .pyc file, unless explicitly prevented by env.. 0034 if("$ENV{PYTHONDONTWRITEBYTECODE}" STREQUAL "") 0035 get_filename_component(_absfilename ${SOURCE_FILE} ABSOLUTE) 0036 get_filename_component(_filename ${SOURCE_FILE} NAME) 0037 get_filename_component(_filenamebase ${SOURCE_FILE} NAME_WE) 0038 get_filename_component(_basepath ${SOURCE_FILE} PATH) 0039 file(RELATIVE_PATH _relativefilename ${CMAKE_SOURCE_DIR} ${_absfilename}) 0040 0041 set(_bin_py ${CMAKE_CURRENT_BINARY_DIR}/${_basepath}/${_filename}) 0042 0043 set(_bin_pyc "${CMAKE_CURRENT_BINARY_DIR}/${_basepath}/__pycache__/${_filenamebase}.cpython-${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}.pyc") 0044 set(_py_install_dir "${DESTINATION_DIR}/__pycache__/") 0045 0046 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_basepath}) 0047 0048 # Setting because it will be displayed later, in compile_python_files 0049 set(_message "Byte-compiling ${_bin_py} to ${_bin_pyc}") 0050 0051 string(REPLACE "/" "_" _rule_name "${_relativefilename}_rule") 0052 string(REPLACE " " "_" _rule_name "${_rule_name}") 0053 add_custom_target("${_rule_name}" ALL) 0054 0055 get_filename_component(_abs_bin_py ${_bin_py} ABSOLUTE) 0056 if(_abs_bin_py STREQUAL _absfilename) # Don't copy the file onto itself. 0057 add_custom_command( 0058 TARGET "${_rule_name}" 0059 COMMAND "${CMAKE_COMMAND}" -E echo "${_message}" 0060 COMMAND "${PYTHON_EXECUTABLE}" "${_python_compile_py}" "--destination-dir" "${DESTINATION_DIR}" "${_bin_py}" 0061 DEPENDS "${_absfilename}" 0062 ) 0063 else() 0064 add_custom_command( 0065 TARGET "${_rule_name}" 0066 COMMAND "${CMAKE_COMMAND}" -E echo "${_message}" 0067 COMMAND "${CMAKE_COMMAND}" -E copy "${_absfilename}" "${_bin_py}" 0068 COMMAND "${PYTHON_EXECUTABLE}" "${_python_compile_py}" "--destination-dir" "${DESTINATION_DIR}" "${_bin_py}" 0069 DEPENDS "${_absfilename}" 0070 ) 0071 endif() 0072 0073 install(FILES ${_bin_pyc} DESTINATION "${_py_install_dir}") 0074 unset(_py_install_dir) 0075 unset(_message) 0076 0077 endif("$ENV{PYTHONDONTWRITEBYTECODE}" STREQUAL "") 0078 0079 endmacro(PYTHON_INSTALL) 0080 0081 0082 ########################################################################### 0083 # KDE_INSTALL_PYTHON_FILES(file_name...) 0084 # 0085 # Installs and bytes compiles Python files into the data directory for this 0086 # project.. 0087 # 0088 0089 MACRO(KDE_INSTALL_PYTHON_FILES) 0090 FOREACH (_current_file ${ARGN}) 0091 python_install(${_current_file} ${KDE_INSTALL_DATADIR}/${PROJECT_NAME}) 0092 ENDFOREACH (_current_file) 0093 ENDMACRO(KDE_INSTALL_PYTHON_FILES) 0094 0095 0096 ########################################################################### 0097 # KDE_ADD_PYTHON_EXECUTABLE(py_name exe_name) 0098 # 0099 # Creates a smybolic link with name exe_name at install time from the 0100 # install bin directory to the Python file. The Python file is also make 0101 # executable. 0102 # 0103 MACRO(KDE_ADD_PYTHON_EXECUTABLE _pyname _exename) 0104 if(NOT PROJECT_NAME) 0105 MESSAGE(STATUS "Project name is necessary to create symlink against python program!!! It will fail.") 0106 endif(NOT PROJECT_NAME) 0107 0108 set(TARGET ${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_DATADIR}/${PROJECT_NAME}/${_pyname}) 0109 set(LINK_NAME ${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_BINDIR}/${_exename}) 0110 0111 GET_FILENAME_COMPONENT(abs_link_name ${LINK_NAME} ABSOLUTE) 0112 GET_FILENAME_COMPONENT(link_path ${LINK_NAME} PATH) 0113 GET_FILENAME_COMPONENT(abs_link_path ${link_path} ABSOLUTE) 0114 GET_FILENAME_COMPONENT(abs_target ${TARGET} ABSOLUTE) 0115 0116 INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory \$ENV\{DESTDIR\}${abs_link_path})") 0117 INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink ${abs_target} \$ENV\{DESTDIR\}${abs_link_name})") 0118 INSTALL(CODE "EXECUTE_PROCESS(COMMAND chmod a+x \$ENV\{DESTDIR\}/${abs_target})") 0119 0120 ENDMACRO(KDE_ADD_PYTHON_EXECUTABLE)