From a50233ab6e5c4a45dc2681b2ef5aa293526a3325 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Tue, 13 Jan 2026 15:45:38 +0800 Subject: [PATCH] chore: add preprocessor support for doxygen --- CMakeLists.txt | 4 ++++ doc/CMakeLists.txt | 24 +++++++++++++++++++++--- doc/Doxyfile.in | 4 ++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b4c1a7..a737d3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,10 @@ endif () if (YYCC_BUILD_BENCHMARK) find_package(benchmark REQUIRED) endif () +# Doxygen is required if we build doc +if (YYCC_BUILD_DOC) + find_package(Doxygen REQUIRED) +endif () # Iconv is required if we are not in Windows or user request it if (YYCC_ENFORCE_ICONV OR (NOT WIN32)) find_package(Iconv REQUIRED) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 12a10e2..cbbabca 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -1,13 +1,31 @@ -# Configure Doxygen config file +# Extract all public macros defined in YYCC +# However, you should note that these extratcted macros have generator expressions. +get_target_property(YYCC_COMPILE_DEFINITIONS YYCCommonplace COMPILE_DEFINITIONS) +if (YYCC_COMPILE_DEFINITIONS STREQUAL "YYCC_COMPILE_DEFINITIONS-NOTFOUND") + message(FATAL_ERROR "Cannot extract compile definitions from YYCCommonplace.") +endif () +# Convert list to string for expanding in future. +list(JOIN YYCC_COMPILE_DEFINITIONS " " YYCC_MACRO_GENERATOR_EXPRESSIONS) + +# We simply configure Doxygen config file first. configure_file( ${CMAKE_CURRENT_LIST_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY ) -# Add custom target +# Then we use "file GENERATE" syntax to generate per-config truely Doxyfile used by Doxygen. +# Because there is no "$<>" syntax in Doxyfile, so we can safely use it. +# Please note that the generation of "file GENERATE" syntax will be postponed until the build stage. +file(GENERATE + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$/Doxyfile" + INPUT "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile" + TARGET YYCCommonplace +) + +# Add custom target using per-config Doxyfile add_custom_target (YYCCDocumentation - doxygen ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile + Doxygen::doxygen "${CMAKE_CURRENT_BINARY_DIR}/$/Doxyfile" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating documentation" VERBATIM ) diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 2dd5581..ef925e1 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -2306,7 +2306,7 @@ PERLMOD_MAKEVAR_PREFIX = # C-preprocessor directives found in the sources and include files. # The default value is: YES. -ENABLE_PREPROCESSING = NO +ENABLE_PREPROCESSING = YES # If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names # in the source code. If set to NO, only conditional compilation will be @@ -2356,7 +2356,7 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = YYCC_DOXYGEN +PREDEFINED = @YYCC_MACRO_GENERATOR_EXPRESSIONS@ # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The