Statistics
| Branch: | Tag: | Revision:

root / host / cmake / Modules / UHDPython.cmake @ f0ac072a

History | View | Annotate | Download (2.87 KB)

1
#
2
# Copyright 2010-2011 Ettus Research LLC
3
#
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
IF(NOT DEFINED INCLUDED_UHD_PYTHON_CMAKE)
19
SET(INCLUDED_UHD_PYTHON_CMAKE TRUE)
20

    
21
########################################################################
22
# Setup Python
23
########################################################################
24
MESSAGE(STATUS "")
25
MESSAGE(STATUS "Configuring the python interpreter...")
26
#this allows the user to override PYTHON_EXECUTABLE
27
IF(PYTHON_EXECUTABLE)
28

    
29
    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
    IF(NOT PYTHONINTERP_FOUND)
39
        FIND_PROGRAM(PYTHON_EXECUTABLE NAMES python python2.7 python2.6)
40
        IF(PYTHON_EXECUTABLE)
41
            SET(PYTHONINTERP_FOUND TRUE)
42
        ENDIF(PYTHON_EXECUTABLE)
43
    ENDIF(NOT PYTHONINTERP_FOUND)
44

    
45
ENDIF(PYTHON_EXECUTABLE)
46

    
47
#make the path to the executable appear in the cmake gui
48
SET(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "python interpreter")
49

    
50
MESSAGE(STATUS "Python interpreter: ${PYTHON_EXECUTABLE}")
51
MESSAGE(STATUS "Override with: -DPYTHON_EXECUTABLE=<path-to-python>")
52

    
53
IF(NOT PYTHONINTERP_FOUND)
54
    MESSAGE(FATAL_ERROR "Error: Python interpretor required by the build system.")
55
ENDIF(NOT PYTHONINTERP_FOUND)
56

    
57
MACRO(PYTHON_CHECK_MODULE desc mod cmd have)
58
    MESSAGE(STATUS "")
59
    MESSAGE(STATUS "Python checking for ${desc}")
60
    EXECUTE_PROCESS(
61
        COMMAND ${PYTHON_EXECUTABLE} -c "
62
#########################################
63
try: import ${mod}
64
except: exit(1)
65
try: assert ${cmd}
66
except: exit(2)
67
exit(0)
68
#########################################"
69
        RESULT_VARIABLE ${have}
70
    )
71
    IF(${have} EQUAL 0)
72
        MESSAGE(STATUS "Python checking for ${desc} - found")
73
        SET(${have} TRUE)
74
    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
        SET(${have} FALSE)
80
    ELSE()
81
        MESSAGE(STATUS "Python checking for ${desc} - unknown error")
82
        SET(${have} FALSE)
83
    ENDIF()
84
ENDMACRO(PYTHON_CHECK_MODULE)
85

    
86
ENDIF(NOT DEFINED INCLUDED_UHD_PYTHON_CMAKE)