root / host / cmake / Modules / UHDPython.cmake @ f0ac072a
History | View | Annotate | Download (2.87 KB)
| 1 | 3f1d313c | Josh Blum | # |
|---|---|---|---|
| 2 | 95b966a5 | Josh Blum | # Copyright 2010-2011 Ettus Research LLC |
| 3 | 3f1d313c | Josh Blum | # |
| 4 | # This program is free software: you can redistribute it and/or modify |
||
| 5 | # it under the terms of the GNU General Public License as published by |
||
| 6 | # the Free Software Foundation, either version 3 of the License, or |
||
| 7 | # (at your option) any later version. |
||
| 8 | # |
||
| 9 | # This program is distributed in the hope that it will be useful, |
||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 12 | # GNU General Public License for more details. |
||
| 13 | # |
||
| 14 | # You should have received a copy of the GNU General Public License |
||
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
| 16 | # |
||
| 17 | |||
| 18 | 5e8b0752 | Josh Blum | IF(NOT DEFINED INCLUDED_UHD_PYTHON_CMAKE) |
| 19 | SET(INCLUDED_UHD_PYTHON_CMAKE TRUE) |
||
| 20 | |||
| 21 | 3f1d313c | Josh Blum | ######################################################################## |
| 22 | # Setup Python |
||
| 23 | ######################################################################## |
||
| 24 | 5e8b0752 | Josh Blum | MESSAGE(STATUS "") |
| 25 | MESSAGE(STATUS "Configuring the python interpreter...") |
||
| 26 | 3017907f | Josh Blum | #this allows the user to override PYTHON_EXECUTABLE |
| 27 | IF(PYTHON_EXECUTABLE) |
||
| 28 | 3f1d313c | Josh Blum | |
| 29 | 3017907f | Josh Blum | SET(PYTHONINTERP_FOUND TRUE) |
| 30 | |||
| 31 | #otherwise if not set, try to automatically find it |
||
| 32 | ELSE(PYTHON_EXECUTABLE) |
||
| 33 | |||
| 34 | #use the built-in find script |
||
| 35 | FIND_PACKAGE(PythonInterp) |
||
| 36 | |||
| 37 | #and if that fails use the find program routine |
||
| 38 | 9d50dea1 | Josh Blum | IF(NOT PYTHONINTERP_FOUND) |
| 39 | e49f94f4 | Josh Blum | FIND_PROGRAM(PYTHON_EXECUTABLE NAMES python python2.7 python2.6) |
| 40 | 3017907f | Josh Blum | IF(PYTHON_EXECUTABLE) |
| 41 | SET(PYTHONINTERP_FOUND TRUE) |
||
| 42 | ENDIF(PYTHON_EXECUTABLE) |
||
| 43 | 9d50dea1 | Josh Blum | ENDIF(NOT PYTHONINTERP_FOUND) |
| 44 | 3017907f | Josh Blum | |
| 45 | ENDIF(PYTHON_EXECUTABLE) |
||
| 46 | |||
| 47 | #make the path to the executable appear in the cmake gui |
||
| 48 | d0244e83 | Josh Blum | SET(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "python interpreter")
|
| 49 | 3017907f | Josh Blum | |
| 50 | 5e8b0752 | Josh Blum | MESSAGE(STATUS "Python interpreter: ${PYTHON_EXECUTABLE}")
|
| 51 | MESSAGE(STATUS "Override with: -DPYTHON_EXECUTABLE=<path-to-python>") |
||
| 52 | |||
| 53 | 3017907f | Josh Blum | IF(NOT PYTHONINTERP_FOUND) |
| 54 | MESSAGE(FATAL_ERROR "Error: Python interpretor required by the build system.") |
||
| 55 | ENDIF(NOT PYTHONINTERP_FOUND) |
||
| 56 | 3f1d313c | Josh Blum | |
| 57 | 904332c7 | Josh Blum | MACRO(PYTHON_CHECK_MODULE desc mod cmd have) |
| 58 | 5e4875eb | Josh Blum | MESSAGE(STATUS "") |
| 59 | 904332c7 | Josh Blum | MESSAGE(STATUS "Python checking for ${desc}")
|
| 60 | 3f1d313c | Josh Blum | EXECUTE_PROCESS( |
| 61 | 904332c7 | Josh Blum | COMMAND ${PYTHON_EXECUTABLE} -c "
|
| 62 | ######################################### |
||
| 63 | try: import ${mod}
|
||
| 64 | 5e8b0752 | Josh Blum | except: exit(1) |
| 65 | 904332c7 | Josh Blum | try: assert ${cmd}
|
| 66 | 5e8b0752 | Josh Blum | except: exit(2) |
| 67 | exit(0) |
||
| 68 | 904332c7 | Josh Blum | #########################################" |
| 69 | 3f1d313c | Josh Blum | RESULT_VARIABLE ${have}
|
| 70 | ) |
||
| 71 | IF(${have} EQUAL 0)
|
||
| 72 | 904332c7 | Josh Blum | MESSAGE(STATUS "Python checking for ${desc} - found")
|
| 73 | 3f1d313c | Josh Blum | SET(${have} TRUE)
|
| 74 | 5e8b0752 | Josh Blum | ELSEIF(${have} EQUAL 1)
|
| 75 | MESSAGE(STATUS "Python checking for ${desc} - \"import ${mod}\" failed")
|
||
| 76 | SET(${have} FALSE)
|
||
| 77 | ELSEIF(${have} EQUAL 2)
|
||
| 78 | MESSAGE(STATUS "Python checking for ${desc} - \"assert ${cmd}\" failed")
|
||
| 79 | 3f1d313c | Josh Blum | SET(${have} FALSE)
|
| 80 | 5e8b0752 | Josh Blum | ELSE() |
| 81 | MESSAGE(STATUS "Python checking for ${desc} - unknown error")
|
||
| 82 | SET(${have} FALSE)
|
||
| 83 | ENDIF() |
||
| 84 | 3f1d313c | Josh Blum | ENDMACRO(PYTHON_CHECK_MODULE) |
| 85 | 5e8b0752 | Josh Blum | |
| 86 | ENDIF(NOT DEFINED INCLUDED_UHD_PYTHON_CMAKE) |