This GitLab instance will be migrated to gitlab.mel.vin before 2020-06-01 and will lose the shared runners, setup your own runners if needed.

Commit 74d8320e authored by Stefan Schrijvers's avatar Stefan Schrijvers

Merge branch '104-missing-search-for-sphinxcontrib-plantuml-python-module' into 'master'

Resolve "missing search for sphinxcontrib.plantuml python module"

Closes #104

See merge request !86
parents dc6d9ecd ae1b0366
function(find_python_module module)
string(TOUPPER "${module}" module_u)
function(find_python_module module module_u)
if(${module_u}_FOUND)
return()
......@@ -14,12 +12,25 @@ if(NOT ${module_u}_PATH)
# A module's location is usually a directory, but for binary modules
# it's an .so file.
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import os, re, ${module}; print(os.path.dirname( \
"import os, re, ${module}; print(os.path.dirname(\
re.compile('/__init__.py.*').sub('',${module}.__file__)))"
RESULT_VARIABLE "${module_u}_RESULT"
OUTPUT_VARIABLE "${module_u}_OUTPUT"
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# strip module directories to get the base path
# abc.foo.bar.xyz -> ... (three dots)
string(REGEX REPLACE "[^\\.]+" "" module_strip "${module}")
string(LENGTH "${module_strip}" module_strip)
# strip ${module_strip} times the final directory from path
if(module_strip GREATER 0)
# CMake's loops are inclusive so start at 1
foreach(module_strip_i RANGE 1 ${module_strip})
string(REGEX REPLACE "/[^/]+$" ""
"${module_u}_OUTPUT" "${${module_u}_OUTPUT}")
endforeach(module_strip_i)
endif()
# if the exit code (RESULT) is non-zero python couldn't import module
if(NOT ${module_u}_RESULT)
set("${module_u}_PATH" "${${module_u}_OUTPUT}" CACHE STRING
......
......@@ -32,22 +32,24 @@ else()
find_package(PythonInterp REQUIRED)
include(find_python_module)
find_python_module(breathe)
find_python_module(sphinx)
# do not change the ENV, doesn't work with add_custom_target
# https://cmake.org/Bug/view.php?id=5145
if(ENV{PYTHONPATH})
set(PYTHONPATH
"${BREATHE_PATH}:${SPHINX_PATH}:$ENV{PYTHONPATH}")
set(PYTHONPATH "$ENV{PYTHONPATH}")
else()
# PYTHONPATH disables defaults, manually append them
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import sys; sys.stdout.write(':'.join(sys.path))"
OUTPUT_VARIABLE PYTHONPATH)
set(PYTHONPATH "${BREATHE_PATH}:${SPHINX_PATH}:${PYTHONPATH}")
"import sys; sys.stdout.write(':'.join(sys.path))"
OUTPUT_VARIABLE PYTHONPATH)
endif()
foreach(module breathe sphinx sphinxcontrib.plantuml)
string(TOUPPER "${module}" module_upper)
find_python_module("${module}" "${module_upper}")
set(PYTHONPATH "${${module_upper}_PATH}:${PYTHONPATH}")
endforeach(module)
if(${WERROR})
set(SPHINX_WERROR "-W")
else()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment