1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 20:50:33 +00:00
gnss-sdr/cmake/Modules/SetupPython.cmake

88 lines
3.4 KiB
CMake
Raw Normal View History

2018-04-29 10:02:40 +00:00
# Copyright (C) 2011-2018 (see AUTHORS file for a list of contributors)
#
# This file is part of GNSS-SDR.
#
# GNSS-SDR is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GNSS-SDR is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
2018-04-29 10:02:40 +00:00
2016-12-25 19:42:20 +00:00
########################################################################
# Setup the python interpreter:
# This allows the user to specify a specific interpreter,
# or finds the interpreter via the built-in cmake module.
########################################################################
if (PYTHON_EXECUTABLE)
message(STATUS "User set python executable ${PYTHON_EXECUTABLE}")
find_package(PythonInterp ${GNSSSDR_PYTHON_MIN_VERSION} REQUIRED)
else (PYTHON_EXECUTABLE)
message(STATUS "PYTHON_EXECUTABLE not set - using default python2")
find_package(PythonInterp ${GNSSSDR_PYTHON_MIN_VERSION})
if(NOT PYTHONINTERP_FOUND)
# message(STATUS "Use -DPYTHON_EXECUTABLE=/path/to/python2 to build for python2.")
message(STATUS "python2 not found - using python3")
find_package(PythonInterp ${GNSSSDR_PYTHON3_MIN_VERSION} REQUIRED)
endif(NOT PYTHONINTERP_FOUND)
endif (PYTHON_EXECUTABLE)
2016-12-25 19:42:20 +00:00
if (${PYTHON_VERSION_MAJOR} VERSION_EQUAL 3)
set(PYTHON3 TRUE)
endif ()
2016-12-25 19:42:20 +00:00
find_package(PythonLibs ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} EXACT)
2016-12-25 19:42:20 +00:00
2016-12-26 11:29:05 +00:00
if (CMAKE_CROSSCOMPILING)
set(QA_PYTHON_EXECUTABLE "/usr/bin/python")
else (CMAKE_CROSSCOMPILING)
set(QA_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
endif(CMAKE_CROSSCOMPILING)
2016-12-25 19:42:20 +00:00
#make the path to the executable appear in the cmake gui
set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "python interpreter")
2016-12-26 11:29:05 +00:00
set(QA_PYTHON_EXECUTABLE ${QA_PYTHON_EXECUTABLE} CACHE FILEPATH "python interpreter for QA tests")
2016-12-25 19:42:20 +00:00
########################################################################
# Check for the existence of a python module:
# - desc a string description of the check
# - mod the name of the module to import
# - cmd an additional command to run
# - have the result variable to set
########################################################################
macro(GNSSSDR_PYTHON_CHECK_MODULE_RAW desc python_code have)
2016-12-25 19:42:20 +00:00
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "${python_code}"
OUTPUT_QUIET ERROR_QUIET
RESULT_VARIABLE return_code
2016-12-25 19:42:20 +00:00
)
if(return_code EQUAL 0)
2016-12-25 19:42:20 +00:00
message(STATUS "Python checking for ${desc} - found")
set(${have} TRUE)
else()
2016-12-25 19:42:20 +00:00
message(STATUS "Python checking for ${desc} - not found")
set(${have} FALSE)
endif()
endmacro(GNSSSDR_PYTHON_CHECK_MODULE_RAW)
macro(GNSSSDR_PYTHON_CHECK_MODULE desc mod cmd have)
GNSSSDR_PYTHON_CHECK_MODULE_RAW(
"${desc}" "
#########################################
try:
import ${mod}
assert ${cmd}
except (ImportError, AssertionError): exit(-1)
except: pass
#########################################"
"${have}")
2016-12-25 19:42:20 +00:00
endmacro(GNSSSDR_PYTHON_CHECK_MODULE)