# #Python script interpreter # #Compile and install for use as a platform independent build tool available #for use in the configure step of other packages as #$ # #A distributable Python 2.7 should be compiled with Visual Studio 2008. #The Python we compile here is not for distribution, but strictly for use as a #build tool (typically in the configure step), so it can be compiled with #later versions of Visual Studio (including Visual Studio 2015). #We take care to use a Python release that will build with as many versions of #Visual Studio as possible. if (WIN32) set (PYTHON_VERSION 2.7.12) set (PYTHON_MD5 88d61f82e3616a4be952828b3694109d) #Download, unpack and patch the source code ExternalProject_Add ( python2-download PREFIX ${CMAKE_INSTALL_PREFIX}/python2 URL http://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz URL_MD5 ${PYTHON_MD5} PATCH_COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/patch . CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" ) #Obtain the directory where the patched source code exists ExternalProject_Get_Property(python2-download SOURCE_DIR) #Build the patched source code #NOTE: We are using c_flag_overrides.cmake and cxx_flag_overrides.cmake in #order to instruct Visual Studio to use the STATIC C RUNTIME. This is required #in order to compile Python 2.7.X with Visual Studio 2015 and later editions, #whose dynamic runtime no longer exports some (undocumented) symbols that #Python relies on. Python should be compiled with /MT or /MTd so it will use #the static CRT, which allows the linker to resolve the undocumented symbol #_pioinfo used in the internal function _PyVerify_fd(). # #Comment: YES - compiling with a static C runtime is not a god idea for #dynamically linked Python extensions. However, we are building Python for use #as a configure/build tool to be invoked via find_program() offering a #limited, fixed set of extensions built in, so we have no need for external #extensions. # #More specifically, we need Python 2.7 in order to use the scons build tool. # ExternalProject_Add ( python2 PREFIX ${CMAKE_INSTALL_PREFIX}/python2 SVN_REPOSITORY http://github.com/python-cmake-buildsystem/python-cmake-buildsystem/trunk UPDATE_COMMAND "" CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= -DPYTHON_VERSION=${PYTHON_VERSION} -DSRC_DIR=${SOURCE_DIR} -DCMAKE_BUILD_TYPE=Release #Ensures static runtime when building with MSVC (see comment above) -DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_CURRENT_LIST_DIR}/c_flag_overrides.cmake -DCMAKE_USER_MAKE_RULES_OVERRIDE_CXX=${CMAKE_CURRENT_LIST_DIR}/cxx_flag_overrides.cmake DEPENDS python2-download ) endif (WIN32) if (UNIX) #Rely on manual installation via the package manager #You can then invoke python as /usr/bin/python2 #sudo apt-get install python2 ExternalProject_Add ( python2 PREFIX ${CMAKE_INSTALL_PREFIX} BUILD_IN_SOURCE 1 DOWNLOAD_COMMAND "" UPDATE_COMMAND "" CONFIGURE_COMMAND "" BUILD_COMMAND /usr/bin/python2 --version INSTALL_COMMAND "" ) endif (UNIX)