- IF(ext STREQUAL .py)
- # FILE TIMESTAMP command appears in cmake-2.8.11
- IF(${CMAKE_VERSION} VERSION_LESS "2.8.11")
- INSTALL(CODE "MESSAGE(STATUS \"py compiling ${CMAKE_INSTALL_PREFIX}/${path}/${file_name}\")")
- INSTALL(CODE "SET(CMD \"import py_compile ; py_compile.compile('${CMAKE_INSTALL_PREFIX}/${path}/${file_name}')\")")
- INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c \"\${CMD}\")")
- INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -O -c \"\${CMD}\")")
- ELSE(${CMAKE_VERSION} VERSION_LESS "2.8.11")
- GET_FILENAME_COMPONENT(file_we ${file_name} NAME_WE)
- INSTALL(CODE "SET(CMD \"import py_compile ; py_compile.compile('${CMAKE_INSTALL_PREFIX}/${path}/${file_name}')\")")
- INSTALL(CODE "FILE(TIMESTAMP \"${CMAKE_CURRENT_SOURCE_DIR}/${file}\" py_time)")
- INSTALL(CODE "FILE(TIMESTAMP \"${CMAKE_INSTALL_PREFIX}/${path}/${file_we}.pyc\" pyc_time)")
- INSTALL(CODE "FILE(TIMESTAMP \"${CMAKE_INSTALL_PREFIX}/${path}/${file_we}.pyo\" pyo_time)")
- #INSTALL(CODE "MESSAGE(STATUS \"\${py_time} \${pyc_time} \")")
- INSTALL(CODE "STRING(COMPARE LESS \${pyc_time} \${py_time} to_install_pyc)")
- INSTALL(CODE "STRING(COMPARE LESS \${pyo_time} \${py_time} to_install_pyo)")
- INSTALL(CODE "IF (\${to_install_pyc} OR \${to_install_pyo}) \n MESSAGE(STATUS \"py compiling ${CMAKE_INSTALL_PREFIX}/${path}/${file_name}\") \n ENDIF()")
- INSTALL(CODE "IF (\${to_install_pyc}) \n EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c \"\${CMD}\") \n ENDIF()")
- INSTALL(CODE "IF (\${to_install_pyo}) \n EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -O -c \"\${CMD}\") \n ENDIF()")
- ENDIF(${CMAKE_VERSION} VERSION_LESS "2.8.11")
+ GET_FILENAME_COMPONENT(we_ext ${file} NAME_WE)
+
+ IF(ext STREQUAL .py)
+ # Generate and install the pyc and pyo
+ # [ABN] Important: we avoid references or usage of CMAKE_INSTALL_PREFIX which is not correctly set
+ # when using CPack.
+ SET(_pyc_file "${CMAKE_CURRENT_BINARY_DIR}/${we_ext}.pyc")
+ SET(_pyo_file "${CMAKE_CURRENT_BINARY_DIR}/${we_ext}.pyo")
+ LIST(APPEND _all_pyc ${_pyc_file})
+ LIST(APPEND _all_pyo ${_pyo_file})
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${_pyc_file}
+ COMMAND ${PYTHON_EXECUTABLE} -c "import py_compile ; py_compile.compile('${_source_prefix}${file}', '${_pyc_file}' )"
+ DEPENDS ${PREFIX}${file}
+ VERBATIM
+ )
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${_pyo_file}
+ COMMAND ${PYTHON_EXECUTABLE} -O -c "import py_compile ; py_compile.compile('${_source_prefix}${file}', '${_pyo_file}' )"
+ DEPENDS ${PREFIX}${file}
+ VERBATIM
+ )
+ # Install the .pyo and the .pyc
+ INSTALL(FILES ${_pyc_file} DESTINATION ${path} PERMISSIONS ${PERMS})
+ INSTALL(FILES ${_pyo_file} DESTINATION ${path} PERMISSIONS ${PERMS})