2023-06-27 08:49:05 +08:00
|
|
|
include(CMakeParseArguments)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
|
|
|
function(SDL_generate_manpages)
|
2023-09-05 00:56:00 +08:00
|
|
|
cmake_parse_arguments(ARG "" "RESULT_VARIABLE;NAME;BUILD_DOCDIR;HEADERS_DIR;SOURCE_DIR;SYMBOL;OPTION_FILE;WIKIHEADERS_PL_PATH;REVISION" "" ${ARGN})
|
|
|
|
|
|
|
|
set(wikiheaders_extra_args)
|
2023-06-27 08:49:05 +08:00
|
|
|
|
|
|
|
if(NOT ARG_NAME)
|
|
|
|
set(ARG_NAME "${PROJECT_NAME}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT ARG_SOURCE_DIR)
|
|
|
|
set(ARG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT ARG_OPTION_FILE)
|
|
|
|
set(ARG_OPTION_FILE "${PROJECT_SOURCE_DIR}/.wikiheaders-options")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT ARG_HEADERS_DIR)
|
2023-09-29 09:42:33 +08:00
|
|
|
message(FATAL_ERROR "Missing required HEADERS_DIR argument")
|
2023-06-27 08:49:05 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# FIXME: get rid of SYMBOL and let the perl script figure out the dependencies
|
|
|
|
if(NOT ARG_SYMBOL)
|
|
|
|
message(FATAL_ERROR "Missing required SYMBOL argument")
|
|
|
|
endif()
|
|
|
|
|
2023-09-05 00:56:00 +08:00
|
|
|
if(ARG_REVISION)
|
|
|
|
list(APPEND wikiheaders_extra_args "--rev=${ARG_REVISION}")
|
|
|
|
endif()
|
|
|
|
|
2023-06-27 08:49:05 +08:00
|
|
|
if(NOT ARG_BUILD_DOCDIR)
|
|
|
|
set(ARG_BUILD_DOCDIR "${CMAKE_CURRENT_BINARY_DIR}/docs")
|
|
|
|
endif()
|
|
|
|
set(BUILD_WIKIDIR "${ARG_BUILD_DOCDIR}/wiki")
|
|
|
|
set(BUILD_MANDIR "${ARG_BUILD_DOCDIR}/man")
|
|
|
|
|
|
|
|
find_package(Perl)
|
2023-06-27 19:49:29 +08:00
|
|
|
file(GLOB HEADER_FILES "${ARG_HEADERS_DIR}/*.h")
|
2023-06-27 08:49:05 +08:00
|
|
|
|
|
|
|
set(result FALSE)
|
|
|
|
|
2023-06-28 01:02:33 +08:00
|
|
|
if(PERL_FOUND AND EXISTS "${ARG_WIKIHEADERS_PL_PATH}")
|
2023-06-27 08:49:05 +08:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${BUILD_WIKIDIR}/${ARG_SYMBOL}.md"
|
2023-06-28 20:41:31 +08:00
|
|
|
COMMAND "${CMAKE_COMMAND}" -E make_directory "${BUILD_WIKIDIR}"
|
2023-09-05 00:56:00 +08:00
|
|
|
COMMAND "${PERL_EXECUTABLE}" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_SOURCE_DIR}" "${BUILD_WIKIDIR}" "--options=${ARG_OPTION_FILE}" --copy-to-wiki ${wikiheaders_extra_args}
|
2023-06-28 01:02:33 +08:00
|
|
|
DEPENDS ${HEADER_FILES} "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_OPTION_FILE}"
|
2023-06-27 08:49:05 +08:00
|
|
|
COMMENT "Generating ${ARG_NAME} wiki markdown files"
|
|
|
|
)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${BUILD_MANDIR}/man3/${ARG_SYMBOL}.3"
|
2023-09-05 00:56:00 +08:00
|
|
|
COMMAND "${PERL_EXECUTABLE}" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_SOURCE_DIR}" "${BUILD_WIKIDIR}" "--options=${ARG_OPTION_FILE}" "--manpath=${BUILD_MANDIR}" --copy-to-manpages ${wikiheaders_extra_args}
|
2023-06-28 01:02:33 +08:00
|
|
|
DEPENDS "${BUILD_WIKIDIR}/${ARG_SYMBOL}.md" "${ARG_WIKIHEADERS_PL_PATH}" "${ARG_OPTION_FILE}"
|
2023-06-27 08:49:05 +08:00
|
|
|
COMMENT "Generating ${ARG_NAME} man pages"
|
|
|
|
)
|
|
|
|
add_custom_target(${ARG_NAME}-docs ALL DEPENDS "${BUILD_MANDIR}/man3/${ARG_SYMBOL}.3")
|
|
|
|
|
|
|
|
install(DIRECTORY "${BUILD_MANDIR}/" DESTINATION "${CMAKE_INSTALL_MANDIR}")
|
|
|
|
set(result TRUE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(ARG_RESULT_VARIABLE)
|
|
|
|
set(${ARG_RESULT_VARIABLE} ${result} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endfunction()
|