提交 4abe68a915e4db4da5539d1ff977552f837037ac

作者 LJH 李佳桓
1 个父辈 7bb453be

add

正在显示 1 个修改的文件 包含 61 行增加0 行删除
  1 +# Python macros
  2 +# ~~~~~~~~~~~~~
  3 +# Copyright (c) 2007, Simon Edwards <simon@simonzone.com>
  4 +#
  5 +# Redistribution and use is allowed according to the terms of the BSD license.
  6 +# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
  7 +#
  8 +# This file defines the following macros:
  9 +#
  10 +# PYTHON_INSTALL (SOURCE_FILE DESTINATION_DIR)
  11 +# Install the SOURCE_FILE, which is a Python .py file, into the
  12 +# destination directory during install. The file will be byte compiled
  13 +# and both the .py file and .pyc file will be installed.
  14 +
  15 +GET_FILENAME_COMPONENT(PYTHON_MACROS_MODULE_PATH ${CMAKE_CURRENT_LIST_FILE} PATH)
  16 +
  17 +MACRO(PYTHON_INSTALL SOURCE_FILE DESTINATION_DIR)
  18 +
  19 + FIND_FILE(_python_compile_py PythonCompile.py PATHS ${CMAKE_MODULE_PATH})
  20 +
  21 +
  22 + # Install the source file.
  23 + INSTALL(FILES ${SOURCE_FILE} DESTINATION ${DESTINATION_DIR})
  24 +
  25 + # Byte compile and install the .pyc file.
  26 + GET_FILENAME_COMPONENT(_absfilename ${SOURCE_FILE} ABSOLUTE)
  27 + GET_FILENAME_COMPONENT(_filename ${SOURCE_FILE} NAME)
  28 + GET_FILENAME_COMPONENT(_filenamebase ${SOURCE_FILE} NAME_WE)
  29 + GET_FILENAME_COMPONENT(_basepath ${SOURCE_FILE} PATH)
  30 +
  31 + if(WIN32)
  32 + string(REGEX REPLACE ".:/" "/" _basepath "${_basepath}")
  33 + endif(WIN32)
  34 +
  35 + SET(_bin_py ${CMAKE_CURRENT_BINARY_DIR}/${_basepath}/${_filename})
  36 + SET(_bin_pyc ${CMAKE_CURRENT_BINARY_DIR}/${_basepath}/${_filenamebase}.pyc)
  37 +
  38 + FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_basepath})
  39 +
  40 + SET(_message "-DMESSAGE=Byte-compiling ${_bin_py}")
  41 +
  42 + GET_FILENAME_COMPONENT(_abs_bin_py ${_bin_py} ABSOLUTE)
  43 + IF(_abs_bin_py STREQUAL ${_absfilename}) # Don't copy the file onto itself.
  44 + ADD_CUSTOM_COMMAND(
  45 + TARGET compile_python_files
  46 + COMMAND ${CMAKE_COMMAND} -E echo ${message}
  47 + COMMAND ${PYTHON_EXECUTABLE} ${_python_compile_py} ${_bin_py}
  48 + DEPENDS ${_absfilename}
  49 + )
  50 + ELSE(_abs_bin_py STREQUAL ${_absfilename})
  51 + ADD_CUSTOM_COMMAND(
  52 + TARGET compile_python_files
  53 + COMMAND ${CMAKE_COMMAND} -E echo ${message}
  54 + COMMAND ${CMAKE_COMMAND} -E copy ${_absfilename} ${_bin_py}
  55 + COMMAND ${PYTHON_EXECUTABLE} ${_python_compile_py} ${_bin_py}
  56 + DEPENDS ${_absfilename}
  57 + )
  58 + ENDIF(_abs_bin_py STREQUAL ${_absfilename})
  59 +
  60 + INSTALL(FILES ${_bin_pyc} DESTINATION ${DESTINATION_DIR})
  61 +ENDMACRO(PYTHON_INSTALL)
... ...
注册登录 后发表评论