python: prep to install with DESTDIR

This commit is contained in:
nick black 2020-02-20 01:23:49 -05:00
parent 447ca1f3b9
commit adfbedf3ef
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

View File

@ -546,36 +546,40 @@ write_basic_package_version_file(
# Python bindings
if(${USE_PYTHON})
find_package(Python3 COMPONENTS Development Interpreter REQUIRED)
file(GLOB PYSRC CONFIGURE_DEPENDS python/src/notcurses/*.py)
file(COPY python/src/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python/src)
file(COPY python/README.md DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python)
set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/tools/setup.py.in")
set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/python/setup.py")
set(SETUP_CFG_IN "${CMAKE_CURRENT_SOURCE_DIR}/tools/setup.cfg.in")
set(SETUP_CFG "${CMAKE_CURRENT_BINARY_DIR}/python/setup.cfg")
configure_file(${SETUP_PY_IN} ${SETUP_PY})
configure_file(${SETUP_CFG_IN} ${SETUP_CFG})
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/build/pytimestamp"
COMMAND
env LDFLAGS="-L${CMAKE_CURRENT_BINARY_DIR}" "${Python3_EXECUTABLE}" ${SETUP_PY} build &&
"${Python3_EXECUTABLE}" ${SETUP_PY} egg_info
DEPENDS
${PYSRC} ${SETUP_PY} ${SETUP_CFG} notcurses
COMMENT "Building Python wrappers"
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/python
)
# build/pytimestamp isn't actually generated, and thus this runs each time.
# python does its own dep tracking, so it "works" out like recursive make.
add_custom_target(pymod ALL
DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/build/pytimestamp"
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/python
)
# when we're building debs, we use pybuild to directly call into setup.py,
# so none of this applies.
if(NOT "${DFSG_BUILD}")
find_package(Python3 COMPONENTS Development Interpreter REQUIRED)
file(GLOB PYSRC CONFIGURE_DEPENDS python/src/notcurses/*.py)
file(COPY python/src/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python/src)
file(COPY python/README.md DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/python)
set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/tools/setup.py.in")
set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/python/setup.py")
set(SETUP_CFG_IN "${CMAKE_CURRENT_SOURCE_DIR}/tools/setup.cfg.in")
set(SETUP_CFG "${CMAKE_CURRENT_BINARY_DIR}/python/setup.cfg")
configure_file(${SETUP_PY_IN} ${SETUP_PY})
configure_file(${SETUP_CFG_IN} ${SETUP_CFG})
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/build/pytimestamp"
COMMAND
env LDFLAGS="-L${CMAKE_CURRENT_BINARY_DIR}" "${Python3_EXECUTABLE}" ${SETUP_PY} build &&
"${Python3_EXECUTABLE}" ${SETUP_PY} egg_info
DEPENDS
${PYSRC} ${SETUP_PY} ${SETUP_CFG} notcurses
COMMENT "Building Python wrappers"
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/python
)
# build/pytimestamp isn't actually generated, and thus this runs each time.
# python does its own dep tracking, so it "works" out like recursive make.
add_custom_target(pymod ALL
DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/build/pytimestamp"
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/python
)
endif()
endif()
# Rust bindings + colloquy
@ -692,13 +696,19 @@ install(TARGETS notcurses notcurses-static
)
if(${USE_PYTHON})
# if DFSG_BUILD has been selected, assume we're building debs. debian/rules
# has its own python install logic after many hours wasted, so we don't
# install from here for a deb build.
# has its own python logic after many hours wasted, so we don't install from
# here for a deb build.
if(NOT "${DFSG_BUILD}")
# --root both implies, and is required by, --single-external-package-managed
# Arch makepkg sets it. if unset, use /
set(PYROOT $ENV{DESTDIR})
if(NOT PYROOT)
set(PYROOT "/")
endif()
install(
CODE "execute_process(
COMMAND
${Python3_EXECUTABLE} ${SETUP_PY} install --root=/ --prefix=${CMAKE_INSTALL_PREFIX} --optimize=1
${Python3_EXECUTABLE} ${SETUP_PY} install --root=${PYROOT} --prefix=${CMAKE_INSTALL_PREFIX} --optimize=1
WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/python
)"