Salome HOME
974887e6c25a140470d02f04298ca3aefefbe9a5
[tools/solverlab.git] / CDMATH / cmake_files / FindMatplotlib.cmake
1 # - Find the matplotlib libraries
2 # This module finds IF matplotlib is installed, and sets the following variables
3 # indicating where it is.
4 #
5 #  MATPLOTLIB_FOUND            - was matplotlib found
6 #  MATPLOTLIB_VERSION          - the version of matplotlib found as a string
7 #  MATPLOTLIB_VERSION_MAJOR    - the major version number of matplotlib
8 #  MATPLOTLIB_VERSION_MINOR    - the minor version number of matplotlib
9 #  MATPLOTLIB_VERSION_PATCH    - the patch version number of matplotlib
10 #  MATPLOTLIB_PATH_DIRS        - path to the matplotlib include files
11
12 IF(PYTHONINTERP_FOUND)
13     # Try to import matplotlib into Python interpreter. Python
14     # interpreter was found previously as required package, so
15     # don't take care about this.
16     execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
17         "import matplotlib as m; print(m.__version__); print(m.__path__[0]);"
18         RESULT_VARIABLE _MATPLOTLIB_SEARCH_SUCCESS
19         OUTPUT_VARIABLE _MATPLOTLIB_VALUES
20         ERROR_VARIABLE _MATPLOTLIB_ERROR_VALUE
21         OUTPUT_STRIP_TRAILING_WHITESPACE)
22
23     IF(_MATPLOTLIB_SEARCH_SUCCESS MATCHES 0)
24         set(MATPLOTLIB_FOUND TRUE)
25
26         # Convert the process output into a list
27         string(REGEX REPLACE ";" "\\\\;" _MATPLOTLIB_VALUES ${_MATPLOTLIB_VALUES})
28         string(REGEX REPLACE "\n" ";" _MATPLOTLIB_VALUES ${_MATPLOTLIB_VALUES})
29         list(GET _MATPLOTLIB_VALUES 0 MATPLOTLIB_VERSION)
30         list(GET _MATPLOTLIB_VALUES 1 MATPLOTLIB_PATH_DIRS)
31
32         # Make sure all directory separators are '/'
33         string(REGEX REPLACE "\\\\" "/" MATPLOTLIB_PATH_DIRS ${MATPLOTLIB_PATH_DIRS})
34
35         # Get the major and minor version numbers
36         string(REGEX REPLACE "\\." ";" _MATPLOTLIB_VERSION_LIST ${MATPLOTLIB_VERSION})
37         list(GET _MATPLOTLIB_VERSION_LIST 0 MATPLOTLIB_VERSION_MAJOR)
38         list(GET _MATPLOTLIB_VERSION_LIST 1 MATPLOTLIB_VERSION_MINOR)
39         list(GET _MATPLOTLIB_VERSION_LIST 2 MATPLOTLIB_VERSION_PATCH)
40     ELSE()
41         set(MATPLOTLIB_FOUND FALSE)
42     ENDIF()
43 ELSE()
44     set(MATPLOTLIB_FOUND FALSE)
45 ENDIF()
46