1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
if(POLICY CMP0012)
cmake_policy(SET CMP0012 NEW)
endif()
set(VIRTUALENV_ARGS --clear --no-pip)
if ( "@SimpleITK_FORBID_DOWNLOADS@" )
set(VIRTUALENV_ARGS ${VIRTUALENV_ARGS} --never-download)
endif()
if ( NOT "@SimpleITK_PYTHON_WHEEL@" )
if ("@PYTHON_VIRTUALENV_VERSION_STRING@" VERSION_GREATER "13")
set(VIRTUALENV_ARGS ${VIRTUALENV_ARGS} --no-wheel)
endif()
if ( NOT "@SimpleITK_PYTHON_EGG@" )
set(VIRTUALENV_ARGS ${VIRTUALENV_ARGS} --no-setuptools)
endif()
endif()
#
# Create the Python virtual environment.
#
execute_process(
COMMAND ${CMAKE_COMMAND}
"-E"
"remove_directory"
"@PythonVirtualenvHome@"
)
execute_process(
COMMAND "@PYTHON_EXECUTABLE@"
"@PYTHON_VIRTUALENV_SCRIPT@"
"--python=@PYTHON_EXECUTABLE@"
${VIRTUALENV_ARGS}
"@PythonVirtualenvHome@"
WORKING_DIRECTORY "@SimpleITK_SOURCE_DIR@/Wrapping/Python"
RESULT_VARIABLE failed
ERROR_VARIABLE error
)
if ( failed )
message( FATAL_ERROR "Creation of Python virtual enviroment failed.\n${error}" )
endif()
#
# Install the SimpleITK Package into the virtual environment.
#
message(STATUS "Installing Python Package: SimpleITK")
# The working directory for the installation and packaging with
# setup.py is very important. As if the setup is run from another
# directory files will not be correctly execute_process.
execute_process(
COMMAND "@VIRTUAL_PYTHON_EXECUTABLE@" "@CMAKE_CURRENT_BINARY_DIR@/Packaging/setup.py" install
WORKING_DIRECTORY "@SimpleITK_Python_BINARY_DIR@"
RESULT_VARIABLE failed
ERROR_VARIABLE error
)
if ( failed )
message( FATAL_ERROR "Installation of SimpleITK into Python virutal enviroment failed.\n${error}" )
endif()
if(@BUILD_TESTING@)
#
# Get Python library directory.
#
execute_process(
COMMAND "@VIRTUAL_PYTHON_EXECUTABLE@" -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
OUTPUT_VARIABLE PythonVirtualenvLib
ERROR_VARIABLE error
RESULT_VARIABLE failed
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if ( failed )
message( SEND_ERROR "Determining python library path failed.\n${error}" )
endif()
#
# Manual copy the numpy installation into the virtual environment.
#
execute_process(
COMMAND "@PYTHON_EXECUTABLE@" -c "import numpy; import os; print(os.path.dirname(numpy.__file__))"
OUTPUT_VARIABLE numpy_dir
ERROR_VARIABLE error
RESULT_VARIABLE failed
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if( failed )
message( WARNING "Failed to determine numpy.__file__ path: \"${error}\"" )
else()
message( STATUS "Installing numpy from ${numpy_dir} to ${PythonVirtualenvLib}/numpy")
if ( UNIX )
execute_process( COMMAND ${CMAKE_COMMAND} -E create_symlink "${numpy_dir}" "${PythonVirtualenvLib}/numpy"
RESULT_VARIABLE failed
ERROR_VARIABLE error )
if ( failed )
message( SEND_ERROR ${error} )
endif()
else ()
execute_process( COMMAND ${CMAKE_COMMAND} -E copy_directory "${numpy_dir}" "${PythonVirtualenvLib}/numpy"
RESULT_VARIABLE failed
ERROR_VARIABLE error )
if ( failed )
message( SEND_ERROR ${error} )
endif()
endif ()
endif()
endif()
|