Compare commits

...

2 Commits

Author SHA1 Message Date
a0a786f590 FindSphinx 2019-02-20 13:41:26 +03:00
8cdb005db6 FindPythonModule 2019-02-20 13:41:11 +03:00
2 changed files with 83 additions and 0 deletions

45
FindPythonModule.cmake Normal file
View File

@@ -0,0 +1,45 @@
# Find a Python module
# Found at http://www.cmake.org/pipermail/cmake/2011-January/041666.html
# To use do: find_python_module(NumPy REQUIRED)
# Reports also version of package, but you can't currently enforce a specific version to be
# searched for...
include(FindPackageHandleStandardArgs)
function(find_python_module module)
# Fail if Python interpreter not known
if(NOT PYTHON_EXECUTABLE)
message(FATAL_ERROR "Use find_package(PythonInterp) first!")
endif()
string(TOLOWER ${module} _module_lower)
if(NOT ${_module_lower})
if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
set(${module}_FIND_REQUIRED TRUE)
endif()
# Find module location
execute_process(
COMMAND
${PYTHON_EXECUTABLE} "-c" "import re, ${_module_lower}; print(re.compile('/__init__.py.*').sub('',${_module_lower}.__file__))"
RESULT_VARIABLE _${module}_status
OUTPUT_VARIABLE _${module}_location
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT _${module}_status)
set(${module} ${_${module}_location} CACHE STRING "Location of Python module ${module}")
endif()
# Find module version
execute_process(
COMMAND
${PYTHON_EXECUTABLE} "-c" "import re, ${_module_lower}; print(re.compile('/__init__.py.*').sub('',${_module_lower}.__version__))"
OUTPUT_VARIABLE _${module}_ver
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
find_package_handle_standard_args(${module}
FOUND_VAR ${module}_FOUND
REQUIRED_VARS ${module}
VERSION_VAR _${module}_ver
)
endfunction()

38
FindSphinx.cmake Normal file
View File

@@ -0,0 +1,38 @@
# - This module looks for Sphinx
# Find the Sphinx documentation generator
#
# This modules defines
# SPHINX_EXECUTABLE
# SPHINX_FOUND
#=============================================================================
# Copyright 2002-2009 Kitware, Inc.
# Copyright 2009-2011 Peter Colberg
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file COPYING-CMAKE-SCRIPTS for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
find_program(SPHINX_EXECUTABLE NAMES sphinx-build
HINTS
$ENV{SPHINX_DIR}
HINTS ${SPHINX_ROOT}/bin
PATH_SUFFIXES bin
DOC "Sphinx documentation generator"
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Sphinx DEFAULT_MSG
SPHINX_EXECUTABLE
)
mark_as_advanced(
SPHINX_EXECUTABLE
)