diff --git a/CMakeLists.txt b/CMakeLists.txt index 1037ab208..7a62a9e35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,9 @@ include(buildpresets.cmake) # include Modules list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules") +# include pythonAux Macros +include(${PROJECT_SOURCE_DIR}/cmake/pythonAux.cmake) + #check compiller if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") include(CheckCXXCompilerFlag) @@ -89,32 +92,6 @@ macro(list_subdirectories2 retval curdir return_relative) set(${retval} ${list_of_dirs}) endmacro() -#macro to switch pythonInterp -macro(usePython ver) - if (${ver} EQUAL 2 AND ${PYTHON2INTERP_FOUND}) - set(PYTHON_EXECUTABLE ${PYTHON2_EXECUTABLE}) - set(PYTHON_VERSION_STRING ${PYTHON2_VERSION_STRING}) - set(PYTHON_VERSION_MAJOR ${PYTHON2_VERSION_MAJOR}) - set(PYTHON_VERSION_MINOR ${PYTHON2_VERSION_MINOR}) - set(PYTHON_VERSION_PATCH ${PYTHON2_VERSION_PATCH}) - set(PYTHONINTERP_FOUND TRUE) - elseif(${ver} EQUAL 3 AND ${PYTHON3INTERP_FOUND}) - set(PYTHON_EXECUTABLE ${PYTHON3_EXECUTABLE}) - set(PYTHON_VERSION_STRING ${PYTHON3_VERSION_STRING}) - set(PYTHON_VERSION_MAJOR ${PYTHON3_VERSION_MAJOR}) - set(PYTHON_VERSION_MINOR ${PYTHON3_VERSION_MINOR}) - set(PYTHON_VERSION_PATCH ${PYTHON3_VERSION_PATCH}) - set(PYTHONINTERP_FOUND TRUE) - else(${ver} EQUAL 2 AND ${PYTHON2INTERP_FOUND}) - unset(PYTHON_EXECUTABLE) - unset(PYTHON_VERSION_STRING) - unset(PYTHON_VERSION_MAJOR) - unset(PYTHON_VERSION_MINOR) - unset(PYTHON_VERSION_PATCH) - set(PYTHONINTERP_FOUND FALSE) - endif(${ver} EQUAL 2 AND ${PYTHON2INTERP_FOUND}) -endmacro() - ################### diff --git a/Deps/findPythonModules/CMakeLists.txt b/Deps/findPythonModules/CMakeLists.txt deleted file mode 100644 index 82fdd33a8..000000000 --- a/Deps/findPythonModules/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# Find if a Python module is installed -# Found at http://www.cmake.org/pipermail/cmake/2011-January/041666.html -# To use do: find_python_module(PyQt5 REQUIRED) -function(find_python_module module) - string(TOUPPER ${module} module_upper) - if(NOT PY_${module_upper}) - if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED") - set(${module}_FIND_REQUIRED TRUE) - endif() - # A module's location is usually a directory, but for binary modules - # it's a .so file. - message(STATUS ${module}) - set(python_cmd "/usr/bin/python3") - execute_process(COMMAND "${python_cmd}" "-c" - "import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))" - RESULT_VARIABLE _${module}_status - OUTPUT_VARIABLE _${module}_location - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - if(NOT _${module}_status ) - set(PY_${module_upper} ${_${module}_location} CACHE STRING - "Location of Python module ${module}") - endif(NOT _${module}_status ) - endif(NOT PY_${module_upper}) - find_package_handle_standard_args(PY_${module} DEFAULT_MSG PY_${module_upper}) -endfunction(find_python_module) diff --git a/Deps/python/CMakeLists.txt b/Deps/python/CMakeLists.txt index 282a3790a..8a8909039 100644 --- a/Deps/python/CMakeLists.txt +++ b/Deps/python/CMakeLists.txt @@ -1,18 +1,6 @@ find_package(Python3Interp) find_package(Python2Interp) -usePython(3) +message(${PYTHON3_MODULE_PATH}) -execute_process( - COMMAND ${PYTHON_EXECUTABLE} -c "import os;print(os.path.dirname(os.__file__))" - RESULT_VARIABLE _RESULT - OUTPUT_VARIABLE PYTHON_MODULE_PATH - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -if(_RESULT) - message(FATAL_ERROR "Failed to determine python information") -endif(_RESULT) -unset(_RESULT) - -message(${PYTHON_MODULE_PATH}) +message(${PYTHON2_MODULE_PATH}) diff --git a/Deps/findPythonModules/ice_py/CMakeLists.txt b/Deps/python/Modules/ice_py/CMakeLists.txt similarity index 95% rename from Deps/findPythonModules/ice_py/CMakeLists.txt rename to Deps/python/Modules/ice_py/CMakeLists.txt index 9c269d565..f26a821ca 100644 --- a/Deps/findPythonModules/ice_py/CMakeLists.txt +++ b/Deps/python/Modules/ice_py/CMakeLists.txt @@ -1,4 +1,6 @@ set(module "Ice") + +usePython(2) find_python_module(${module} REQUIRED) string(TOUPPER ${module} module_upper) diff --git a/Deps/findPythonModules/matplotlib_py/CMakeLists.txt b/Deps/python/Modules/matplotlib_py/CMakeLists.txt similarity index 64% rename from Deps/findPythonModules/matplotlib_py/CMakeLists.txt rename to Deps/python/Modules/matplotlib_py/CMakeLists.txt index e391109a6..e4920a2ff 100644 --- a/Deps/findPythonModules/matplotlib_py/CMakeLists.txt +++ b/Deps/python/Modules/matplotlib_py/CMakeLists.txt @@ -1,10 +1,12 @@ set(module "matplotlib") + +usePython(2) find_python_module(${module} REQUIRED) string(TOUPPER ${module} module_upper) if(PY_${module_upper}) SET (MATPLOTLIB_PY_MODULES PY_${module_upper}) - list(APPEND DEPS python3-matplotlib) - list(APPEND DEPS_DEV python3-matplotlib) + list(APPEND DEPS python-matplotlib) + list(APPEND DEPS_DEV python-matplotlib python3-matplotlib) endif(PY_${module_upper}) diff --git a/Deps/findPythonModules/numpy/CMakeLists.txt b/Deps/python/Modules/numpy/CMakeLists.txt similarity index 66% rename from Deps/findPythonModules/numpy/CMakeLists.txt rename to Deps/python/Modules/numpy/CMakeLists.txt index f07ec7c95..eece47996 100644 --- a/Deps/findPythonModules/numpy/CMakeLists.txt +++ b/Deps/python/Modules/numpy/CMakeLists.txt @@ -1,11 +1,13 @@ set(module "numpy") + +usePython(2) find_python_module(${module} REQUIRED) string(TOUPPER ${module} module_upper) if(PY_${module_upper}) SET (NUMPY_MODULES PY_${module_upper}) - list(APPEND DEPS "python3-numpy") - list(APPEND DEPS_DEV "python3-numpy") + list(APPEND DEPS python-numpy) + list(APPEND DEPS_DEV python-numpy python3-numpy) endif(PY_${module_upper}) diff --git a/Deps/findPythonModules/opencv_py/CMakeLists.txt b/Deps/python/Modules/opencv_py/CMakeLists.txt similarity index 69% rename from Deps/findPythonModules/opencv_py/CMakeLists.txt rename to Deps/python/Modules/opencv_py/CMakeLists.txt index 7d8415062..ef4a7d364 100644 --- a/Deps/findPythonModules/opencv_py/CMakeLists.txt +++ b/Deps/python/Modules/opencv_py/CMakeLists.txt @@ -1,10 +1,12 @@ set(module "cv2") + +usePython(2) find_python_module(${module} REQUIRED) string(TOUPPER ${module} module_upper) if(PY_${module_upper}) SET (OpenCV_PY_MODULES PY_${module_upper}) - list(APPEND DEPS "opencv-python") - list(APPEND DEPS_DEV "opencv-python") + list(APPEND DEPS opencv-python) + list(APPEND DEPS_DEV opencv-python) endif(PY_${module_upper}) diff --git a/Deps/findPythonModules/pip/CMakeLists.txt b/Deps/python/Modules/pip/CMakeLists.txt similarity index 67% rename from Deps/findPythonModules/pip/CMakeLists.txt rename to Deps/python/Modules/pip/CMakeLists.txt index 38277b050..4099f7833 100644 --- a/Deps/findPythonModules/pip/CMakeLists.txt +++ b/Deps/python/Modules/pip/CMakeLists.txt @@ -1,10 +1,12 @@ set(module "pip") + +usePython(3) find_python_module(${module} REQUIRED) string(TOUPPER ${module} module_upper) if(PY_${module_upper}) SET (OpenCV_PY_MODULES PY_${module_upper}) - list(APPEND DEPS "python3-pip") - list(APPEND DEPS_DEV "python3-pip") + list(APPEND DEPS python-pip) + list(APPEND DEPS_DEV python-pip python3-pip) endif(PY_${module_upper}) \ No newline at end of file diff --git a/Deps/findPythonModules/pyqt5/CMakeLists.txt b/Deps/python/Modules/pyqt5/CMakeLists.txt similarity index 55% rename from Deps/findPythonModules/pyqt5/CMakeLists.txt rename to Deps/python/Modules/pyqt5/CMakeLists.txt index c520e6486..dca1b2bdc 100644 --- a/Deps/findPythonModules/pyqt5/CMakeLists.txt +++ b/Deps/python/Modules/pyqt5/CMakeLists.txt @@ -1,11 +1,13 @@ set(module "PyQt5") + +usePython(2) find_python_module(${module} REQUIRED) string(TOUPPER ${module} module_upper) if(PY_${module_upper}) SET (QT5_PY_MODULES PY_${module_upper}) - list(APPEND DEPS python3-pyqt5 python3-pyqt5.qtsvg) - list(APPEND DEPS_DEV python3-pyqt5 python3-pyqt5.qtsvg) + list(APPEND DEPS python-pyqt5 python-pyqt5.qtsvg) + list(APPEND DEPS_DEV python-pyqt5 python-pyqt5.qtsvg python3-pyqt5 python3-pyqt5.qtsvg) endif(PY_${module_upper}) diff --git a/cmake/modules/FindPython2Interp.cmake b/cmake/modules/FindPython2Interp.cmake index f2d57ccf6..422997d83 100644 --- a/cmake/modules/FindPython2Interp.cmake +++ b/cmake/modules/FindPython2Interp.cmake @@ -20,10 +20,10 @@ # PYTHON2_VERSION_PATCH - Python patch version found e.g. 2 # # Nuke the cache, somebody might have looked for Python 2... -# copy from: https://gitlab.dune-project.org/quality/dune-python/blob/694ae69fe57de42b1a87373ed9eea8d76a1ebfd3/cmake/modules/FindPython2Interp.cmake +# copied from: https://gitlab.dune-project.org/quality/dune-python/blob/694ae69fe57de42b1a87373ed9eea8d76a1ebfd3/cmake/modules/FindPython2Interp.cmake unset(PYTHON_EXECUTABLE CACHE) set(PYTHONINTERP_FOUND FALSE) -find_package(PythonInterp 2) +find_package(PythonInterp 2 REQUIRED) find_package_handle_standard_args(Python2Interp REQUIRED_VARS PYTHONINTERP_FOUND) # Set all those variables that we promised @@ -35,4 +35,17 @@ set(PYTHON2_VERSION_PATCH ${PYTHON_VERSION_PATCH}) # Now nuke the cache to allow later rerunning of find_package(PythonInterp) # with a different required version number. unset(PYTHON_EXECUTABLE CACHE) -set(PYTHONINTERP_FOUND FALSE) \ No newline at end of file +set(PYTHONINTERP_FOUND FALSE) + +#Searching module path of python2 +execute_process( + COMMAND ${PYTHON2_EXECUTABLE} -c "import os;print(os.path.dirname(os.__file__))" + RESULT_VARIABLE _RESULT + OUTPUT_VARIABLE PYTHON2_MODULE_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if(_RESULT) + message(FATAL_ERROR "Failed to determine python information") +endif(_RESULT) +unset(_RESULT) \ No newline at end of file diff --git a/cmake/modules/FindPython3Interp.cmake b/cmake/modules/FindPython3Interp.cmake index a9375c1bc..80f0d3889 100644 --- a/cmake/modules/FindPython3Interp.cmake +++ b/cmake/modules/FindPython3Interp.cmake @@ -25,7 +25,7 @@ unset(PYTHON_EXECUTABLE CACHE) set(PYTHONINTERP_FOUND FALSE) -find_package(PythonInterp 3) +find_package(PythonInterp 3 REQUIRED) find_package_handle_standard_args(Python3Interp REQUIRED_VARS PYTHONINTERP_FOUND) # Set all those variables that we promised @@ -37,4 +37,18 @@ set(PYTHON3_VERSION_PATCH ${PYTHON_VERSION_PATCH}) # Now nuke the cache to allow later rerunning of find_package(PythonInterp) # with a different required version number. unset(PYTHON_EXECUTABLE CACHE) -set(PYTHONINTERP_FOUND FALSE) \ No newline at end of file +set(PYTHONINTERP_FOUND FALSE) + + +#Searching module path of python3 +execute_process( + COMMAND ${PYTHON3_EXECUTABLE} -c "import os;print(os.path.dirname(os.__file__))" + RESULT_VARIABLE _RESULT + OUTPUT_VARIABLE PYTHON3_MODULE_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if(_RESULT) + message(FATAL_ERROR "Failed to determine python information") +endif(_RESULT) +unset(_RESULT) \ No newline at end of file diff --git a/src/libs/easyiceconfig_py/CMakeLists.txt b/src/libs/easyiceconfig_py/CMakeLists.txt index a3dc50f11..dff0a92c8 100644 --- a/src/libs/easyiceconfig_py/CMakeLists.txt +++ b/src/libs/easyiceconfig_py/CMakeLists.txt @@ -1,28 +1,8 @@ cmake_minimum_required(VERSION 2.8) -configure_file( - easyiceconfig/hardcodedpaths.py.in - easyiceconfig/hardcodedpaths.py - @ONLY -) - -file(GLOB ModuleFiles - RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/easyiceconfig - ${CMAKE_CURRENT_SOURCE_DIR}/easyiceconfig/*) - -string(REGEX REPLACE "[^;]+\\.in;?" "" ModuleFiles "${ModuleFiles}") - +configure_module_python(easyiceconfig) add_custom_target(easyiceconfig_py ALL) -foreach(ModuleFile ${ModuleFiles}) - add_custom_command(TARGET easyiceconfig_py - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_SOURCE_DIR}/easyiceconfig/${ModuleFile} ${CMAKE_CURRENT_BINARY_DIR}/easyiceconfig/${ModuleFile} - ) -endforeach(ModuleFile ${ModuleFiles}) +copy_to_binary_python(easyiceconfig_py easyiceconfig) -### Install -install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/easyiceconfig - DESTINATION ${PYTHON_MODULE_PATH} - COMPONENT core -) +install_python(easyiceconfig core) diff --git a/src/libs/easyiceconfig_py/easyiceconfig/easyiceconfig.py b/src/libs/easyiceconfig_py/easyiceconfig/easyiceconfig.py index 3fe2d37c0..b06334ad7 100644 --- a/src/libs/easyiceconfig_py/easyiceconfig/easyiceconfig.py +++ b/src/libs/easyiceconfig_py/easyiceconfig/easyiceconfig.py @@ -22,7 +22,7 @@ import re import Ice -from easyiceconfig.hardcodedpaths import HARDCODED_PATHS +from .hardcodedpaths import HARDCODED_PATHS ENV_PATH_NAME = "ICE_CONFIG_PATH" diff --git a/src/libs/parallelIce_py/CMakeLists.txt b/src/libs/parallelIce_py/CMakeLists.txt index b9df5b61d..c02e2cc09 100644 --- a/src/libs/parallelIce_py/CMakeLists.txt +++ b/src/libs/parallelIce_py/CMakeLists.txt @@ -1,11 +1,8 @@ cmake_minimum_required(VERSION 2.8) -### Install +configure_module_python(parallelIce) -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/parallelIce +add_custom_target(parallelIce_py ALL) +copy_to_binary_python(parallelIce_py parallelIce) - DESTINATION ${PYTHON_MODULE_PATH} - - COMPONENT core - -) \ No newline at end of file +install_python(parallelIce core)