Skip to content

Commit

Permalink
add PYTHON_STRATEGY=PYTHONPATH, tidy before migration to SIRF
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Apr 27, 2018
1 parent 703b18a commit 6030bca
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 56 deletions.
75 changes: 19 additions & 56 deletions SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,28 @@ set(CCPPETMR_INSTALL ${SUPERBUILD_INSTALL_DIR})
set(ENV_PYTHON_BASH "##### Python not found #####")
set(ENV_PYTHON_CSH "##### Python not found #####")
if(PYTHONINTERP_FOUND)
set(PYTHON_STRATEGY "PYTHONPATH" CACHE STRING "\
PYTHONPATH: prefix PYTHONPATH \n\
SETUP_PY: execute ${PYTHON_EXECUTABLE} setup.py install \n\
CONDA: do nothing")
set_property(CACHE PYTHON_STRATEGY PROPERTY STRINGS PYTHONPATH SETUP_PY CONDA)

if("${PYTHON_STRATEGY}" STREQUAL "PYTHONPATH")
set(COMMENT_OUT_PREFIX "")
else()
set(COMMENT_OUT_PREFIX "#")
endif()

set (ENV_PYTHON_CSH "\
if $?PYTHONPATH then \n\
#setenv PYTHONPATH ${PYTHON_DEST}:$PYTHONPATH \n\
else \n\
#setenv PYTHONPATH ${PYTHON_DEST} \n\
setenv SIRF_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}")
${COMMENT_OUT_PREFIX}if $?PYTHONPATH then \n\
${COMMENT_OUT_PREFIX} setenv PYTHONPATH ${PYTHON_DEST}:$PYTHONPATH \n\
${COMMENT_OUT_PREFIX}else \n\
${COMMENT_OUT_PREFIX} setenv PYTHONPATH ${PYTHON_DEST} \n\
setenv SIRF_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}")

set (ENV_PYTHON_BASH "\
#export PYTHONPATH=${PYTHON_DEST}:$PYTHONPATH \n\
export SIRF_PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}")

${COMMENT_OUT_PREFIX}export PYTHONPATH=\"${PYTHON_DEST}\${PYTHONPATH:+:\${PYTHONPATH}}\" \n\
export SIRF_PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}")
endif()

set(ENV_MATLAB_BASH "##### Matlab not found #####")
Expand All @@ -218,54 +228,7 @@ endif()
configure_file(env_ccppetmr.sh.in ${CCPPETMR_INSTALL}/bin/env_ccppetmr.sh)
configure_file(env_ccppetmr.csh.in ${CCPPETMR_INSTALL}/bin/env_ccppetmr.csh)

# Install python packages via pip and setup.py
if(PYTHONINTERP_FOUND)
set(PYTHON_SETUP_PKGS "sirf" CACHE INTERNAL "list of provided python packages")

# alias sirf.p* -> p* for backward-compatibility
function(python_pkg_alias PY_PKG_NEW PY_PKG_OLD)
list(APPEND PYTHON_SETUP_PKGS ${PY_PKG_NEW})
set(PYTHON_SETUP_PKGS "${PYTHON_SETUP_PKGS}" PARENT_SCOPE)
set(SETUP_PY_INIT_IN "${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild/__init__.py.in")
set(SETUP_PY_INIT "${PYTHON_DEST}/${PY_PKG_NEW}/__init__.py")
configure_file("${SETUP_PY_INIT_IN}" "${SETUP_PY_INIT}")
# message(STATUS "setup.py:${SETUP_PY_INIT}")
message(STATUS "setup.py:${PY_PKG_NEW}<-${PY_PKG_OLD}")
endfunction(python_pkg_alias)
python_pkg_alias(pGadgetron "sirf.pGadgetron")
python_pkg_alias(pSTIR "sirf.pSTIR")
python_pkg_alias(pUtilities "sirf.pUtilities")
python_pkg_alias(pygadgetron "sirf.pygadgetron")
python_pkg_alias(pystir "sirf.pystir")
python_pkg_alias(pyiutilities "sirf.pyiutilities")
# convert to python CSV tuple for setup.py configure_file
string(REPLACE ";" "', '" PYTHON_SETUP_PKGS_CSV "${PYTHON_SETUP_PKGS}")
set(PYTHON_SETUP_PKGS_CSV "'${PYTHON_SETUP_PKGS_CSV}'")
# message(STATUS "setup.py:pacakges:${PYTHON_SETUP_PKGS_CSV}")

