Doxygen排除模式正则表达式

Doxygen排除模式正则表达式,doxygen,Doxygen,我正试图从doxygen生成的文档中排除某些文件。我使用的是1.8.14版 我的文件采用以下命名约定: /Path2/OtherFile.cs /Path/DAL.Entity/Source.cs /Path/DAL.Entity/SourceBase.generated.cs 我想排除所有不以Base.generated.cs结尾并且位于/Path/内部的文件 由于doxygen似乎声称将regex用于exclude_patterns变量,因此我最终得出了以下结论: .*\\Path\\DA

我正试图从doxygen生成的文档中排除某些文件。我使用的是1.8.14版

我的文件采用以下命名约定:

/Path2/OtherFile.cs
/Path/DAL.Entity/Source.cs
/Path/DAL.Entity/SourceBase.generated.cs
我想排除所有不以Base.generated.cs结尾并且位于/Path/内部的文件

由于doxygen似乎声称将regex用于exclude_patterns变量,因此我最终得出了以下结论:

.*\\Path\\DAL\..{4,15}\\((?<!Base\.generated).)*
*\\Path\\DAL\..{4,15}\\(?
不用说,它不起作用。其他多种变体也不起作用。到目前为止,一个简单的通配符*是我得到的唯一真正起作用的正则表达式字符

doxygen在很多方面都使用QRegExp,所以我假设该库也用于该变量,但即使是该库不起作用的模式的几个变体;尽管该库显然充满了bug,但我希望有些东西能起作用

doxygen是否实际为此变量使用正则表达式库? 如果是,它是哪个图书馆?
在这两种情况下,有没有一种方法可以实现我的目标?

我的结论是;没有……Doxygen-Doxyfile不支持真正的正则表达式。即使他们声称它支持。它只是标准的通配符

我们最终找到了一个非常棘手的解决方案来解决这个问题

我们所做的是在CMakeLists.txt中添加了一个宏,该宏创建了一个字符串,其中包含了我们想要包含在输入中的所有内容。手动排除了我们不想要的部分

可悲的是,CMakes正则表达式也有缺陷。因此,我们无法使用高级正则表达式,例如类似于
LIST(FILTER children EXCLUDE regex)^((?!autogen/public)。*)*$”
…的列表中的负前瞻(FILTER EXLUDE)之类的高级正则表达式,所以即使是这种解决方案也不是我们真正想要的

我们的CMakeLists.txt最终看起来像这样

cmake_minimum_required(VERSION 3.9)

project(documentation_html LANGUAGES CXX)

find_package(Doxygen REQUIRED dot)

# Custom macros
## Macro for getting all relevant directories when creating HTML documentain.
## This was created cause the regex matching in Doxygen and CMake are lacking support for more
## advanced syntax.
MACRO(SUBDIRS result current_dir include_regex)
  FILE(GLOB_RECURSE children ${current_dir} ${current_dir}/*)
  LIST(FILTER children INCLUDE REGEX "${include_regex}")
  SET(dir_list "")
  FOREACH(child ${children})
    get_filename_component(path ${child} DIRECTORY)
    IF(${path} MATCHES ".*autogen/public.*$" OR NOT ${path} MATCHES ".*build.*$") # If we have the /source/build/autogen/public folder available we create the doxygen for those interfaces also.
        LIST(APPEND dir_list ${path})
    ENDIF()
  ENDFOREACH()
  LIST(REMOVE_DUPLICATES dir_list)
  string(REPLACE ";" " " dirs "${dir_list}")
  SET(${result} ${dirs})
ENDMACRO()

SUBDIRS(DOCSDIRS "${CMAKE_SOURCE_DIR}/docs" ".*.plantuml$|.*.puml$|.*.md$|.*.txt$|.*.sty$|.*.tex$|")
SUBDIRS(SOURCEDIRS "${CMAKE_SOURCE_DIR}/source" ".*.cpp$|.*.hpp$|.*.h$|.*.md$")

# Common config
set(DOXYGEN_CONFIG_PATH ${CMAKE_SOURCE_DIR}/docs/doxy_config)
set(DOXYGEN_IN ${DOXYGEN_CONFIG_PATH}/Doxyfile.in)
set(DOXYGEN_IMAGE_PATH ${CMAKE_SOURCE_DIR}/docs)
set(DOXYGEN_PLANTUML_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/docs)
set(DOXYGEN_OUTPUT_DIRECTORY docs)

# HTML config
set(DOXYGEN_INPUT "${DOCSDIRS} ${SOURCEDIRS}")
set(DOXYGEN_EXCLUDE_PATTERNS "*/tests/* */.*/*")
set(DOXYGEN_FILE_PATTERNS "*.cpp *.hpp *.h *.md")
set(DOXYGEN_RECURSIVE NO)
set(DOXYGEN_GENERATE_LATEX NO)
set(DOXYGEN_GENERATE_HTML YES)
set(DOXYGEN_HTML_DYNAMIC_MENUS NO)
configure_file(${DOXYGEN_IN} ${CMAKE_BINARY_DIR}/DoxyHTML @ONLY)

add_custom_target(docs
    COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/DoxyHTML -d Markdown
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
    COMMENT "Generating documentation"
    VERBATIM)
在Doxyfile中,我们为这些字段添加了环境变量

OUTPUT_DIRECTORY       = @DOXYGEN_OUTPUT_DIRECTORY@
INPUT                  = @DOXYGEN_INPUT@
FILE_PATTERNS          = @DOXYGEN_FILE_PATTERNS@
RECURSIVE              = @DOXYGEN_RECURSIVE@
EXCLUDE_PATTERNS       = @DOXYGEN_EXCLUDE_PATTERNS@
IMAGE_PATH             = @DOXYGEN_IMAGE_PATH@
GENERATE_HTML          = @DOXYGEN_GENERATE_HTML@
HTML_DYNAMIC_MENUS     = @DOXYGEN_HTML_DYNAMIC_MENUS@
GENERATE_LATEX         = @DOXYGEN_GENERATE_LATEX@
PLANTUML_INCLUDE_PATH  = @DOXYGEN_PLANTUML_INCLUDE_PATH@
在此之后,我们可以运行
cd./build&&cmake../&&make docs
来创建html文档,并让它在源文件夹中包含自动生成的接口,而不包括build文件夹中的所有其他目录

快速描述CMakeLists.txt中实际发生的情况

# Macro that gets all directories from current_dir recursively and returns the result to result as a space separated string 
MACRO(SUBDIRS result current_dir include_regex)

  # Gets all files recursively from current_dir
  FILE(GLOB_RECURSE children ${current_dir} ${current_dir}/*)
  
  # Filter files so we only keep the files that match the include_regex (can't be to advanced regex)
  LIST(FILTER children INCLUDE REGEX "${include_regex}")
  SET(dir_list "")
  
  # Let us act on all files... :)
  FOREACH(child ${children})

    # We're only interested in the path. So we get the path part from the file
    get_filename_component(path ${child} DIRECTORY)
    
    # Since CMakes regex also is crippled we can't do nice things such as LIST(FILTER children EXCLUDE REGEX "^((?!autogen/public).)*$") which would have been preferred (CMake regex does not understand negative lookahead/lookbehind)... So we ended up with this ugly thing instead... Adding all build/autogen/public paths and not adding any other paths inside build. I guess it would be possible to write this expression in regex without negative lookahead. But I'm both not really fluent in regex (who are... right?) and a bit lazy in this case. We just needed to get this one pointer task done... :P
    IF(${path} MATCHES ".*autogen/public.*$" OR NOT ${path} MATCHES ".*build.*$") 
        LIST(APPEND dir_list ${path})
    ENDIF()
  ENDFOREACH()

  # Remove all duplicates... Since we GLOBed all files there are a lot of them. So this is important or Doxygen INPUT will overflow... I know... I tested... 
  LIST(REMOVE_DUPLICATES dir_list)

  # Convert the dir_list to a space seperated string
  string(REPLACE ";" " " dirs "${dir_list}")

  # Return the result! Coffee and cinnamon buns for everyone!
  SET(${result} ${dirs})
ENDMACRO()

# Get all the pathes that we want to include in our documentation ... this is also where the build folders for the different applications are going to be... with our autogenerated interfaces which we want to keep.
SUBDIRS(SOURCEDIRS "${CMAKE_SOURCE_DIR}/source" ".*.cpp$|.*.hpp$|.*.h$|.*.md$")

# Add the dirs we want to the Doxygen INPUT
set(DOXYGEN_INPUT "${SOURCEDIRS}")

# Normal exlude patterns for stuff we don't want to add. This thing does not support regex... even though it should.
set(DOXYGEN_EXCLUDE_PATTERNS "*/tests/* */.*/*")

# Normal use of the file patterns that we want to keep in the documentation
set(DOXYGEN_FILE_PATTERNS "*.cpp *.hpp *.h *.md")

# IMPORTANT! Since we are creating all the INPUT paths our self we don't want Doxygen to do any recursion for us
set(DOXYGEN_RECURSIVE NO)

# Write the config
configure_file(${DOXYGEN_IN} ${CMAKE_BINARY_DIR}/DoxyHTML @ONLY)

# Create the target that will use that config to create the html documentation
add_custom_target(docs
    COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/DoxyHTML -d Markdown
    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
    COMMENT "Generating documentation"
    VERBATIM)

我知道这不是任何一个偶然发现这个问题的人想要的答案…不幸的是,这似乎是唯一合理的解决方案。。。
…大家都有我最深切的慰问…

我也遇到了类似的问题…似乎也没有任何关于如何使用regex的相关文档…有点讽刺,因为它是创建文档的工具。您写道:“尽管他们声称它可以。”手册中的内容在哪里?他们常见问题解答中的第9项:表明他们使用了QRegExp。@JeremeGuenther说了什么……我还记得在文档中读到了类似“可以使用正则表达式排除”的内容。但我现在找不到它。也许我只是做梦吧_(ツ)_/¯