45

I am trying to figure out if there is a way to create a custom tag using Doxygen. I did find the ALIAS configuration file option but that does not do exactly what I need. Basically in my code I want to be able to write something like

/// \req Requirement #322 - blah blah

And then have Doxygen create a list like it does for \bug and \todo commands for lines that have this custom tag. Is this possible with Doxygen?

1
  • This does not seem to work with XML (C#) documenting style. Aug 14, 2012 at 8:35

3 Answers 3

54

The generalization of \bug and \todo is \xrefitem.

The solution I suggest is:

  • in Doxyfile:

    ALIASES += "req=\xrefitem req \"Requirement\" \"Requirements\" "
    
  • in documented code:

    /// \req #42 - The system shall work in any situation
    
1
  • 1
    Excellent, I did not see that while looking at the manual. Thanks a bunch.
    – RishiD
    Feb 11, 2009 at 15:53
29

Thanks mouviciel! I have adopted your solution and extended it for my purposes.

The text below goes into my Doxyfile:

ALIASES += req{1}="\ref SRTX_\1 \"SRTX-\1\" "
ALIASES += satisfy{1}="\xrefitem satisfy \"Satisfies requirement\" \"Requirement Implementation\" \1"
ALIASES += verify{1}="\xrefitem verify \"Verifies requirement\" \"Requirement Verification\" \1"

Where SRTX is the name of my project and is used as a prefix to requirements.

Then I create a file called Requirements.dox that provides a link between the requirement id and a URL for the requirement in my requirements management tool (an issue tracker in my case).

/**
@page Requirements

@section Build1

@anchor SRTX_1113
<a href="https://foo.bar.com/mantis/view.php?id=1113">SRTX-1113</a>

@anchor SRTX_1114
<a href="https://foo.bar.com/mantis/view.php?id=1114">SRTX-1114</a>

*/

One could also put the text of the requirement in the anchor tag if you didn't need to link to an external source.

In my code I have:

/**
 * This is the basic executive that schedules processes.
 * @satisfy{@req{1114}}
 */
class Scheduler: public Process
{
    ...
}

And in my tests I put:

/**
 * Provide a number of tests for process scheduling.
 * @verify{@req{1114}}
 */
class Scheduler_ut : public CppUnit::TestFixture
{
    ...
}

This gives me related pages for Requirements, Requirements Implementation, and Requirements Verification. It also provides Satisfies requirement and Verifies requirements sections in the class description (or function -- wherever you put the tag).

2
  • Add the Requirements.dox specified above in the INPUT= variable to be able to see the links, in the "Requirement Implementation" and "Requirement Verification" pages.
    – parasrish
    Nov 8, 2017 at 10:27
  • is it also possible to add a reverse lookup, in order to see the list of req and which function implements/versify it ?
    – phschoen
    Sep 14, 2021 at 15:18
7

Combining the two answers above, you can have a single clean requirement tag that will build a cross-reference table, and, also provide a direct link to the requirement repo in your docs:

Doxygen CONFIG file:

ALIASES = "requirement{1}=@xrefitem requirement \"Requirements\" \"Requirements Traceability\" <a href=\"http://your.requirementtool.com/browse/\1\">\1</a>"

Source code:

@requirement{REQ-123} Brief textual summary of this requirement item

This will render in the documentation as:

Requirements:

  • REQ-123 Brief textual summary of this requirement item
3
  • Nice answer - off topic, what open source requirement traceability tool do you recommend to be used in this situation? Mar 11, 2019 at 7:18
  • A little off topic? ;) I've used a lot of commercial requirements tools. Requirements for JIRA (R4J) provides the best integration (to s/w teams using JIRA) and lightweight usability for small - medium s/ware projects, imho. I've not evaluated open-source alternatives seriously. ReqIF was an industry-standard requirements interchange format - take a look at the tools that support that. Most requirements tools suffer the same problem: they are an information island - with poor integration to your existing tools and processes - try to find something that works with your toolchains.
    – Jay
    Mar 12, 2019 at 21:41
  • Hi @Jay, in this way I get the relationship between the functions that satisfy a requirement and a requirement, obtaining a section in which there are listed all the functions and for each of them the requirements they satisfy. Is there a way to get the inverse matrix of the relationship? Obtaining another section in which all the requirements are listed indicating the functions that satisfy each requirement.
    – s_frix
    May 6, 2022 at 10:07

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.