aboutsummaryrefslogtreecommitdiff
path: root/cmake/FindPythonModules.cmake
diff options
context:
space:
mode:
authorGyorgy Szing <Gyorgy.Szing@arm.com>2018-09-27 17:00:46 +0200
committerGyorgy Szing <Gyorgy.Szing@arm.com>2019-05-02 11:33:56 +0200
commit74dae3cf92b7c4a52ff629c353649f43fcfa5c86 (patch)
treee62622b300f87ba92b12c4341c93e64f5fcbc1c8 /cmake/FindPythonModules.cmake
parentcf32b90f2b80d9afa0f5d62e817c40d70bf5a6f5 (diff)
downloadtrusted-firmware-m-74dae3cf92b7c4a52ff629c353649f43fcfa5c86.tar.gz
Doc: Add support for Sphinx documentation build.
Technical documentation of TF-M is captured in GitHub flavored markdown files. This change add support for building HTML and PDF output of these files using the Sphinx tool. Change-Id: I8be11256f2c654c248b1974974a5de6190ca0fc3 Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
Diffstat (limited to 'cmake/FindPythonModules.cmake')
-rw-r--r--cmake/FindPythonModules.cmake64
1 files changed, 64 insertions, 0 deletions
diff --git a/cmake/FindPythonModules.cmake b/cmake/FindPythonModules.cmake
new file mode 100644
index 0000000000..bb8d4fb209
--- /dev/null
+++ b/cmake/FindPythonModules.cmake
@@ -0,0 +1,64 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#FindPythonModules
+#-----------
+#This module checks availability of Python modules.
+#
+#This module has the following parameters:
+# PYTHON_EXECUTABLE - Location of python interpreter.
+# COMPONENTS - List of python modules to look for.
+#
+#This module defines the following variables:
+# PY_XXX - Cached string variable with the location of the module.
+# PY_XXX_FOUND - Set if the module is available.
+#
+# Where XXX is the upper case name of the module.
+#
+#Examples
+# To look for m2r and report error if not found
+# find_module(PythonModules COMPONENTS m2r)
+# if (PY_M2R_FOUND)
+# do something
+# endif()
+#
+# To look for m2r and do not report error if not found
+# find_module(PythonModules OPTIONAL_COMPONENTS m2r)
+# if (PY_M2R_FOUND)
+# do something
+# endif()
+
+if(NOT DEFINED PYTHON_EXECUTABLE)
+ message(FATAL_ERROR "FindPythonModules: mandatory parameter PYTHON_EXECUTABLE is missing.")
+endif()
+
+include(Common/Utils)
+
+foreach(_mod ${PythonModules_FIND_COMPONENTS})
+ string(TOUPPER ${_mod} _mod_upper)
+ string(REPLACE "-" "_" _modname "${_mod}")
+ if (NOT PY_${_mod_upper})
+ #Execute python and try to include the module.
+ execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -c "import ${_modname}; print(${_modname}.__file__);"
+ RESULT_VARIABLE ${_mod}_status
+ OUTPUT_VARIABLE ${_mod}_path
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ #If suceeded
+ if(NOT ${_mod}_status)
+ #Avoid trouble with directory separator on windows.
+ win_fix_dir_sep(PATH ${_mod}_path)
+ set("PY_${_mod_upper}" "${${_mod}_path}" CACHE STRING
+ "Location of Python module ${_mod}")
+ endif()
+ endif()
+ find_package_handle_standard_args(PY_${_mod_upper}
+ FOUND_VAR PY_${_mod_upper}_FOUND
+ REQUIRED_VARS PY_${_mod_upper}
+ FAIL_MESSAGE "Can not find Python module ${_mod}")
+endforeach()