Skip to content

Commit 0cd9b66

Browse files
author
Hannes Steffenhagen
committed
Fix doxygen in cmake
This has been broken for 3 years, ever since doxygen.cfg was renamed to doxyfile. This lets us build documentation in from cmake with the 'doc' target. One difference to the previous version (i.e. the one that was broken before) is that this creates the documentation in the cmake binary directory now instead of the source directory. Reasoning for this is that cmake targets should not change files in the source directory ideally.
1 parent 0f57d77 commit 0cd9b66

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/CMakeLists.txt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,26 @@ find_package(FLEX REQUIRED)
55

66
find_package(Doxygen)
77
if(DOXYGEN_FOUND)
8-
add_custom_target(doc
9-
"${DOXYGEN_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/doxygen.cfg"
10-
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
11-
)
8+
set(ROOT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/..")
9+
set(ROOT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
10+
set(ORIGINAL_DOXYFILE "${CMAKE_CURRENT_SOURCE_DIR}/doxyfile")
11+
set(CONFIGURED_DOXYFILE "${ROOT_BINARY_DIR}/doxyfile")
12+
set(DOC_INPUT_DIRECTORY "${ROOT_SOURCE_DIR}/doc")
13+
set(DOC_OUTPUT_DIRECTORY "${ROOT_BINARY_DIR}/doc")
14+
15+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/doxyfile.override.in" "${CONFIGURED_DOXYFILE}")
16+
add_custom_target(doc
17+
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${DOC_OUTPUT_DIRECTORY}"
18+
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${DOC_INPUT_DIRECTORY}" "${DOC_OUTPUT_DIRECTORY}"
19+
COMMAND "${DOXYGEN_EXECUTABLE}" "${CONFIGURED_DOXYFILE}"
20+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
21+
22+
unset(DOC_OUTPUT_DIRECTORY)
23+
unset(DOC_INPUT_DIRECTORY)
24+
unset(CONFIGURED_DOXYFILE)
25+
unset(ORIGINAL_DOXYFILE)
26+
unset(ROOT_SOURCE_DIR)
27+
unset(ROOT_BINARY_DIR)
1228
endif(DOXYGEN_FOUND)
1329

1430
# Add a bison target named 'parser'.

src/doxyfile.override.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Overrides for cmake out of source builds specifically, we
2+
# want to avoid copying files into the main doc directory,
3+
# instead we should be generating the doxygen docs in our
4+
# cmake output directory
5+
6+
# Note: This file is intended to be used with cmake
7+
# configure_file; variables like @this@ are replaced by
8+
# cmake variables.
9+
10+
@INCLUDE = @ORIGINAL_DOXYFILE@
11+
12+
OUTPUT_DIRECTORY = @DOC_OUTPUT_DIRECTORY@

0 commit comments

Comments
 (0)