Skip to content

Commit

Permalink
[camke] Add PIP_OPTIONS option for Python bindings install control
Browse files Browse the repository at this point in the history
[cmake] Use PIP_OPTIONS over PIP_VERBOSE

find if --prefix exists

Set default option to ""
c.f. https://cmake.org/cmake/help/latest/command/option.html
  • Loading branch information
matthewfeickert committed Mar 14, 2022
1 parent 3d64cda commit 0fdf09e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
38 changes: 26 additions & 12 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ endif()

configure_file(${SETUP_PY_IN} ${SETUP_PY})

if( PIP_VERBOSE )
set(PIP_INSTALL_VERBOSE_FLAG "--verbose")
else()
set(PIP_INSTALL_VERBOSE_FLAG "")
endif()
SET(PIP_OPTIONS "" CACHE STRING "pip options used during the Python bindings install.")
string(FIND "${PIP_OPTIONS}" "--prefix" PIP_OPTIONS_PREFIX_POSITION)

# Check it the Python interpreter has a valid version of pip
execute_process(
Expand All @@ -59,7 +56,7 @@ if ( NOT ${VALID_PIP_EXIT_CODE} EQUAL 0 )

# https://docs.python.org/3/install/#splitting-the-job-up
add_custom_command(OUTPUT ${OUTPUT}
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} ${PIP_INSTALL_VERBOSE_FLAG} build
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} ${PIP_OPTIONS} build
DEPENDS ${DEPS})

add_custom_target(python_target ALL DEPENDS ${OUTPUT} XrdCl)
Expand All @@ -75,25 +72,42 @@ if ( NOT ${VALID_PIP_EXIT_CODE} EQUAL 0 )
set(DEB_INSTALL_ARGS "--install-layout ${PYTHON_LAYOUT}")
endif()

if( "${PIP_OPTIONS_PREFIX_POSITION}" EQUAL "-1" )
string(APPEND PIP_OPTIONS " --prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}")
else()
message(WARNING
" The pip option --prefix has been set in ${PIP_OPTIONS} which will change "
" it from its default value of '--prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}'."
" Make sure this is intentional and that you understand the effects."
)
endif()

install(
CODE
"EXECUTE_PROCESS(
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install \
${PIP_INSTALL_VERBOSE_FLAG} \
--prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX} \
${PIP_OPTIONS} \
${DEB_INSTALL_ARGS}
)"
)

else()
# Use --force-reinstall to ensure a clean install if a rebuild needs to happen

if( "${PIP_OPTIONS_PREFIX_POSITION}" EQUAL "-1" )
string(APPEND PIP_OPTIONS " --prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}")
else()
message(WARNING
" The pip option --prefix has been set in ${PIP_OPTIONS} which will change "
" it from its default value of '--prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}'."
" Make sure this is intentional and that you understand the effects."
)
endif()

install(
CODE
"EXECUTE_PROCESS(
COMMAND ${PYTHON_EXECUTABLE} -m pip install \
${PIP_INSTALL_VERBOSE_FLAG} \
--force-reinstall \
--prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX} \
${PIP_OPTIONS} \
${CMAKE_CURRENT_BINARY_DIR}
)"
)
Expand Down
2 changes: 1 addition & 1 deletion cmake/XRootDDefaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ option( ENABLE_XRDCL "Enable XRootD client."
option( ENABLE_TESTS "Enable unit tests." FALSE )
option( ENABLE_HTTP "Enable HTTP component." TRUE )
option( ENABLE_PYTHON "Enable python bindings." TRUE )
option( PIP_VERBOSE "Turn on --verbose flag for pip during Python bindings install." FALSE )
option( PIP_OPTIONS "pip options to use during the Python bindings install." "" )
option( XRDCL_ONLY "Build only the client and necessary dependencies" FALSE )
option( XRDCL_LIB_ONLY "Build only the client libraries and necessary dependencies" FALSE )
option( PYPI_BUILD "The project is being built for PyPI release" FALSE )
Expand Down

0 comments on commit 0fdf09e

Please sign in to comment.