|
| 1 | +# Version 0.5 (21/6/23, support Python 2/Python 3, répertoire d'installation des modules python fourni par le python utilisé) |
| 2 | + |
| 3 | +# Par défaut on utilise Python 2 |
| 4 | + |
1 | 5 | include (GNUInstallDirs) |
2 | 6 | find_package (SWIG 3 REQUIRED) |
3 | 7 |
|
4 | | -include (${SWIG_USE_FILE}) |
5 | 8 |
|
6 | 9 | #find_package (Python REQUIRED COMPONENTS Interpreter Development) # Rem : Python3 a la priorité => inutilisé car empêche l'accès à Python2 |
7 | | -if (NOT USE_PYTHON_3) |
| 10 | +if (USE_PYTHON_3) |
| 11 | + message (STATUS "========================================= UTILISATION DE PYTHON 3 =========================================") |
| 12 | + find_package (Python3 REQUIRED COMPONENTS Interpreter Development) |
| 13 | + set (Python_INCLUDE_DIRS ${Python3_INCLUDE_DIRS}) |
| 14 | + set (Python_EXECUTABLE ${Python3_EXECUTABLE}) |
| 15 | + set (Python_VERSION ${Python3_VERSION}) |
| 16 | + set (Python_LIBRARIES ${Python3_LIBRARIES}) |
| 17 | + set (Python_LIBRARY_DIRS ${Python3_LIBRARY_DIRS}) |
| 18 | + set (PYTHON_MAJOR_VERSION 3) |
| 19 | +elseif (USE_PYTHON_2) |
| 20 | + message (STATUS "========================================= UTILISATION DE PYTHON 2 =========================================") |
8 | 21 | find_package (Python2 REQUIRED COMPONENTS Interpreter Development) |
9 | | - set (PYTHON_BINDING_DIR ${CMAKE_INSTALL_LIBDIR}/python${Python2_VERSION_MAJOR}.${Python2_VERSION_MINOR}/site-packages/) |
10 | 22 | set (Python_INCLUDE_DIRS ${Python2_INCLUDE_DIRS}) |
| 23 | + set (Python_EXECUTABLE ${Python2_EXECUTABLE}) |
| 24 | + set (Python_VERSION ${Python2_VERSION}) |
| 25 | + set (Python_LIBRARIES ${Python2_LIBRARIES}) |
| 26 | + set (Python_LIBRARY_DIRS ${Python2_LIBRARY_DIRS}) |
11 | 27 | set (PYTHON_MAJOR_VERSION 2) |
12 | 28 | else ( ) |
13 | | - find_package (Python3 REQUIRED COMPONENTS Interpreter Development) |
14 | | - set (PYTHON_BINDING_DIR ${CMAKE_INSTALL_LIBDIR}/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/) |
15 | | - set (Python_INCLUDE_DIRS ${Python3_INCLUDE_DIRS}) |
16 | | - set (PYTHON_MAJOR_VERSION 3) |
17 | | -endif (NOT USE_PYTHON_3) |
| 29 | + message (STATUS "========================================= VERSION DE PYTHON NON DEFINIE =========================================") |
| 30 | + message (FATAL_ERROR "==> UTILISEZ -DUSE_PYTHON_2 OU -DUSE_PYTHON_3 A LA LIGNE DE COMMANDE") |
| 31 | +endif (USE_PYTHON_3) |
| 32 | + |
| 33 | + |
| 34 | +# Recherche du répertoire d'installation des modules (procédure spack organizer) : |
| 35 | +# get python installation path |
| 36 | +macro (_set_from_python outvar python_code) |
| 37 | + if (NOT ${outvar}) |
| 38 | + execute_process ( |
| 39 | + COMMAND ${Python_EXECUTABLE} -c "${python_code}" |
| 40 | + OUTPUT_VARIABLE ${outvar} |
| 41 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 42 | + if (NOT ${outvar}) |
| 43 | + message (FATAL_ERROR "Failed to detect ${outvar} from command:${Python_EXECUTABLE} -c ${python_code}") |
| 44 | + endif ( ) |
| 45 | + endif ( ) |
| 46 | +endmacro ( ) |
| 47 | + |
| 48 | +_set_from_python (_GET_PYTHON_SITEARCH "import sys; from distutils import sysconfig; sys.stdout.write (sysconfig.get_python_lib (plat_specific=True, standard_lib=False, prefix=''))") |
| 49 | +set (PYTHON_BINDING_DIR ${_GET_PYTHON_SITEARCH}) |
| 50 | +set (CMAKE_PYTHON_RPATH_DIR ${CMAKE_INSTALL_PREFIX}/${_GET_PYTHON_SITEARCH}) |
| 51 | + |
| 52 | +include (${SWIG_USE_FILE}) |
| 53 | + |
| 54 | +message (STATUS "========================================= VARIABLES LIEES A PYTHON =========================================") |
| 55 | +message (STATUS "PYTHON_BINDING_DIR=${PYTHON_BINDING_DIR}") |
| 56 | +message (STATUS "Python_INCLUDE_DIRS=${Python_INCLUDE_DIRS}") |
| 57 | +message (STATUS "Python_EXECUTABLE=${Python_EXECUTABLE}") |
| 58 | +message (STATUS "Python_VERSION=${Python_VERSION} PYTHON_MAJOR_VERSION=${PYTHON_MAJOR_VERSION}") |
| 59 | +message (STATUS "Python_LIBRARIES=${Python_LIBRARIES}") |
| 60 | +message (STATUS "Python_LIBRARY_DIRS=${Python_LIBRARY_DIRS}") |
| 61 | +message (STATUS "PYTHON_BINDING_DIR=${PYTHON_BINDING_DIR}") |
| 62 | +message (STATUS "CMAKE_PYTHON_RPATH_DIR=${CMAKE_PYTHON_RPATH_DIR}") |
| 63 | +message (STATUS "============================================================================================================") |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
18 | 68 |
|
19 | | -# Répertoire d'installation des modules (pour le RPATH) : |
20 | | -set (CMAKE_PYTHON_RPATH_DIR ${CMAKE_INSTALL_PREFIX}/${PYTHON_BINDING_DIR}) |
21 | 69 |
|
0 commit comments