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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
set(header "Python wheel (${Python3_VERSION}):")
# Python package directory structure:
#
# py {Python package build-workspace}
# |...{Package setup config files}
# +--src
# | |
# | +--bornagain
# | |...{Package init files}
# | +--lib {BornAgain libraries and their Python wrappers}
# | |
# | +--extra {Extra dependencies}
# |
# +--wheel {wheel for the Python version}
set(WHEEL_ROOT_DIR "${CMAKE_SOURCE_DIR}/Wrap/Python")
# output directories:
set(PY_OUTPUT_DIR "${CMAKE_BINARY_DIR}/py")
set(WHEEL_DIR "${PY_OUTPUT_DIR}/wheel")
set(BA_PY_SOURCE_OUTPUT_DIR "${PY_OUTPUT_DIR}/src")
set(BA_PY_INIT_OUTPUT_DIR "${PY_OUTPUT_DIR}/src/bornagain")
set(BA_PY_LIBRARY_OUTPUT_DIR "${PY_OUTPUT_DIR}/src/bornagain/lib")
set(BA_PY_EXTRA_LIBRARY_OUTPUT_DIR "${PY_OUTPUT_DIR}/src/bornagain/lib/extra")
# make the directories
file(MAKE_DIRECTORY
"${PY_OUTPUT_DIR}"
"${WHEEL_DIR}"
"${BA_PY_SOURCE_OUTPUT_DIR}"
"${BA_PY_INIT_OUTPUT_DIR}"
"${BA_PY_LIBRARY_OUTPUT_DIR}"
"${BA_PY_EXTRA_LIBRARY_OUTPUT_DIR}"
)
# configure setup files
configure_file(${WHEEL_ROOT_DIR}/setup.cfg.in ${PY_OUTPUT_DIR}/setup.cfg @ONLY)
configure_file(${WHEEL_ROOT_DIR}/setup.py.in ${PY_OUTPUT_DIR}/setup.py @ONLY)
configure_file(${WHEEL_ROOT_DIR}/pyproject.toml ${PY_OUTPUT_DIR} COPYONLY)
# MANIFEST.in is needed for inclusion of binary files under Windows
configure_file(${WHEEL_ROOT_DIR}/MANIFEST.in ${PY_OUTPUT_DIR} COPYONLY)
# copy text files
configure_file(${CMAKE_SOURCE_DIR}/README.md ${PY_OUTPUT_DIR} COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/COPYING ${PY_OUTPUT_DIR} COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/CITATION ${PY_OUTPUT_DIR} COPYONLY)
# dummy C extension for the Python package
# NOTE: Dummy C extension is used merely to set the correct wheel tag according to PEP 425
# determine the full wheel-name
execute_process(
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/cmake/multipython/wheelname.py
${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_VERSION}
OUTPUT_VARIABLE _BA_WHEEL_NAMES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# name for a pure-Python wheel, eg. 'BA-3.2.1-py3-none-any'
list(GET _BA_WHEEL_NAMES 0 BA_PURE_WHEEL_NAME)
set(BA_PY_PURE_WHEEL_NAME "${BA_PURE_WHEEL_NAME}.whl")
# name for a platform-dependent Python wheel; eg., 'BA-3.2.1-cp311-cp311-linux_x86_64'
list(GET _BA_WHEEL_NAMES 1 BA_WHEEL_NAME)
set(BA_PY_WHEEL_NAME "${BA_WHEEL_NAME}.whl")
message(STATUS "Python pure wheel-name: '${BA_PURE_WHEEL_NAME}'")
message(STATUS "Python platform-dependent wheel-name: '${BA_WHEEL_NAME}'")
# store init files for the Python package
configure_file(${WHEEL_ROOT_DIR}/src/bornagain/__init__.py.in
${BA_PY_INIT_OUTPUT_DIR}/__init__.py @ONLY)
file(GLOB _sources ${WHEEL_ROOT_DIR}/src/bornagain/*.py)
foreach(_src ${_sources})
configure_file(${_src} ${BA_PY_INIT_OUTPUT_DIR})
endforeach()
file(GLOB _sources ${WHEEL_ROOT_DIR}/src/bornagain/lib/*.py)
foreach(_src ${_sources})
configure_file(${_src} ${BA_PY_LIBRARY_OUTPUT_DIR})
endforeach()
# external library dependencies
if(WIN32)
set(_extra_libs "${BA_Dependencies_WIN32}")
else()
set(_extra_libs "${BA_Dependencies}")
endif()
if(LINUX)
# On Linux, building the Python packages needs further effort
# which is performed in a dedicated shell script which
# should be executed after build process is done (like CPack).
configure_file("${CMAKE_SOURCE_DIR}/deploy/linux/mk_wheel_multilinux.sh.in"
${BUILD_VAR_DIR}/mk_wheel_multilinux.sh @ONLY)
add_custom_target(ba_wheel
COMMAND bash ${BUILD_VAR_DIR}/mk_wheel_multilinux.sh
COMMENT "${header} Making the Python wheel..."
)
set(WHEEL_DIR "${WHEEL_DIR}/manylinux/")
else()
# Windows
message(STATUS "Will copy extra libs (${_extra_libs}) to ${BA_PY_EXTRA_LIBRARY_OUTPUT_DIR}")
foreach(_src ${_extra_libs})
configure_file(${_src} ${BA_PY_EXTRA_LIBRARY_OUTPUT_DIR} COPYONLY)
endforeach()
add_custom_target(ba_wheel
COMMAND ${Python3_EXECUTABLE} -m pip wheel ${PY_OUTPUT_DIR} --no-deps --wheel ${WHEEL_DIR}
COMMAND ${CMAKE_COMMAND} -E rename "${WHEEL_DIR}/${BA_PY_PURE_WHEEL_NAME}"
"${WHEEL_DIR}/${BA_PY_WHEEL_NAME}"
COMMENT "${header} Making the Python wheel..."
)
endif()
# install the wheel in the proper directory
install(DIRECTORY "${WHEEL_DIR}/" DESTINATION "${destination_share}/wheel/"
COMPONENT Libraries OPTIONAL FILES_MATCHING PATTERN "*.whl")
message(STATUS "${header} ${BA_PY_WHEEL_NAME} will be installed in ${destination_share}/wheel/")
|