|
@@ -5,49 +5,125 @@
|
|
|
# ParaView/VTK/Wrapping/Python/CMakeLists.txt
|
|
|
#
|
|
|
|
|
|
-MACRO(ctkMacroCompilePythonScript kit_name python_source_files dest_dir)
|
|
|
+INCLUDE(${CTK_CMAKE_DIR}/ctkMacroParseArguments.cmake)
|
|
|
|
|
|
+MACRO(ctkMacroCompilePythonScript)
|
|
|
+ ctkMacroParseArguments(MY
|
|
|
+ "TARGET_NAME;SCRIPTS;RESOURCES;DESTINATION_DIR;INSTALL_DIR"
|
|
|
+ ""
|
|
|
+ ${ARGN}
|
|
|
+ )
|
|
|
+
|
|
|
FIND_PACKAGE(PythonInterp REQUIRED)
|
|
|
+ FIND_PACKAGE(PythonLibs REQUIRED)
|
|
|
+
|
|
|
+ # Extract python lib path
|
|
|
+ get_filename_component(PYTHON_LIBRARY_PATH ${PYTHON_LIBRARY} PATH)
|
|
|
|
|
|
- SET(copied_python_files)
|
|
|
+ # Sanity checks
|
|
|
+ FOREACH(varname TARGET_NAME SCRIPTS DESTINATION_DIR;INSTALL_DIR)
|
|
|
+ IF(NOT DEFINED MY_${varname})
|
|
|
+ MESSAGE(SEND_ERROR "${varname} is mandatory")
|
|
|
+ ENDIF()
|
|
|
+ ENDFOREACH()
|
|
|
|
|
|
- FOREACH(file ${python_source_files})
|
|
|
- GET_FILENAME_COMPONENT(file_we "${CMAKE_CURRENT_SOURCE_DIR}/${file}" NAME_WE)
|
|
|
- SET(src "${CMAKE_CURRENT_SOURCE_DIR}/${file_we}.py")
|
|
|
- SET(tgt "${dest_dir}/${file_we}.py")
|
|
|
+ set(copied_files)
|
|
|
+ set(copied_python_files)
|
|
|
+ FOREACH(file ${MY_SCRIPTS})
|
|
|
+ # Append "py" extension if needed
|
|
|
+ get_filename_component(file_ext ${file} EXT)
|
|
|
+ IF(NOT "${file_ext}" MATCHES "py")
|
|
|
+ SET(file "${file}.py")
|
|
|
+ ENDIF()
|
|
|
+
|
|
|
+ SET(src "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
|
|
|
+ SET(tgt "${MY_DESTINATION_DIR}/${file}")
|
|
|
+ IF(IS_ABSOLUTE ${file})
|
|
|
+ SET(src ${file})
|
|
|
+ file(RELATIVE_PATH tgt_file ${CMAKE_CURRENT_BINARY_DIR} ${file})
|
|
|
+ SET(tgt "${MY_DESTINATION_DIR}/${tgt_file}")
|
|
|
+ ENDIF()
|
|
|
+
|
|
|
SET(copied_python_files ${copied_python_files} ${tgt})
|
|
|
+ SET(copied_files ${copied_files} ${tgt})
|
|
|
ADD_CUSTOM_COMMAND(DEPENDS ${src}
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${src} ${tgt}
|
|
|
OUTPUT ${tgt}
|
|
|
- COMMENT "Copying ${file_we}")
|
|
|
+ COMMENT "Copying python script: ${file}.py")
|
|
|
ENDFOREACH()
|
|
|
+
|
|
|
+ IF(DEFINED MY_RESOURCES)
|
|
|
+ FOREACH(file ${MY_RESOURCES})
|
|
|
+ SET(src "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
|
|
|
+ SET(tgt "${MY_DESTINATION_DIR}/${file}")
|
|
|
+ SET(copied_files ${copied_files} ${tgt})
|
|
|
+ ADD_CUSTOM_COMMAND(DEPENDS ${src}
|
|
|
+ COMMAND ${CMAKE_COMMAND} -E copy ${src} ${tgt}
|
|
|
+ OUTPUT ${tgt}
|
|
|
+ COMMENT "Copying python resource: ${file}")
|
|
|
+ ENDFOREACH()
|
|
|
+
|
|
|
+ ADD_CUSTOM_TARGET(Copy${MY_TARGET_NAME}PythonFiles
|
|
|
+ ALL
|
|
|
+ DEPENDS ${copied_files})
|
|
|
+ ENDIF()
|
|
|
+
|
|
|
|
|
|
# Byte compile the Python files.
|
|
|
- SET(compile_all_script "${CMAKE_CURRENT_BINARY_DIR}/compile_all_${kit_name}.py")
|
|
|
+ SET(compile_all_script "${CMAKE_CURRENT_BINARY_DIR}/compile_${MY_TARGET_NAME}_python_scripts.py")
|
|
|
|
|
|
- # Based on paraview/VTK/Wrapping/Python/compile_all_vtk.py.in
|
|
|
+ # Generate compile_${MY_TARGET_NAME}_python_scripts.py
|
|
|
FILE(WRITE ${compile_all_script} "
|
|
|
-\# Auto-generated
|
|
|
+#
|
|
|
+# Generated by ctkMacroCompilePythonScript CMAKE macro
|
|
|
+#
|
|
|
+
|
|
|
+# Based on paraview/VTK/Wrapping/Python/compile_all_vtk.py.in
|
|
|
+
|
|
|
import compileall
|
|
|
-compileall.compile_dir('${dest_dir}')
|
|
|
-file = open('${CMAKE_CURRENT_BINARY_DIR}/${kit_name}_python_compile_complete', 'w')
|
|
|
+compileall.compile_dir('@MY_DESTINATION_DIR@')
|
|
|
+file = open('@CMAKE_CURRENT_BINARY_DIR@/python_compile_@MY_TARGET_NAME@_complete', 'w')
|
|
|
file.write('Done')
|
|
|
")
|
|
|
|
|
|
+ # Configure cmake script associated with the custom command
|
|
|
+ # required to properly update the library path with PYTHON_LIBRARY_PATH
|
|
|
+ SET(compile_all_cmake_script "${CMAKE_CURRENT_BINARY_DIR}/compile_${MY_TARGET_NAME}_python_scripts.cmake")
|
|
|
+ FILE(WRITE ${compile_all_cmake_script} "
|
|
|
+#
|
|
|
+# Generated by ctkMacroCompilePythonScript CMAKE macro
|
|
|
+#
|
|
|
+
|
|
|
+IF(WIN32)
|
|
|
+ SET(ENV{PATH} \"@PYTHON_LIBRARY_PATH@;\$ENV{PATH}\")
|
|
|
+ELSEIF(APPLE)
|
|
|
+ SET(ENV{DYLD_LIBRARY_PATH} \"@PYTHON_LIBRARY_PATH@:\$ENV{DYLD_LIBRARY_PATH}\")
|
|
|
+ELSE()
|
|
|
+ SET(ENV{LD_LIBRARY_PATH} \"@PYTHON_LIBRARY_PATH@:\$ENV{LD_LIBRARY_PATH}\")
|
|
|
+ENDIF()
|
|
|
+
|
|
|
+EXECUTE_PROCESS(
|
|
|
+ COMMAND \"@PYTHON_EXECUTABLE@\" \"@compile_all_script@\"
|
|
|
+ )
|
|
|
+")
|
|
|
+
|
|
|
ADD_CUSTOM_COMMAND(
|
|
|
- COMMAND ${PYTHON_EXECUTABLE} ${compile_all_script}
|
|
|
+ COMMAND ${CMAKE_COMMAND} -P ${compile_all_cmake_script}
|
|
|
DEPENDS ${copied_python_files} ${compile_all_script}
|
|
|
- OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${kit_name}_python_compile_complete"
|
|
|
- COMMENT "Compiling ${kit_name} python files"
|
|
|
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/python_compile_${MY_TARGET_NAME}_complete"
|
|
|
+ COMMENT "Compiling python scripts: ${MY_TARGET_NAME}"
|
|
|
)
|
|
|
-
|
|
|
- ADD_CUSTOM_TARGET(${kit_name}_pyc ALL
|
|
|
- DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${kit_name}_python_compile_complete")
|
|
|
-
|
|
|
-
|
|
|
- # Install the slicer python module directory
|
|
|
- #INSTALL(DIRECTORY "${Slicer3_BINARY_DIR}/bin/Python"
|
|
|
- # DESTINATION "${Slicer3_INSTALL_BIN_DIR}" COMPONENT Runtime
|
|
|
- # USE_SOURCE_PERMISSIONS)
|
|
|
|
|
|
+ ADD_CUSTOM_TARGET(Compile${MY_TARGET_NAME}PythonFiles ALL
|
|
|
+ DEPENDS
|
|
|
+ ${CMAKE_CURRENT_BINARY_DIR}/python_compile_${MY_TARGET_NAME}_complete
|
|
|
+ ${compile_all_script}
|
|
|
+ )
|
|
|
+
|
|
|
+ # Install python module directory
|
|
|
+ INSTALL(DIRECTORY "${MY_DESTINATION_DIR}"
|
|
|
+ DESTINATION "${MY_INSTALL_DIR}" COMPONENT Runtime
|
|
|
+ USE_SOURCE_PERMISSIONS)
|
|
|
+
|
|
|
ENDMACRO()
|
|
|
+
|