diff options
author | Brad King <brad.king@kitware.com> | 2021-01-15 19:01:53 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-01-18 17:35:41 (GMT) |
commit | 7d498d6b436638f5d85a0e97d43d51603d79205c (patch) | |
tree | 5e6a7174c41689811bb2b0c41d85207daee48a57 /Utilities/Sphinx/cmake.py | |
parent | cc1f53351c52d03aecc47f8074ab1290cf7fb1a5 (diff) | |
download | CMake-7d498d6b436638f5d85a0e97d43d51603d79205c.zip CMake-7d498d6b436638f5d85a0e97d43d51603d79205c.tar.gz CMake-7d498d6b436638f5d85a0e97d43d51603d79205c.tar.bz2 |
Utilities/Sphinx: Add role and directive for 'genex' in CMake domain
This enables cross-reference syntax for CMake generator expressions:
:genex:`SOME_GENEX`
:genex:`$<SOME_GENEX>`
:genex:`$<SOME_GENEX:...>`
and definition of CMake generator expressions via a directive:
.. genex:: SOME_GENEX
.. genex:: $<SOME_GENEX>
.. genex:: $<SOME_GENEX:...>
It also adds generator expressions defined by the directive and by
`Help/genex/SOME_GENEX.rst` documents to the index.
Diffstat (limited to 'Utilities/Sphinx/cmake.py')
-rw-r--r-- | Utilities/Sphinx/cmake.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/Utilities/Sphinx/cmake.py b/Utilities/Sphinx/cmake.py index e175d0d..ece4bf5 100644 --- a/Utilities/Sphinx/cmake.py +++ b/Utilities/Sphinx/cmake.py @@ -191,6 +191,7 @@ _cmake_index_objs = { 'cpack_gen': _cmake_index_entry('cpack generator'), 'envvar': _cmake_index_entry('envvar'), 'generator': _cmake_index_entry('generator'), + 'genex': _cmake_index_entry('genex'), 'guide': _cmake_index_entry('guide'), 'manual': _cmake_index_entry('manual'), 'module': _cmake_index_entry('module'), @@ -224,7 +225,7 @@ class CMakeTransform(Transform): self.titles = {} def parse_title(self, docname): - """Parse a document title as the first line starting in [A-Za-z0-9<] + """Parse a document title as the first line starting in [A-Za-z0-9<$] or fall back to the document basename if no such line exists. The cmake --help-*-list commands also depend on this convention. Return the title or False if the document file does not exist. @@ -239,7 +240,7 @@ class CMakeTransform(Transform): title = False else: for line in f: - if len(line) > 0 and (line[0].isalnum() or line[0] == '<'): + if len(line) > 0 and (line[0].isalnum() or line[0] == '<' or line[0] == '$'): title = line.rstrip() break f.close() @@ -260,6 +261,10 @@ class CMakeTransform(Transform): if objtype == 'command': targetname = title.lower() else: + if objtype == 'genex': + m = CMakeXRefRole._re_genex.match(title) + if m: + title = m.group(1) targetname = title targetid = '%s:%s' % (objtype, targetname) targetnode = nodes.target('', '', ids=[targetid]) @@ -277,6 +282,10 @@ class CMakeObject(ObjectDescription): def handle_signature(self, sig, signode): # called from sphinx.directives.ObjectDescription.run() signode += addnodes.desc_name(sig, sig) + if self.objtype == 'genex': + m = CMakeXRefRole._re_genex.match(sig) + if m: + sig = m.group(1) return sig def add_target_and_index(self, name, sig, signode): @@ -302,6 +311,7 @@ class CMakeXRefRole(XRefRole): # See sphinx.util.nodes.explicit_title_re; \x00 escapes '<'. _re = re.compile(r'^(.+?)(\s*)(?<!\x00)<(.*?)>$', re.DOTALL) _re_sub = re.compile(r'^([^()\s]+)\s*\(([^()]*)\)$', re.DOTALL) + _re_genex = re.compile(r'^\$<([^<>:]+)(:[^<>]+)?>$', re.DOTALL) def __call__(self, typ, rawtext, text, *args, **keys): # Translate CMake command cross-references of the form: @@ -312,6 +322,10 @@ class CMakeXRefRole(XRefRole): m = CMakeXRefRole._re_sub.match(text) if m: text = '%s <%s>' % (text, m.group(1)) + elif typ == 'cmake:genex': + m = CMakeXRefRole._re_genex.match(text) + if m: + text = '%s <%s>' % (text, m.group(1)) # CMake cross-reference targets frequently contain '<' so escape # any explicit `<target>` with '<' not preceded by whitespace. while True: @@ -374,6 +388,7 @@ class CMakeDomain(Domain): 'cpack_gen': ObjType('cpack_gen', 'cpack_gen'), 'envvar': ObjType('envvar', 'envvar'), 'generator': ObjType('generator', 'generator'), + 'genex': ObjType('genex', 'genex'), 'guide': ObjType('guide', 'guide'), 'variable': ObjType('variable', 'variable'), 'module': ObjType('module', 'module'), @@ -390,6 +405,7 @@ class CMakeDomain(Domain): directives = { 'command': CMakeObject, 'envvar': CMakeObject, + 'genex': CMakeObject, 'variable': CMakeObject, # Other object types cannot be created except by the CMakeTransform # 'generator': CMakeObject, @@ -409,6 +425,7 @@ class CMakeDomain(Domain): 'cpack_gen': CMakeXRefRole(), 'envvar': CMakeXRefRole(), 'generator': CMakeXRefRole(), + 'genex': CMakeXRefRole(), 'guide': CMakeXRefRole(), 'variable': CMakeXRefRole(), 'module': CMakeXRefRole(), |