Skip to content
Snippets Groups Projects
Commit 6689c8e4 authored by Wuttke, Joachim's avatar Wuttke, Joachim Committed by Wuttke, Joachim
Browse files

MakePythonWheel fct make_python_wheel -> main code

parent 1c94b091
No related branches found
No related tags found
1 merge request!2461CMake simplifications
Pipeline #138882 canceled
......@@ -49,122 +49,115 @@ function(set_python_package_dirs pyversion)
endfunction(set_python_package_dirs)
function(make_python_wheel)
# parse function arguments for text like 'PYTAG xy',
# and set local variable '__PYTAG' to 'xy'.
cmake_parse_arguments(
"_" "" "Py3_EXECUTABLE;Py3_VERSION" "Py3_INCLUDE_DIRS;Py3_LIBRARY_DIRS" ${ARGN})
set(header "Python wheel (${__Py3_VERSION}):")
# make directories for the Python wheel
set_python_package_dirs(${__Py3_VERSION})
#-- define the main target to build a Python wheel
# store the external libraries needed for making the Python wheel
if(WIN32)
set(_extra_libs "${BA_Dependencies_WIN32}")
else()
set(_extra_libs "${BA_Dependencies}")
endif()
# make the Python wheel
if(APPLE)
# On MacOS, 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).
set(BA_PY_MODE "ON")
set(MACPKG_EXTRA_LIBS "${_extra_libs}")
configure_file("${CMAKE_SOURCE_DIR}/devtools/deploy/mac/mac_package.py.in"
${BUILD_VAR_DIR}/mac_py_package.py @ONLY)
add_custom_target(BAPyWheel ALL
COMMENT "${header} Script to build the Python wheel: "
"'${${BUILD_VAR_DIR}/mk_pypack_macos.zsh}'"
)
elseif(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}/devtools/deploy/linux/mk_pypack_linux.sh.in"
${BUILD_VAR_DIR}/mk_pypack_linux.sh @ONLY)
add_custom_target(BAPyWheel ALL
COMMENT "${header} Script to build the Python wheel: "
"'${${BUILD_VAR_DIR}/mk_pypack_linux.sh}'"
)
else()
# MS-Windows
add_custom_target(BAPyWheel ALL
COMMAND ${__Py3_EXECUTABLE} -m pip wheel ${BA_PY_OUTPUT_DIR} --no-deps
--wheel ${WHEEL_DIR}
COMMENT "${header} Making the Python wheel..."
)
endif()
set_target_properties(BAPyWheel PROPERTIES
_EXTRA_LIBRARIES "${_extra_libs}")
#-- store the configuration files for the Python package
# make the version-dependent setup config
set(_setup_cfg ${BA_PY_OUTPUT_DIR}/setup.cfg)
set(_setup_py ${BA_PY_OUTPUT_DIR}/setup.py)
set(WHEEL_C_EXT "src/bornagain_c_ext_dummy.c")
set(WHEEL_C_EXT_INC_DIRS "${__Py3_INCLUDE_DIRS}")
set(WHEEL_C_EXT_LIB_DIRS "${__Py3_LIBRARY_DIRS}")
configure_file(${WHEEL_ROOT_DIR}/setup.cfg.in
${_setup_cfg} @ONLY)
configure_file(${WHEEL_ROOT_DIR}/setup.py.in
${_setup_py} @ONLY)
# copy config files
set(_dst ${BA_PY_OUTPUT_DIR}/)
file(GLOB _config_files
${WHEEL_ROOT_DIR}/pyproject.toml
${WHEEL_ROOT_DIR}/MANIFEST.in
set(header "Python wheel (${Python3_VERSION}):")
# make directories for the Python wheel
set_python_package_dirs(${Python3_VERSION})
#-- define the main target to build a Python wheel
# store the external libraries needed for making the Python wheel
if(WIN32)
set(_extra_libs "${BA_Dependencies_WIN32}")
else()
set(_extra_libs "${BA_Dependencies}")
endif()
# make the Python wheel
if(APPLE)
# On MacOS, 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).
set(BA_PY_MODE "ON")
set(MACPKG_EXTRA_LIBS "${_extra_libs}")
configure_file("${CMAKE_SOURCE_DIR}/devtools/deploy/mac/mac_package.py.in"
${BUILD_VAR_DIR}/mac_py_package.py @ONLY)
add_custom_target(BAPyWheel ALL
COMMENT "${header} Script to build the Python wheel: "
"'${${BUILD_VAR_DIR}/mk_pypack_macos.zsh}'"
)
add_custom_target(BAPyWheel_config_files
COMMAND ${CMAKE_COMMAND} -E copy ${_config_files} ${_dst}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/README.md ${_dst}/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/COPYING ${_dst}/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/CITATION ${_dst}/
COMMENT "${header} Copying config files to '${_dst}'..."
DEPENDS ${_setup_cfg} ${_setup_py}
elseif(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}/devtools/deploy/linux/mk_pypack_linux.sh.in"
${BUILD_VAR_DIR}/mk_pypack_linux.sh @ONLY)
add_custom_target(BAPyWheel ALL
COMMENT "${header} Script to build the Python wheel: "
"'${${BUILD_VAR_DIR}/mk_pypack_linux.sh}'"
)
# store dummy C extension for the Python package
# NOTE: Dummy C extension is used merely to set the correct wheel tag
# according to PEP 425
set(_dst ${BA_PY_SOURCE_OUTPUT_DIR})
file(GLOB _c_dummy_file ${WHEEL_ROOT_DIR}/${WHEEL_C_EXT})
add_custom_target(BAPyWheel_c_dummy_file
COMMAND ${CMAKE_COMMAND} -E copy ${_c_dummy_file} ${_dst}
COMMENT "${header} Copying dummy C extension file to '${_dst}'..."
else()
# MS-Windows
add_custom_target(BAPyWheel ALL
COMMAND ${Python3_EXECUTABLE} -m pip wheel ${BA_PY_OUTPUT_DIR} --no-deps
--wheel ${WHEEL_DIR}
COMMENT "${header} Making the Python wheel..."
)
# store init files for the Python package
set(_dst ${BA_PY_INIT_OUTPUT_DIR}/)
set(_dst_lib ${BA_PY_LIBRARY_OUTPUT_DIR}/)
file(GLOB _ba_py_files ${WHEEL_ROOT_DIR}/src/bornagain/*.py)
file(GLOB _init_files_lib ${WHEEL_ROOT_DIR}/src/bornagain/lib/*.py)
configure_file(${WHEEL_ROOT_DIR}/src/bornagain/__init__.py.in
${_dst}/__init__.py @ONLY)
add_custom_target(BAPyWheel_init_files
COMMAND ${CMAKE_COMMAND} -E copy ${_ba_py_files} ${_dst}
COMMAND ${CMAKE_COMMAND} -E copy ${_init_files_lib} ${_dst_lib}
COMMENT "${header} Copying init files to '${_dst}'..."
)
# store the required extra libraries
set(_dst ${BA_PY_EXTRA_LIBRARY_OUTPUT_DIR})
add_custom_target(BAPyWheel_extra_libs
COMMAND ${CMAKE_COMMAND} -E copy ${_extra_libs} ${_dst}
COMMENT "${header} Copying extra libraries {${_extra_libs}} to '${_dst}'..."
)
# add dependencies
add_dependencies(BAPyWheel
BAPyWheel_config_files
BAPyWheel_c_dummy_file
BAPyWheel_init_files
BAPyWheel_extra_libs
)
endfunction()
endif()
set_target_properties(BAPyWheel PROPERTIES
_EXTRA_LIBRARIES "${_extra_libs}")
#-- store the configuration files for the Python package
# make the version-dependent setup config
set(_setup_cfg ${BA_PY_OUTPUT_DIR}/setup.cfg)
set(_setup_py ${BA_PY_OUTPUT_DIR}/setup.py)
set(WHEEL_C_EXT "src/bornagain_c_ext_dummy.c")
set(WHEEL_C_EXT_INC_DIRS "${Python3_INCLUDE_DIRS}")
set(WHEEL_C_EXT_LIB_DIRS "${Python3_LIBRARY_DIRS}")
configure_file(${WHEEL_ROOT_DIR}/setup.cfg.in
${_setup_cfg} @ONLY)
configure_file(${WHEEL_ROOT_DIR}/setup.py.in
${_setup_py} @ONLY)
# copy config files
set(_dst ${BA_PY_OUTPUT_DIR}/)
file(GLOB _config_files
${WHEEL_ROOT_DIR}/pyproject.toml
${WHEEL_ROOT_DIR}/MANIFEST.in
)
add_custom_target(BAPyWheel_config_files
COMMAND ${CMAKE_COMMAND} -E copy ${_config_files} ${_dst}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/README.md ${_dst}/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/COPYING ${_dst}/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/CITATION ${_dst}/
COMMENT "${header} Copying config files to '${_dst}'..."
DEPENDS ${_setup_cfg} ${_setup_py}
)
# store dummy C extension for the Python package
# NOTE: Dummy C extension is used merely to set the correct wheel tag
# according to PEP 425
set(_dst ${BA_PY_SOURCE_OUTPUT_DIR})
file(GLOB _c_dummy_file ${WHEEL_ROOT_DIR}/${WHEEL_C_EXT})
add_custom_target(BAPyWheel_c_dummy_file
COMMAND ${CMAKE_COMMAND} -E copy ${_c_dummy_file} ${_dst}
COMMENT "${header} Copying dummy C extension file to '${_dst}'..."
)
# store init files for the Python package
set(_dst ${BA_PY_INIT_OUTPUT_DIR}/)
set(_dst_lib ${BA_PY_LIBRARY_OUTPUT_DIR}/)
file(GLOB _ba_py_files ${WHEEL_ROOT_DIR}/src/bornagain/*.py)
file(GLOB _init_files_lib ${WHEEL_ROOT_DIR}/src/bornagain/lib/*.py)
configure_file(${WHEEL_ROOT_DIR}/src/bornagain/__init__.py.in
${_dst}/__init__.py @ONLY)
add_custom_target(BAPyWheel_init_files
COMMAND ${CMAKE_COMMAND} -E copy ${_ba_py_files} ${_dst}
COMMAND ${CMAKE_COMMAND} -E copy ${_init_files_lib} ${_dst_lib}
COMMENT "${header} Copying init files to '${_dst}'..."
)
# store the required extra libraries
set(_dst ${BA_PY_EXTRA_LIBRARY_OUTPUT_DIR})
add_custom_target(BAPyWheel_extra_libs
COMMAND ${CMAKE_COMMAND} -E copy ${_extra_libs} ${_dst}
COMMENT "${header} Copying extra libraries {${_extra_libs}} to '${_dst}'..."
)
# add dependencies
add_dependencies(BAPyWheel
BAPyWheel_config_files
BAPyWheel_c_dummy_file
BAPyWheel_init_files
BAPyWheel_extra_libs
)
......@@ -54,14 +54,7 @@ if(CONFIGURE_BINDINGS)
endif()
if(BA_WHEEL)
# define a target to make a Python wheel
include("multipython/MakePythonWheel")
make_python_wheel(
Py3_VERSION ${Python3_VERSION}
Py3_EXECUTABLE "${Python3_EXECUTABLE}"
Py3_INCLUDE_DIRS "${Python3_INCLUDE_DIRS}"
Py3_LIBRARY_DIRS "${Python3_LIBRARY_DIRS}"
)
include("multipython/MakePythonWheel") # define a target to make a Python wheel
endif()
# install Python example scripts
......
......@@ -21,7 +21,7 @@ pyoutdir="@BA_PY_OUTPUT_DIR@"
libdir="@BA_PY_LIBRARY_OUTPUT_DIR@"
xlibdir="@BA_PY_EXTRA_LIBRARY_OUTPUT_DIR@"
wheeldir="@WHEEL_DIR@"
PYTHON="@__Py3_EXECUTABLE@"
PYTHON="@Python3_EXECUTABLE@"
# constants
TITLE=$(basename $0)
......
......@@ -729,7 +729,7 @@ if len(sys.argv) > 1:
# Python-related variables
python_mode = bool("@BA_PY_MODE@")
python_exe = "@__Py3_EXECUTABLE@"
python_exe = "@Python3_EXECUTABLE@"
pkg_py_output_dir = os.path.dirname("@BA_PY_OUTPUT_DIR@/")
pkg_py_root_dir = os.path.dirname("@BA_PY_INIT_OUTPUT_DIR@/")
pkg_py_lib_dir = os.path.dirname("@BA_PY_LIBRARY_OUTPUT_DIR@/")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment