Demonstrates Doxygen html generation and publishing on GitHub Pages. The Doxygen files for this project can be seen here.
How to use
- Point your browser to this repository (https://github.com/semcneil/doxygen-cmake-github)
- Press the "Use this template" button
- Give your repository a new name
- Write a short (one sentence) description of what your project will do
- Click the Create repository from template button
VS Code VM Instructions
- VS Code needs the following extension added:
- C/C++ from Microsoft
- CMake Tools also from Microsoft
- Connect to Host in New Window
- Open a terminal (
ctrl+
`)
- Initialize git if you haven't already using the same email you used on your GitHub account:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
- Navigate to the parent directory for your project
- Clone your repository using the URL from the GitHub Code button on your repository and on VS Code either clone repository on the Welcome screen or open the Command Palette (ctrl+shift+P), type
git clone
and select Git: Clone
- Select the parent directory for your project
- Open the cloned repository either as prompted or by adding the newly created folder to your workspace by the Welcome tab's Open folder link or File -> Add Folder to Workspace
- If you use the command line
git clone
the authentications for pushing to your online repository are not set up
- If you wait a bit it should ask you which kit you want to use (at the time of this writing I typically use GCC 9.3.0)
- Allow Intellisense if prompted
- Edit README.md to reflect your new project
- Edit the
project
line in the CMakeLists.txt file to have your project's name and version
- Edit the
add_executable
line in the CMakeLists.txt file to change the name of the executable file to something relevant
- Change the @brief, @details, @author, and @date in src/main.cpp
- To create the PDF on a standard Ubuntu install, the following need to be added:
sudo apt install graphviz texlive-latex-base texlive-latex-recommended texlive-latex-extra
- Doxygen also needs installing:
sudo apt install doxygen
- In the terminal, change to the
build
directory (should have been automatically generated)
- Run the following:
make
make docs
make pdf
- Add the newly named PDF to git staging (
git status
-> git add docs/yourprojectname.pdf
)
- Commit all the changes:
git commit -a -m "Initial commit"
- Push the changes to GitHub:
git push origin main
- Back at your repository on GitHub, refresh the page to show latest commit
- In the Settings tab, scroll down to GitHub Pages
- Select "Branch: main" as source and "/docs" as the folder and then press Save
- Scroll back down to GitHub Pages and click the link to the published site
- You now have a C++ repository with doxygen output hosted on GitHub Pages
- The link usually doesn't work for a while (minutes to hours). This can be worked around by adding
index.html
to the end of the URL. A second commit will also fix it once the commit propagates over to GitHub Pages.
- You can see the PDF file generated by Doxygen by adding the name of the PDF to the end of the URL. It will be of the form
projectname.pdf
and can be seen in the docs
folder.
- It can take a few minutes for a new
git push origin main
to propagate over to GitHub Pages
- Edit README.md to reflect your project usage and point to the Doxygen output for your project
- Stage the commit (
git add README.md
)
- Commit (
git commit -a -m "Describe your changes here"
)
- Push your changes to GitHub as before (
git push origin main
)
General Usage
During normal development, you will change main.cpp, maybe add more files in the src directory, make them, and run them. To update the documentation on the web do the following at a terminal prompt in your project's build
directory:
make
make docs
make pdf
Then in your project's root directory do the following:
- Check the git status:
git status
git commit -a -m "Describe your changes since last commit"
- The
-a
flag is used to commit all the updated documentation files
- VS Code also has git built into it, but the use of branches isn't as easy a workflow as the commandline offers for me (personal opinion).
References
- https://www.doxygen.nl/manual/docblocks.html
- https://stackoverflow.com/questions/44212101/cmake-how-to-have-add-custom-command-run-after-all-project-files-are-built
- Very useful overview: https://caiorss.github.io/C-Cpp-Notes/Doxygen-documentation.html
- https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/
- https://vicrucann.github.io/tutorials/quick-cmake-doxygen/
- https://medium.com/practical-coding/c-documentation-with-doxygen-cmake-sphinx-breathe-for-those-of-use-who-are-totally-lost-7d555386fe13
- https://stackoverflow.com/questions/18590445/cmake-custom-command-to-copy-and-rename