Commit acfab3cf authored by jcfr's avatar jcfr
Browse files

COMP: Use ctkMacroCompilePythonScript instead of Slicer_compile_python_scripts

git-svn-id: http://svn.slicer.org/Slicer4/trunk@15376 3bd1e089-480b-0410-8dfb-8563597acbee
parent 474375ed
......@@ -26,7 +26,7 @@ IF(Slicer_USE_PYTHONQT_WITH_TCL)
)
ENDIF()
Slicer_compile_python_scripts(
ctkMacroCompilePythonScript(
TARGET_NAME slicer
SCRIPTS "${Slicer_PYTHON_SCRIPTS}"
RESOURCES "${Slicer_PYTHON_RESOURCES}"
......
#
# Based on ParaView/VTK/Utilities/vtkTclTest2Py/CMakeLists.txt and
# ParaView/VTK/Wrapping/Python/CMakeLists.txt
#
MACRO(Slicer_compile_python_scripts)
SLICER_PARSE_ARGUMENTS(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)
# Sanity checks
FOREACH(varname TARGET_NAME SCRIPTS DESTINATION_DIR;INSTALL_DIR)
IF(NOT DEFINED MY_${varname})
MESSAGE(SEND_ERROR "${varname} is mandatory")
ENDIF()
ENDFOREACH()
set(copied_files)
set(copied_python_files)
FOREACH(file ${MY_SCRIPTS})
SET(src "${CMAKE_CURRENT_SOURCE_DIR}/${file}.py")
SET(tgt "${MY_DESTINATION_DIR}/${file}.py")
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 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_${MY_TARGET_NAME}_python_scripts.py")
# Generate compile_${MY_TARGET_NAME}_python_scripts.py
FILE(WRITE ${compile_all_script} "
#
# Generated by Slicer_compile_python_scripts CMAKE macro
#
# Based on paraview/VTK/Wrapping/Python/compile_all_vtk.py.in
import compileall
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 Slicer_compile_python_scripts 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 ${CMAKE_COMMAND} -P ${compile_all_cmake_script}
DEPENDS ${copied_python_files} ${compile_all_script}
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/python_compile_${MY_TARGET_NAME}_complete"
COMMENT "Compiling python scripts: ${MY_TARGET_NAME}"
)
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()
......@@ -448,11 +448,6 @@ IF(Slicer_USE_QT)
INCLUDE(${CTK_USE_FILE})
# Update CMake module path
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CTK_CMAKE_UTILITIES_DIR})
IF(Slicer_USE_PYTHONQT)
SET(PYTHONQT_INSTALL_DIR ${CTK_PYTHONQT_INSTALL_DIR})
LINK_DIRECTORIES(${PYTHONQT_INSTALL_DIR}/lib)
INCLUDE(${CTK_CMAKE_DIR}/ctkMacroWrapPythonQt.cmake)
ENDIF()
ENDIF()
#-----------------------------------------------------------------------------
......@@ -463,8 +458,12 @@ IF(Slicer_USE_QT)
IF(NOT VTK_WRAP_PYTHON)
MESSAGE(FATAL_ERROR "Since both Slicer_USE_QT and Slicer_USE_PYTHONQT are ON, VTK_WRAP_PYTHON is expected to be ON. Disable Slicer_USE_PYTHONQT or re-configure VTK with python wrapping.")
ENDIF()
# Include convenient script allowing to copy and compile python scripts
INCLUDE(${Slicer_CMAKE_DIR}/SlicerCompilePythonScripts.cmake)
SET(PYTHONQT_INSTALL_DIR ${CTK_PYTHONQT_INSTALL_DIR})
LINK_DIRECTORIES(${PYTHONQT_INSTALL_DIR}/lib)
INCLUDE(${CTK_CMAKE_DIR}/ctkMacroWrapPythonQt.cmake)
INCLUDE(${CTK_CMAKE_DIR}/ctkMacroCompilePythonScript.cmake)
# Enable qMRMLWidgets python wrapping
SET(qMRMLWidgets_WRAP_PYTHON OFF)
ENDIF()
......
......@@ -4,7 +4,7 @@ SET(displayableManager_PYTHON_SCRIPTS
mrmlDisplayableManager/vtkScriptedExampleDisplayableManager
)
Slicer_compile_python_scripts(
ctkMacroCompilePythonScript(
TARGET_NAME mrmlDisplayableManager
SCRIPTS "${displayableManager_PYTHON_SCRIPTS}"
DESTINATION_DIR ${Slicer_BINARY_DIR}/bin/Python
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment