diff --git a/CMake/mitkMacroInstallPython.cmake b/CMake/mitkMacroInstallPython.cmake index 3956daf8b3..89c588ca42 100644 --- a/CMake/mitkMacroInstallPython.cmake +++ b/CMake/mitkMacroInstallPython.cmake @@ -1,152 +1,151 @@ #! This CMake macro installs the python runtime with #! all python related libraries and toolkits. Py files are #! searched one by one with a globbing expression to generate a list used #! by the mac and NSIS installer. #! #! params: #! _python_libs Returns a list of the installed libraries. Used to fixup the bundle. #! _python_dirs Returns a list with the directories containig the dependencies #! to the installed libs. #! _app_bundle App bundle name in case of a Apple bundle. #! macro(mitkMacroInstallPython _python_libs _python_dirs _app_bundle) # find package sets the python version numbers find_package(PythonLibs REQUIRED) find_package(PythonInterp REQUIRED) # set the destination bundle set(_destination bin) if(APPLE) set(_destination ${_app_bundle}) endif() if(UNIX) # apple and linux only supports .so as loadable extension set(PYTHON_LIB_SUFFIX .so) + set(_py_include_postfix python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/) set(_python_runtime_dir lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}) else(WIN32) # windows only supports pyd as loadable extension set(PYTHON_LIB_SUFFIX .pyd) + set(_py_include_postfix ) set(_python_runtime_dir Lib) endif() # install OpenCV python wrapping if(MITK_USE_OpenCV) list(APPEND _python_libs "cv2${PYTHON_LIB_SUFFIX}") if(UNIX) install(FILES "${OpenCV_DIR}/lib/cv2${PYTHON_LIB_SUFFIX}" DESTINATION ${_destination}) else() install(FILES "${OpenCV_DIR}/lib/Release/cv2${PYTHON_LIB_SUFFIX}" DESTINATION ${_destination}) endif() if(UNIX AND NOT APPLE) install(CODE "file(RPATH_REMOVE FILE \"\${CMAKE_INSTALL_PREFIX}/bin/cv2${CMAKE_SHARED_LIBRARY_SUFFIX}\")") endif() list(APPEND _python_dirs "${OpenCV_DIR}/lib") endif() # install VTK python wrapping find_package(VTK REQUIRED) set(_VTK_PYTHON_TARGETS ) # find all vtk python wrapped targets foreach(_lib ${VTK_LIBRARIES}) # exclude system libs if(${_lib} MATCHES "^vtk.+") # use only python wrapped modules ( targets end with PythonD ) if(TARGET ${_lib}PythonD) list(APPEND _VTK_PYTHON_TARGETS ${_lib}Python) endif() endif() endforeach() # install the python modules and loaders foreach(_target ${_VTK_PYTHON_TARGETS}) # get the properties of the python wrapped target if( CMAKE_BUILD_TYPE STREQUAL "Debug") get_target_property(_target_lib "${_target}D" IMPORTED_LOCATION_DEBUG) else() get_target_property(_target_lib "${_target}D" IMPORTED_LOCATION_RELEASE) endif() get_filename_component(_filepath "${_target_lib}" PATH) install(FILES "${_filepath}/${_target}${PYTHON_LIB_SUFFIX}" DESTINATION ${_destination}) if(UNIX AND NOT APPLE ) install(CODE "file(RPATH_REMOVE FILE \"\${CMAKE_INSTALL_PREFIX}/bin/${_target}${PYTHON_LIB_SUFFIX}\")") endif() list(APPEND _python_libs "${_target}${PYTHON_LIB_SUFFIX}") endforeach() # install vtk python. This folder contains all *.py and # *.pyc files for VTK module loading. # glob through all files, NSIS can't use directories file(GLOB_RECURSE item RELATIVE "${VTK_DIR}/Wrapping/Python/vtk" "${VTK_DIR}/Wrapping/Python/vtk/*.py*") foreach(f ${item}) get_filename_component(_filepath "${f}" PATH) install(FILES "${VTK_DIR}/Wrapping/Python/vtk/${f}" DESTINATION ${_destination}/Python/vtk/${_filepath}) endforeach() list(APPEND _python_dirs "${VTK_DIR}/lib") # install the python runtime from the superbuild if(NOT MITK_USE_SYSTEM_PYTHON) if(UNIX) list(APPEND _python_dirs "${Python_DIR}/lib") else() #WIN32 list(APPEND _python_dirs "${Python_DIR}/libs") list(APPEND _python_dirs "${Python_DIR}/bin") endif() file(GLOB_RECURSE item RELATIVE "${Python_DIR}/${_python_runtime_dir}" "${Python_DIR}/${_python_runtime_dir}/*") foreach(f ${item}) get_filename_component(_filepath "${f}" PATH) install(FILES "${Python_DIR}/${_python_runtime_dir}/${f}" DESTINATION ${_destination}/Python/${_python_runtime_dir}/${_filepath}) endforeach() - file(GLOB_RECURSE item RELATIVE "${Python_DIR}/include" "${Python_DIR}/include/*") - foreach(f ${item}) - get_filename_component(_filepath "${f}" PATH) - install(FILES "${Python_DIR}/include/${f}" DESTINATION ${_destination}/Python/include/${_filepath}) - endforeach() + # config will by read out at runtime + install(FILES "${Python_DIR}/include/${_py_include_postfix}pyconfig.h" DESTINATION ${_destination}/Python/include/${_py_include_postfix}) - # add simple itk python wrapping file to the dependency list + # add simple itk python wrapping file to the dependency list to resolve linked libraries file(GLOB_RECURSE item RELATIVE "${Python_DIR}/${_python_runtime_dir}" "${Python_DIR}/${_python_runtime_dir}/_SimpleITK${PYTHON_LIB_SUFFIX}") foreach(f ${item}) list(APPEND _python_libs "Python/${_python_runtime_dir}/${f}") if(UNIX AND NOT APPLE) install(CODE "file(RPATH_REMOVE FILE \"\${CMAKE_INSTALL_PREFIX}/bin/Python/${_python_runtime_dir}/${f}\")") endif() endforeach() else() # Deploy the SimpleITK egg into the MITK installer set(_sitk_userbase_install ${SimpleITK_DIR}/Wrapping/PythonPackage/${_python_runtime_dir}/site-packages) # install everything in the userbase into Python/SimpleITK file(GLOB_RECURSE item RELATIVE "${_sitk_userbase_install}" "${_sitk_userbase_install}/*") foreach(f ${item}) get_filename_component(_filepath "${f}" PATH) install(FILES "${_sitk_userbase_install}/${f}" DESTINATION ${_destination}/Python/SimpleITK/${_filepath}) endforeach() # find and add the _SimpleITK library to the dependencies file(GLOB_RECURSE item RELATIVE "${_sitk_userbase_install}" "${_sitk_userbase_install}/_SimpleITK${PYTHON_LIB_SUFFIX}") foreach(f ${item}) list(APPEND _python_libs "Python/SimpleITK/${f}") if(UNIX AND NOT APPLE) install(CODE "file(RPATH_REMOVE FILE \"\${CMAKE_INSTALL_PREFIX}/bin/Python/SimpleITK/${f}\")") endif() endforeach() endif() list(REMOVE_DUPLICATES _python_dirs) endMacro() diff --git a/CMakeExternals/SimpleITK.cmake b/CMakeExternals/SimpleITK.cmake index a949a85244..7106705fb1 100644 --- a/CMakeExternals/SimpleITK.cmake +++ b/CMakeExternals/SimpleITK.cmake @@ -1,125 +1,125 @@ #----------------------------------------------------------------------------- # SimpleITK #----------------------------------------------------------------------------- if(MITK_USE_SimpleITK) # Sanity checks if(DEFINED SimpleITK_DIR AND NOT EXISTS ${SimpleITK_DIR}) message(FATAL_ERROR "SimpleITK_DIR variable is defined but corresponds to non-existing directory") endif() set(proj SimpleITK) set(proj_DEPENDENCIES ITK GDCM Swig) if(MITK_USE_OpenCV) list(APPEND proj_DEPENDENCIES OpenCV) endif() set(SimpleITK_DEPENDS ${proj}) if(NOT DEFINED SimpleITK_DIR) set(additional_cmake_args ) list(APPEND additional_cmake_args -DWRAP_CSHARP:BOOL=OFF -DWRAP_TCL:BOOL=OFF -DWRAP_LUA:BOOL=OFF -DWRAP_PYTHON:BOOL=OFF -DWRAP_JAVA:BOOL=OFF ) if(MITK_USE_Python) list(APPEND additional_cmake_args -DWRAP_PYTHON:BOOL=ON -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} -DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} -DPYTHON_INCLUDE_DIR2:PATH=${PYTHON_INCLUDE_DIR2} -DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY} ) if(NOT MITK_USE_SYSTEM_PYTHON) list(APPEND proj_DEPENDENCIES Python) endif() else(MITK_USE_Python) list(APPEND additional_cmake_args -DWRAP_PYTHON:BOOL=OFF ) endif() #TODO: Installer and testing works only with static libs on MAC set(_build_shared ON) if(APPLE) set(_build_shared OFF) endif() set(SimpleITK_PATCH_COMMAND ${CMAKE_COMMAND} -DTEMPLATE_FILE:FILEPATH=${MITK_SOURCE_DIR}/CMakeExternals/EmptyFileForPatching.dummy -P ${MITK_SOURCE_DIR}/CMakeExternals/PatchSimpleITK.cmake) ExternalProject_Add(${proj} - URL "https://dl.dropboxusercontent.com/u/8367205/ExternalProjects/SimpleITK.tar.gz" - URL_MD5 "7cfa5d0ff79a540f4bcfaf992abe44d2" + URL "https://dl.dropboxusercontent.com/u/8367205/ExternalProjects/SimpleITK-0.8.0.tar.gz" + URL_MD5 "d98f2e5442228e324ef62111febc7446" #GIT_TAG "493f15f5cfc620413d0aa7bb705ffe6d038a41b5" SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}-src BINARY_DIR ${proj}-build PREFIX ${proj}-cmake INSTALL_DIR ${proj}-install PATCH_COMMAND ${SimpleITK_PATCH_COMMAND} CMAKE_ARGS ${ep_common_args} # -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON CMAKE_CACHE_ARGS ${additional_cmake_args} -DBUILD_SHARED_LIBS:BOOL=${_build_shared} -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/${proj}-install -DCMAKE_INSTALL_NAME_DIR:STRING=/lib -DSimpleITK_BUILD_DISTRIBUTE:BOOL=ON -DSimpleITK_PYTHON_THREADS:BOOL=ON -DUSE_SYSTEM_ITK:BOOL=ON -DBUILD_TESTING:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF -DGDCM_DIR:PATH=${GDCM_DIR} -DITK_DIR:PATH=${ITK_DIR} -DSWIG_DIR:PATH=${SWIG_DIR} -DSWIG_EXECUTABLE:FILEPATH=${SWIG_EXECUTABLE} DEPENDS ${proj_DEPENDENCIES} ) set(SimpleITK_DIR ${CMAKE_CURRENT_BINARY_DIR}/${proj}-build) if( MITK_USE_Python ) # Build python distribution with easy install. If a own runtime is used # embedd the egg into the site-package folder of the runtime if(NOT MITK_USE_SYSTEM_PYTHON) ExternalProject_Add_Step(${proj} sitk_python_install_step COMMAND ${PYTHON_EXECUTABLE} setup.py install --prefix=${Python_DIR} DEPENDEES build WORKING_DIRECTORY ${SimpleITK_DIR}/Wrapping/PythonPackage ) # Build egg into custom user base folder and deploy it later into installer # https://pythonhosted.org/setuptools/easy_install.html#use-the-user-option-and-customize-pythonuserbase else() set(_userbase_install ${SimpleITK_DIR}/Wrapping/PythonPackage/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages) if(WIN32) set(_userbase_install ${SimpleITK_DIR}/Wrapping/PythonPackage/Lib/site-packages) endif() ExternalProject_Add_Step(${proj} sitk_create_userbase_step COMMAND ${CMAKE_COMMAND} -E make_directory ${_userbase_install} DEPENDEES build WORKING_DIRECTORY ${SimpleITK_DIR}/Wrapping/PythonPackage ) ExternalProject_Add_Step(${proj} sitk_python_install_step COMMAND PYTHONUSERBASE=${SimpleITK_DIR}/Wrapping/PythonPackage ${PYTHON_EXECUTABLE} setup.py install --user DEPENDEES sitk_create_userbase_step WORKING_DIRECTORY ${SimpleITK_DIR}/Wrapping/PythonPackage ) endif() endif() else() mitkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}") endif() endif()