ctkMacroCompilePythonScript.cmake 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #
  2. # Based on ParaView/VTK/Utilities/vtkTclTest2Py/CMakeLists.txt and
  3. # ParaView/VTK/Wrapping/Python/CMakeLists.txt
  4. #
  5. MACRO(ctkMacroCompilePythonScript kit_name python_source_files dest_dir)
  6. FIND_PACKAGE(PythonInterp REQUIRED)
  7. SET(copied_python_files)
  8. FOREACH(file ${python_source_files})
  9. GET_FILENAME_COMPONENT(file_we "${CMAKE_CURRENT_SOURCE_DIR}/${file}" NAME_WE)
  10. SET(src "${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.py")
  11. SET(tgt "${dest_dir}/${file_we}.py")
  12. SET(copied_python_files ${copied_python_files} ${tgt})
  13. ADD_CUSTOM_COMMAND(DEPENDS ${src}
  14. COMMAND ${CMAKE_COMMAND} -E copy ${src} ${tgt}
  15. OUTPUT ${tgt}
  16. COMMENT "Copying ${file_we}")
  17. ENDFOREACH()
  18. # Byte compile the Python files.
  19. SET(compile_all_script "${CMAKE_CURRENT_BINARY_DIR}/compile_all_${kit_name}.py")
  20. # Based on paraview/VTK/Wrapping/Python/compile_all_vtk.py.in
  21. FILE(WRITE ${compile_all_script} "
  22. \# Auto-generated
  23. import compileall
  24. compileall.compile_dir('${dest_dir}')
  25. file = open('${CMAKE_CURRENT_BINARY_DIR}/${kit_name}_python_compile_complete', 'w')
  26. file.write('Done')
  27. ")
  28. ADD_CUSTOM_COMMAND(
  29. COMMAND ${PYTHON_EXECUTABLE} ${compile_all_script}
  30. DEPENDS ${copied_python_files} ${compile_all_script}
  31. OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${kit_name}_python_compile_complete"
  32. COMMENT "Compiling ${kit_name} python files"
  33. )
  34. ADD_CUSTOM_TARGET(${kit_name}_pyc ALL
  35. DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${kit_name}_python_compile_complete")
  36. # Install the slicer python module directory
  37. #INSTALL(DIRECTORY "${Slicer3_BINARY_DIR}/bin/Python"
  38. # DESTINATION "${Slicer3_INSTALL_BIN_DIR}" COMPONENT Runtime
  39. # USE_SOURCE_PERMISSIONS)
  40. ENDMACRO()