Permalink
Browse files

COMP: Update build-system to use CMake'ified python

Latest stable version 2.7.3 is now used instead of ancient 2.6.6

Directory layout has been updated:
 - Python-2.7.3   : source
 - python         : build system
 - python-build   : build tree
 - python-install : install tree

Associated external project has been simplified. Removed unneeded
custom configure, make and install steps. Also removed unneeded
patch steps.

Note that the pythonrun.h and pythonrun.c are still patched in order
to prevent crash (related to dll boundaries [1][2]) when building Slicer debug
against a released python.

[1] http://stackoverflow.com/questions/2322095/why-does-this-program-crash-passing-of-stdstring-between-dlls
[2] http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/57e0d522-a42c-4add-963d-c87c6e76f161

Since only library located in the "lib-dynload" folder are not duplicated
in the "site-packages" folder, removed the exclude pattern
from the fixup script and update the candidate pattern to consider the
python extension located in lib/python2.7/lib-dynload folder.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21863 3bd1e089-480b-0410-8dfb-8563597acbee
  • Loading branch information...
jcfr committed Apr 4, 2013
1 parent 7764534 commit 140d5f4e4163083b2714d5acbd9470f00b4e0573
@@ -193,7 +193,7 @@ set(CTEST_CUSTOM_WARNING_EXCEPTION
"Modules.(getpath|signalmodule).c.*warning: ignoring return value of.*declared with attribute warn_unused_result"
"Modules.expat.xmlparse.*warning.*discards qualifiers from pointer target type"
# Python - Mac
- "ranlib: file:.*libpython2.6.a.*has no symbols"
+ "ranlib: file:.*libpython2.7.a.*has no symbols"
"python.Modules._cursesmodule.c.*warning.*may be used uninitialized in this function"
"python.Mac.Modules.(cf|Nav).*warning: (cast|unused)"
"python.Modules._ctypes.*warning: function declaration isn't a prototype"
@@ -132,16 +132,20 @@ if(Slicer_USE_OpenIGTLink)
endif()
if(Slicer_USE_PYTHONQT)
- set(SLICER_PYTHONHOME ${Slicer_SUPERBUILD_DIR}/python-build)
- get_filename_component(SLICER_PYTHON_LIB_DIR ${PYTHON_LIBRARY} PATH)
+ set(SLICER_PYTHONHOME ${Slicer_SUPERBUILD_DIR}/python-install)
+ if(UNIX)
+ get_filename_component(SLICER_PYTHON_LIB_DIR ${PYTHON_LIBRARY} PATH)
+ else()
+ get_filename_component(SLICER_PYTHON_LIB_DIR ${PYTHON_EXECUTABLE} PATH)
+ endif()
list(APPEND SLICER_LIBRARY_PATHS_BUILD
${CTK_DIR}/PythonQt-build/<CMAKE_CFG_INTDIR>
${SLICER_PYTHON_LIB_DIR}
)
set(pythonpath_subdir lib/python${Slicer_PYTHON_VERSION_DOT})
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
- set(pythonpath_subdir "Lib")
+ set(pythonpath_subdir Lib)
endif()
endif()
@@ -198,19 +202,15 @@ if(Slicer_USE_PYTHONQT)
set(PYTHONPATH "<APPLAUNCHER_DIR>/bin/<CMAKE_CFG_INTDIR>")
set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/bin/Python")
set(PYTHONPATH "${PYTHONPATH}<PATHSEP>${SLICER_PYTHONHOME}/${pythonpath_subdir}")
+ set(PYTHONPATH "${PYTHONPATH}<PATHSEP>${SLICER_PYTHONHOME}/${pythonpath_subdir}/lib-dynload")
set(PYTHONPATH "${PYTHONPATH}<PATHSEP>${SLICER_PYTHONHOME}/${pythonpath_subdir}/site-packages")
if(Slicer_BUILD_QTLOADABLEMODULES)
set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/${Slicer_QTLOADABLEMODULES_LIB_DIR}/<CMAKE_CFG_INTDIR>")
set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/${Slicer_QTLOADABLEMODULES_PYTHON_LIB_DIR}")
endif()
- # On unix-like system, setting PYTHONHOME is enough to have the following path automatically
- # appended to PYTHONPATH: ../lib/pythonX.Y.zip, ../lib/pythonX.Y/,
- # and ../lib/pythonX.Y/{lib-tk, lib-old, lib-dynload}
- # See http://docs.python.org/c-api/intro.html#embedding-python
- if(WIN32)
- set(PYTHONPATH "${PYTHONPATH}<PATHSEP>${SLICER_PYTHONHOME}/${pythonpath_subdir}")
+ if(Slicer_USE_PYTHONQT_WITH_TCL)
set(PYTHONPATH "${PYTHONPATH}<PATHSEP>${SLICER_PYTHONHOME}/${pythonpath_subdir}/lib-tk")
endif()
@@ -293,7 +293,7 @@ endif()
if(Slicer_USE_PYTHONQT)
set(pythonpath_subdir lib/python${Slicer_PYTHON_VERSION_DOT})
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
- set(pythonpath_subdir "Lib")
+ set(pythonpath_subdir Lib)
endif()
endif()
@@ -325,24 +325,17 @@ set(SLICER_ENVVARS_INSTALLED
)
if(Slicer_USE_PYTHONQT)
- set(pythonpath_subdir lib/python${Slicer_PYTHON_VERSION_DOT})
- if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
- set(pythonpath_subdir "Lib")
- endif()
set(PYTHONPATH "<APPLAUNCHER_DIR>/${Slicer_INSTALL_LIB_DIR}")
+ set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/lib/Python/${pythonpath_subdir}")
+ set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/lib/Python/${pythonpath_subdir}/lib-dynload")
set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/lib/Python/${pythonpath_subdir}/site-packages")
set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/${Slicer_INSTALL_QTSCRIPTEDMODULES_LIB_DIR}")
set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR}")
set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/lib/vtkTeem")
set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/bin/Python")
set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/${Slicer_QTLOADABLEMODULES_PYTHON_LIB_DIR}")
- # On unix-like system, setting PYTHONHOME is enough to have the following path automatically
- # appended to PYTHONPATH: ../lib/pythonX.Y.zip, ../lib/pythonX.Y/,
- # and ../lib/pythonX.Y/{lib-tk, lib-old, lib-dynload}
- # See http://docs.python.org/c-api/intro.html#embedding-python
- if(WIN32)
- set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/lib/Python/${pythonpath_subdir}")
+ if(Slicer_USE_PYTHONQT_WITH_TCL)
set(PYTHONPATH "${PYTHONPATH}<PATHSEP><APPLAUNCHER_DIR>/lib/Python/${pythonpath_subdir}/lib-tk")
endif()
@@ -3,32 +3,22 @@
# -------------------------------------------------------------------------
if(Slicer_USE_PYTHONQT)
+ set(python_lib_subdir /Lib/)
+ if(UNIX)
+ set(python_lib_subdir /lib/python2.7/)
+ endif()
+
get_filename_component(SUPER_BUILD_DIR "${Slicer_BINARY_DIR}" PATH)
- set(PYTHON_DIR "${SUPER_BUILD_DIR}/python-build")
+ set(PYTHON_DIR "${SUPER_BUILD_DIR}/python-install")
if(NOT EXISTS "${PYTHON_DIR}${python_lib_subdir}")
message(FATAL_ERROR "error: Failed to install Python ! - Unexistant directory PYTHON_DIR:${PYTHON_DIR}${python_lib_subdir}")
endif()
# Install libraries
- set(python_lib_subdir /Lib/)
- if(UNIX)
- set(python_lib_subdir /lib/python2.6/)
- endif()
set(extra_exclude_pattern)
if(UNIX)
- # Note:
- # * Libraries directly located under 'site-packages' directory are
- # duplicate of the library located under 'lib-dynload' directory.
- #
- # * On MacOSX, duplicate library are not properly fixed. Indeed, it's safe
- # to assume fixup_bundle identify each library by its name, a same library
- # being in both site-packages and lib-dynload will be fixed only once.
- #
- # * For convenience, let's exclude lib[-]dynload completely.
- #
- list(APPEND extra_exclude_pattern
- REGEX "lib[-]dynload.*" EXCLUDE
+ list(APPEND extra_exclude_pattern
REGEX "distutils/command/wininst-.*" EXCLUDE
)
endif()
@@ -40,7 +30,7 @@ if(Slicer_USE_PYTHONQT)
REGEX "lib2to3/" EXCLUDE
REGEX "lib[-]old/" EXCLUDE
REGEX "plat[-].*" EXCLUDE
- REGEX "test/" EXCLUDE
+ REGEX "/test/" EXCLUDE
REGEX "wsgiref*" EXCLUDE
${extra_exclude_pattern}
)
@@ -55,7 +45,7 @@ if(Slicer_USE_PYTHONQT)
endif()
elseif(WIN32)
get_filename_component(PYTHON_LIB_BASE ${PYTHON_LIBRARY} NAME_WE)
- get_filename_component(PYTHON_LIB_PATH ${PYTHON_LIBRARY} PATH)
+ get_filename_component(PYTHON_LIB_PATH ${PYTHON_EXECUTABLE} PATH)
install(FILES "${PYTHON_LIB_PATH}/${PYTHON_LIB_BASE}.dll"
DESTINATION bin
COMPONENT Runtime)
@@ -64,7 +54,7 @@ if(Slicer_USE_PYTHONQT)
# Install headers
set(python_include_subdir /Include/)
if(UNIX)
- set(python_include_subdir /include/python2.6/)
+ set(python_include_subdir /include/python2.7/)
endif()
install(FILES "${PYTHON_DIR}${python_include_subdir}/pyconfig.h"
@@ -172,7 +172,8 @@ function(fixup_bundle_with_plugins app)
list(APPEND candiates_pattern
"${app_dir}/Contents/@Slicer_LIB_DIR@/*Python.so"
"${app_dir}/Contents/@Slicer_LIB_DIR@/*PythonQt.so"
- "${app_dir}/Contents/lib/Python/lib/python2.6/site-packages/*.so"
+ "${app_dir}/Contents/lib/Python/lib/python2.7/site-packages/*.so"
+ "${app_dir}/Contents/lib/Python/lib/python2.7/lib-dynload/*.so"
)
endif()
@@ -22,41 +22,143 @@ set(proj python)
#message(STATUS "${__indent}Adding project ${proj}")
-set(python_base ${CMAKE_CURRENT_BINARY_DIR}/${proj})
-set(python_build ${CMAKE_CURRENT_BINARY_DIR}/${proj}-build)
#
# WARNING - If you consider updating the Python version, make sure the patch
# step associated with both window and unix are still valid !
#
-set(PYVER_SHORT 26)
-set(python_URL http://svn.slicer.org/Slicer3-lib-mirrors/trunk/Python-2.6.6.tgz)
-set(python_MD5 b2f209df270a33315e62c1ffac1937f0)
-# Since the solution file provided within "Python-2.6.6.tgz" is specific to VS2008, let's use
-# "Python-2.6.6-vc2010" where the solution file is converted for VS2010.
-# This is required because there is command-line tool to convert the solution automatically.
-if(CMAKE_GENERATOR MATCHES "Visual*" AND "${MSVC_VERSION}" VERSION_GREATER "1599")
- set(python_URL http://svn.slicer.org/Slicer3-lib-mirrors/trunk/Python-2.6.6-vc2010.tgz)
- set(python_MD5 120b65e3ab568d8861803be811707c79)
-endif()
-get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
+if(NOT DEFINED python_DIR)
+ #message(STATUS "${__indent}Adding project ${proj}")
+
+ set(python_SOURCE_DIR "${CMAKE_BINARY_DIR}/Python-2.7.3")
+
+ set(HAVE_PYRUN_CLOSEFILE 1)
+ set(HAVE_PYRUN_OPENFILE 1)
+ configure_file(SuperBuild/python_patch_step.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/python_patch_step.cmake
+ @ONLY)
-if(WIN32)
- set(External_python_win_PROJECT_INCLUDED 1)
- include(${CMAKE_CURRENT_LIST_DIR}/External_python_win.cmake)
- set(External_python_win_PROJECT_INCLUDED 0)
+ ExternalProject_Add(python-source
+ URL "http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz"
+ URL_MD5 "2cf641732ac23b18d139be077bd906cd"
+ DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}
+ SOURCE_DIR ${python_SOURCE_DIR}
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+ PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/python_patch_step.cmake
+ )
+
+ # Set CMake OSX variable to pass down the external project
+ set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS)
+ if(APPLE)
+ list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS
+ -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}
+ -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
+ -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
+ endif()
+
+ if(NOT DEFINED git_protocol)
+ set(git_protocol "git")
+ endif()
+
+ set(python_TCL_EXTERNAL_PROJECT_ARGS)
+ if(Slicer_USE_PYTHONQT_WITH_TCL)
+ if(WIN32)
+ set(tcl_library ${CMAKE_CURRENT_BINARY_DIR}/tcl-build/lib/tcl${TCL_TK_VERSION}.lib)
+ set(tk_library ${CMAKE_CURRENT_BINARY_DIR}/tcl-build/lib/tk${TCL_TK_VERSION}.lib)
+ else()
+ set(tcl_library ${CMAKE_CURRENT_BINARY_DIR}/tcl-build/lib/libtcl${TCL_TK_VERSION_DOT}${CMAKE_SHARED_LIBRARY_SUFFIX})
+ set(tk_library ${CMAKE_CURRENT_BINARY_DIR}/tcl-build/lib/libtk${TCL_TK_VERSION_DOT}${CMAKE_SHARED_LIBRARY_SUFFIX})
+ endif()
+ message(STATUS "TCL_LIBRARY:${tcl_library}")
+ message(STATUS "TK_LIBRARY:${tk_library}")
+ list(APPEND python_TCL_EXTERNAL_PROJECT_ARGS
+ -DENABLE_TKINTER:BOOL=ON
+ -DTCL_LIBRARY:FILEPATH=${tcl_library}
+ -DTCL_INCLUDE_PATH:PATH=${CMAKE_CURRENT_BINARY_DIR}/tcl-build/include
+ -DTK_LIBRARY:FILEPATH=${tk_library}
+ -DTK_INCLUDE_PATH:PATH=${CMAKE_CURRENT_BINARY_DIR}/tcl-build/include
+ )
+ else()
+ list(APPEND python_TCL_EXTERNAL_PROJECT_ARGS
+ -DENABLE_TKINTER:BOOL=OFF
+ )
+ endif()
+
+ ExternalProject_Add(${proj}
+ GIT_REPOSITORY "${git_protocol}://github.com/davidsansome/python-cmake-buildsystem.git"
+ GIT_TAG "2c54bc90aa643756ae2c5ac3e0eb344ce158df10"
+ "${${PROJECT_NAME}_EP_UPDATE_IF_GREATER_288}"
+ SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
+ BINARY_DIR ${proj}-build
+ CMAKE_GENERATOR ${gen}
+ CMAKE_ARGS
+ -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
+ #-DCMAKE_CXX_FLAGS:STRING=${ep_common_cxx_flags} # Not used
+ -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
+ -DCMAKE_C_FLAGS:STRING=${ep_common_c_flags}
+ ${CMAKE_OSX_EXTERNAL_PROJECT_ARGS}
+ -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/${proj}-install
+ #-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
+ #-DBUILD_TESTING:BOOL=OFF
+ -DBUILD_SHARED:BOOL=ON
+ -DBUILD_STATIC:BOOL=OFF
+ -DUSE_SYSTEM_LIBRARIES:BOOL=OFF
+ ${python_TCL_EXTERNAL_PROJECT_ARGS}
+ DEPENDS
+ python-source ${python_DEPENDENCIES}
+ )
+ set(python_DIR ${CMAKE_BINARY_DIR}/${proj}-install)
+
+ if(UNIX)
+ set(python_IMPORT_SUFFIX so)
+ if(APPLE)
+ set(python_IMPORT_SUFFIX dylib)
+ endif()
+ set(slicer_PYTHON_SHARED_LIBRARY_DIR ${python_DIR}/lib)
+ set(slicer_PYTHON_INCLUDE ${python_DIR}/include/python2.7)
+ set(slicer_PYTHON_LIBRARY ${python_DIR}/lib/libpython2.7.${python_IMPORT_SUFFIX})
+ set(slicer_PYTHON_EXECUTABLE ${python_DIR}/bin/customPython)
+ set(slicer_PYTHON_REAL_EXECUTABLE ${python_DIR}/bin/python)
+ elseif(WIN32)
+ set(slicer_PYTHON_SHARED_LIBRARY_DIR ${python_DIR}/bin)
+ set(slicer_PYTHON_INCLUDE ${python_DIR}/include)
+ set(slicer_PYTHON_LIBRARY ${python_DIR}/libs/python27.lib)
+ set(slicer_PYTHON_EXECUTABLE ${python_DIR}/bin/python.exe)
+ set(slicer_PYTHON_REAL_EXECUTABLE ${slicer_PYTHON_EXECUTABLE})
+ else()
+ message(FATAL_ERROR "Unknown system !")
+ endif()
else()
- set(External_python_unix_PROJECT_INCLUDED 1)
- include(${CMAKE_CURRENT_LIST_DIR}/External_python_unix.cmake)
- set(External_python_unix_PROJECT_INCLUDED 0)
+ # The project is provided using python_DIR, nevertheless since other project may depend on python,
+ # let's add an 'empty' one
+ SlicerMacroEmptyExternalProject(${proj} "${python_DEPENDENCIES}")
endif()
-#message(STATUS "MSVC_VERSION:${MSVC_VERSION}")
-#message(STATUS "python_URL:${python_URL}")
-#message(STATUS "CMAKE_GENERATOR:${CMAKE_GENERATOR}")
-#message(STATUS "slicer_PYTHON_INCLUDE:${slicer_PYTHON_INCLUDE}")
-#message(STATUS "slicer_PYTHON_LIBRARY:${slicer_PYTHON_LIBRARY}")
-#message(STATUS "slicer_PYTHON_EXECUTABLE:${slicer_PYTHON_EXECUTABLE}")
+message(STATUS "slicer_PYTHON_INCLUDE:${slicer_PYTHON_INCLUDE}")
+message(STATUS "slicer_PYTHON_LIBRARY:${slicer_PYTHON_LIBRARY}")
+message(STATUS "slicer_PYTHON_EXECUTABLE:${slicer_PYTHON_EXECUTABLE}")
+
+if(UNIX)
+ configure_file(
+ SuperBuild/python_customPython_configure.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/python_customPython_configure.cmake
+ @ONLY)
+ ExternalProject_Add_Step(${proj} python_customPython_configure
+ COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/python_customPython_configure.cmake
+ DEPENDEES install
+ )
+endif()
+#-----------------------------------------------------------------------------
+# Since fixup_bundle expects the library to be writable, let's add an extra step
+# to make sure it's the case.
+if(APPLE)
+ ExternalProject_Add_Step(${proj} python_install_chmod_library
+ COMMAND chmod u+xw ${slicer_PYTHON_LIBRARY}
+ DEPENDEES install
+ )
+endif()
Oops, something went wrong.

0 comments on commit 140d5f4

Please sign in to comment.