# Create setup.py
set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild/setup.py.in")
set(SETUP_PY "${PYTHON_DEST}/setup.py")
set(SETUP_PY_INIT "${PYTHON_DEST}/sirf/__init__.py")
message(STATUS "setup.py:${SETUP_PY}")
configure_file("${SETUP_PY_IN}" "${SETUP_PY}")

# python setup.py build
add_custom_command(OUTPUT "${SETUP_PY_INIT}"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${PYTHON_DEST}/sirf"
COMMAND "${CMAKE_COMMAND}" -E touch "${SETUP_PY_INIT}"
COMMAND "${PYTHON_EXECUTABLE}" setup.py build
DEPENDS "${SETUP_PY_IN}"
WORKING_DIRECTORY "${PYTHON_DEST}")

add_custom_target(pybuild_sirf ALL DEPENDS ${SETUP_PY_INIT})

# python setup.py install
install(CODE "execute_process(COMMAND\n\
\"${PYTHON_EXECUTABLE}\" setup.py install\n\
WORKING_DIRECTORY \"${PYTHON_DEST}\")")
endif(PYTHONINTERP_FOUND)

include("${CMAKE_CURRENT_SOURCE_DIR}/setup.py.cmake")

# add tests
enable_testing()
Expand Down
File renamed without changes.
File renamed without changes.
49 changes: 49 additions & 0 deletions setup.py.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Install python packages via pip and setup.py
if(PYTHONINTERP_FOUND)
set(PYTHON_SETUP_PKGS "sirf" CACHE INTERNAL "list of provided python packages")

# alias sirf.p* -> p* for backward-compatibility
function(python_pkg_alias PY_PKG_NEW PY_PKG_OLD)
list(APPEND PYTHON_SETUP_PKGS ${PY_PKG_NEW})
set(PYTHON_SETUP_PKGS "${PYTHON_SETUP_PKGS}" PARENT_SCOPE)
set(SETUP_PY_INIT_IN "${CMAKE_CURRENT_SOURCE_DIR}/cmake/__init__.py.in")
set(SETUP_PY_INIT "${PYTHON_DEST}/${PY_PKG_NEW}/__init__.py")
configure_file("${SETUP_PY_INIT_IN}" "${SETUP_PY_INIT}")
# message(STATUS "setup.py:${SETUP_PY_INIT}")
message(STATUS "setup.py:${PY_PKG_NEW}<-${PY_PKG_OLD}")
endfunction(python_pkg_alias)
python_pkg_alias(pGadgetron "sirf.pGadgetron")
python_pkg_alias(pSTIR "sirf.pSTIR")
python_pkg_alias(pUtilities "sirf.pUtilities")
python_pkg_alias(pygadgetron "sirf.pygadgetron")
python_pkg_alias(pystir "sirf.pystir")
python_pkg_alias(pyiutilities "sirf.pyiutilities")
# convert to python CSV tuple for setup.py configure_file
string(REPLACE ";" "', '" PYTHON_SETUP_PKGS_CSV "${PYTHON_SETUP_PKGS}")
set(PYTHON_SETUP_PKGS_CSV "'${PYTHON_SETUP_PKGS_CSV}'")
# message(STATUS "setup.py:pacakges:${PYTHON_SETUP_PKGS_CSV}")

# Create setup.py
set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/cmake/setup.py.in")
set(SETUP_PY "${PYTHON_DEST}/setup.py")
set(SETUP_PY_INIT "${PYTHON_DEST}/sirf/__init__.py")
message(STATUS "setup.py:${SETUP_PY}")
configure_file("${SETUP_PY_IN}" "${SETUP_PY}")

# python setup.py build
add_custom_command(OUTPUT "${SETUP_PY_INIT}"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${PYTHON_DEST}/sirf"
COMMAND "${CMAKE_COMMAND}" -E touch "${SETUP_PY_INIT}"
COMMAND "${PYTHON_EXECUTABLE}" setup.py build
DEPENDS "${SETUP_PY_IN}"
WORKING_DIRECTORY "${PYTHON_DEST}")

add_custom_target(pybuild_sirf ALL DEPENDS ${SETUP_PY_INIT})

# python setup.py install
if("${PYTHON_STRATEGY}" STREQUAL "SETUP_PY")
install(CODE "execute_process(COMMAND\n\
\"${PYTHON_EXECUTABLE}\" setup.py install\n\
WORKING_DIRECTORY \"${PYTHON_DEST}\")")
endif()
endif(PYTHONINTERP_FOUND)

0 comments on commit 6030bca

Please sign in to comment.