Skip to content
Snippets Groups Projects
Commit e5ad6ea1 authored by Franck Pérignon's avatar Franck Pérignon
Browse files

Fix install/uninstall bug

parent 6ede9800
No related branches found
No related tags found
No related merge requests found
......@@ -22,4 +22,5 @@ function(find_python_module module)
endif(NOT _${module}_status)
find_package_handle_standard_args(${module} DEFAULT_MSG _${module}_location)
set(${module}_FOUND ${${module_upper}_FOUND} PARENT_SCOPE)
endfunction(find_python_module)
......@@ -40,7 +40,6 @@ option(WITH_MAIN_FORTRAN "Create an executable (test purpose) from fortran sourc
option(DEBUG "Enable debug mode for Parmes (0:disabled, 1:verbose, 2:trace, 3:verbose+trace). Default = 0" 0)
option(FULL_TEST "Enable all test options (pep8, mpi ...) - Default = OFF" OFF)
option(PROFILE "Enable profiling mode for Parmes. 0:disabled, 1: enabled. Default = 0" 0)
option(PREFIX "Set install location prefix." "")
option(OPTIM "To allow python -OO run, some packages must be deactivated. Set this option to 'ON' to do so. Default = OFF" OFF)
option(WITH_MPI_TESTS "Enable mpi tests. Default = ON if USE_MPI is ON." ON)
if(NOT WITH_LIB_FORTRAN)
......@@ -89,14 +88,14 @@ set(PACKAGE_NAME Parmes)
# --- Python ---
find_package(PythonInterp)
get_filename_component(PYTHON_DIR ${PYTHON_EXECUTABLE} REALPATH)
display(CMAKE_PATCH_VERSION)
if(CMAKE_PATCH_VERSION LESS 12)
set(PYTHON_DIR ${PYTHON_DIR}/..)
get_filename_component(PYTHON_DIR ${PYTHON_DIR} REALPATH)
else()
get_filename_component(PYTHON_DIR ${PYTHON_DIR} DIRECTORY)
endif()
display(PYTHON_DIR)
set(PYTHON_main_version ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
set(PythonLibs_FIND_VERSION ${PYTHON_VERSION_STRING})
set(PYTHON_INCLUDE_DIR ${PYTHON_DIR}/../include/python${PYTHON_main_version})
......@@ -108,7 +107,11 @@ if(NOT PYTHONLIBS_VERSION_STRING VERSION_EQUAL PYTHON_VERSION_STRING)
endif()
include(FindPythonModule)
find_python_module(numpy REQUIRED)
find_python_module(scitools REQUIRED)
find_python_module(matplotlib)
if(NOT matplotlib_FOUND)
find_python_module(Gnuplot REQUIRED)
endif()
find_python_module(scitools)
find_python_module(h5py REQUIRED)
#find_python_module(evtk)
......@@ -116,56 +119,74 @@ find_python_module(h5py REQUIRED)
# if :
# 1 - cmake ... ==> try to install in site.USER_SITE of python (equivalent to python setup.py install --user)
# if you are using virtualenv, USER_SITE is not enable and install will be done in site-package of the virtualenv.
# 2 - cmake -DPREFIX = some_path ==> install in some_path as base (equivalent to python setup.py install --prefix=<path>)
# 2 - cmake -DCMAKE_INSTALL_PREFIX = some_path ==> install in some_path as base (equivalent to python setup.py install --prefix=<path>)
# Note that case 2 require a proper set of PYTHONPATH environment var for parmepy to work.
if(PREFIX)
#
#if(NOT first_run)
# message(STATUS " THIS IS THE FIRST RUN !!!!!! ")
# set(first_run 1 CACHE INTERNAL "True if first cmake run")
#endif()
if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND NOT first_run)
set(first_run 1 CACHE INTERNAL "True if first cmake run")
# if 'CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT' is false, it means
# that -DCMAKE_INSTALL_PREFIX=something has been given to cmake.
# A prefix is given by user. installation in PREFIX (as python --prefix=<PREFIX>).
set(install-opt "--prefix=${PREFIX}")
set(install-opt "--prefix=${CMAKE_INSTALL_PREFIX}")
# Need to set the CMAKE_INSTALL_PREFIX to the proper site (subdirectory of PREFIX)
# Get python install suffix (~> lib/python/site-package) from numpy package
set(PYTHON_COMMAND_GET_INSTALL_DIR "import os, re, numpy; print os.path.join(os.path.join(\"${PREFIX}\",*re.compile('/numpy/__init__.py.*').sub('',numpy.__file__).split('/')[-3:]), \"${PROJECT_NAME}\")")
set(PYTHON_COMMAND_GET_INSTALL_DIR "import os, re, numpy; print os.path.join(os.path.join(\"${CMAKE_INSTALL_PREFIX}\",*re.compile('/numpy/__init__.py.*').sub('',numpy.__file__).split('/')[-3:]), \"${PROJECT_NAME}\")")
else()
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import site; print site.ENABLE_USER_SITE"
OUTPUT_VARIABLE ENABLE_USER)
set(first_run 1 CACHE INTERNAL "True if first cmake run")
# First, we need to check if '--user' option works in the current environment.
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import site; print site.ENABLE_USER_SITE" OUTPUT_VARIABLE ENABLE_USER)
string(STRIP ${ENABLE_USER} ENABLE_USER)
if(ENABLE_USER)
# Default prefix (as python --user) -> installation in site.USER_SITE
# Note FP : for brew users, you need to set prefix= nothing in file /usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/distutils.cfg
# or create a ~/.pydistutils.cfg with:
# [install]
# prefix=
set(install-opt "--user")
# Need to set the CMAKE_INSTALL_PREFIX to site.USER_SITE
# Get python user site and install path = USER_SITE + project_name
set(PYTHON_COMMAND_GET_INSTALL_DIR "import site, os ; print os.path.join(site.USER_SITE, \"${PROJECT_NAME}\")")
# Set cmake PREFIX variable only for summary
set(PREFIX "No User prefix given, install process with python --user (in site.USER_SITE)")
# Default prefix (as python --user) -> installation in site.USER_SITE
# Note FP : for brew users, you need to set prefix= nothing in file /usr/local/Cellar/python/2.7.6_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/distutils.cfg
# or create a ~/.pydistutils.cfg with:
# [install]
# prefix=
set(install-opt "--user")
# Need to set the CMAKE_INSTALL_PREFIX to site.USER_SITE
# Get python user site and install path = USER_SITE + project_name
set(PYTHON_COMMAND_GET_INSTALL_DIR "import site, os ; print os.path.join(site.USER_SITE, \"${PROJECT_NAME}\")")
else() # user site not included in the path, which probably means that python is run using virtualenv
# Command to find 'global' site-package
set(GET_SITE_PACKAGE "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "${GET_SITE_PACKAGE}"
OUTPUT_VARIABLE GLOBAL_SITE_PACKAGE)
string(STRIP ${GLOBAL_SITE_PACKAGE} GLOBAL_SITE_PACKAGE)
set(PYTHON_COMMAND_GET_INSTALL_DIR ${GET_SITE_PACKAGE})
set(install-opt "")
set(PREFIX "No User prefix given, install in ${GLOBAL_SITE_PACKAGE}")
# Command to find 'global' site-package
set(GET_SITE_PACKAGE "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "${GET_SITE_PACKAGE}" OUTPUT_VARIABLE GLOBAL_SITE_PACKAGE)
string(STRIP ${GLOBAL_SITE_PACKAGE} GLOBAL_SITE_PACKAGE)
set(PYTHON_COMMAND_GET_INSTALL_DIR ${GET_SITE_PACKAGE})
set(install-opt "")
endif()
endif()
# Set the CMAKE_INSTALL_DIR to the proper path
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "${PYTHON_COMMAND_GET_INSTALL_DIR}"
OUTPUT_VARIABLE ${PROJECT_NAME}_INSTALL_DIR)
string(STRIP ${${PROJECT_NAME}_INSTALL_DIR} ${PROJECT_NAME}_INSTALL_DIR)
# set CMAKE_INSTALL_PREFIX to the site
set(CMAKE_INSTALL_PREFIX ${${PROJECT_NAME}_INSTALL_DIR})
#
#Get build dir for python
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.util as ut ; import distutils.sysconfig as sy; print 'lib.'+ut.get_platform()+'-'+sy.get_python_version()"
OUTPUT_VARIABLE ${PROJECT_NAME}_PYTHON_BUILD_DIR)
string(STRIP ${${PROJECT_NAME}_PYTHON_BUILD_DIR} ${PROJECT_NAME}_PYTHON_BUILD_DIR)
# Target to remove parmepy from install-path.
# Set the CMAKE_INSTALL_DIR to the proper path
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "${PYTHON_COMMAND_GET_INSTALL_DIR}"
OUTPUT_VARIABLE ${PROJECT_NAME}_INSTALL_DIR)
string(STRIP ${${PROJECT_NAME}_INSTALL_DIR} ${PROJECT_NAME}_INSTALL_DIR)
set(CMAKE_INSTALL_PREFIX ${${PROJECT_NAME}_INSTALL_DIR} CACHE PATH "default install path" FORCE)
if(CMAKE_PATCH_VERSION LESS 12)
set(dirToBeRemoved ${CMAKE_INSTALL_PREFIX}/..)
get_filename_component(dirToBeRemoved ${dirToBeRemoved} REALPATH)
else()
set(dirToBeRemoved ${CMAKE_INSTALL_PREFIX})
get_filename_component(dirToBeRemoved ${dirToBeRemoved} DIRECTORY)
endif()
display(dirToBeRemoved)
add_custom_target(uninstall COMMAND rm -rf ${dirToBeRemoved}/${PYPACKAGE_NAME}*
COMMENT "Remove ${dirToBeRemoved}/${PYPACKAGE_NAME} directory (parmepy package and its dependencies)")
# --- OpenCL ---
find_python_module(pyopencl REQUIRED)
......@@ -228,12 +249,6 @@ add_custom_target(python-install COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BI
install(CODE "execute_process(COMMAND ${CMAKE_BUILD_TOOL} python-install WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}\")")
# Target to remove parmepy from install-path.
# Remark : this does not work properly if a PREFIX is given by user.
# Todo : fix this.
add_custom_target(python-cleaninstall COMMAND rm -rf ${CMAKE_INSTALL_PREFIX}
COMMENT "remove parmepy package and its dependencies in ${CMAKE_INSTALL_PREFIX}.")
# Target to clean sources (remove .pyc files) and build dir.
file(GLOB_RECURSE PYCFILES "${CMAKE_SOURCE_DIR}/*.pyc")
add_custom_target(pyclean COMMAND rm -f ${PYCFILES}
......@@ -296,7 +311,6 @@ if(VERBOSE_MODE)
message(STATUS " Python executable : ${PYTHON_EXECUTABLE}")
message(STATUS " Python user lib : ${PYTHON_LIBRARY}")
message(STATUS " Python user include : ${PYTHON_INCLUDE_DIR}")
message(STATUS " Python install base : ${PREFIX}")
message(STATUS " Install directory : ${CMAKE_INSTALL_PREFIX}")
message(STATUS " Fortran compiler : ${CMAKE_Fortran_COMPILER}")
message(STATUS " Sources are in : ${CMAKE_SOURCE_DIR}")
......@@ -311,10 +325,10 @@ if(VERBOSE_MODE)
message(STATUS " ")
message(STATUS "Try :")
message(STATUS " 'make -jN' to build the project, N being the number of available processes.")
message(STATUS " 'make python-install' to install python modules and their dependencies. ")
message(STATUS " 'make install' to install python modules and their dependencies. ")
message(STATUS " 'make doc' to generate doxygen documentation for parmepy.")
message(STATUS " 'make test' to run some test (after the build!).")
message(STATUS " 'make clean' to clean build directory.")
message(STATUS " 'make python-cleaninstall' to clean install directory.")
message(STATUS " 'make uninstall' to clean install directory. Dry-run (make -n uninstall) is advisable to check what will really be deleted.")
endif()
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