cmake: allow man page installation by SDL satellite libraries

This is done by installing the wikiheaders.pl script, and add a wrapping cmake function.
main
Anonymous Maarten 2023-06-27 02:49:05 +02:00
parent 9ab2025127
commit 937f5d0059
3 changed files with 74 additions and 22 deletions

View File

@ -59,6 +59,7 @@ find_package(PkgConfig)
list(APPEND CMAKE_MODULE_PATH "${SDL3_SOURCE_DIR}/cmake")
include(${SDL3_SOURCE_DIR}/cmake/macros.cmake)
include(${SDL3_SOURCE_DIR}/cmake/sdlmanpages.cmake)
include(${SDL3_SOURCE_DIR}/cmake/sdlchecks.cmake)
include(${SDL3_SOURCE_DIR}/cmake/sdlfind.cmake)
include(${SDL3_SOURCE_DIR}/cmake/sdlplatform.cmake)
@ -3536,6 +3537,7 @@ else()
endif()
configure_file("cmake/sdlfind.cmake" "sdlfind.cmake" COPYONLY)
configure_file("cmake/sdlmanpages.cmake" "sdlmanpages.cmake" COPYONLY)
include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/SDL3Config.cmake.in SDL3Config.cmake
@ -3654,6 +3656,8 @@ if(NOT SDL_DISABLE_INSTALL)
${CMAKE_CURRENT_BINARY_DIR}/SDL3Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/SDL3ConfigVersion.cmake
${SDL3_SOURCE_DIR}/cmake/sdlfind.cmake
${SDL3_SOURCE_DIR}/build-scripts/wikiheaders.pl
${SDL3_SOURCE_DIR}/cmake/sdlmanpages.cmake
DESTINATION "${SDL_SDL_INSTALL_REAL_CMAKEDIR}"
)
@ -3686,29 +3690,11 @@ if(NOT SDL_DISABLE_INSTALL)
include(CPack)
endif()
set(WIKIHEADERS_PL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build-scripts/wikiheaders.pl")
if(NOT SDL_DISABLE_INSTALL_MAN)
find_package(Perl)
if(PERL_FOUND)
file(GLOB SDL3_MAN_INCLUDE_FILES "${SDL3_SOURCE_DIR}/include/SDL3/*.h")
set(SDL3_BINARY_DOCDIR "${SDL3_BINARY_DIR}/docs")
set(SDL3_BINARY_DOC_WIKIDIR "${SDL3_BINARY_DOCDIR}/wiki")
set(SDL3_BINARY_DOC_MANDIR "${SDL3_BINARY_DOCDIR}/man")
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${SDL3_BINARY_DOC_WIKIDIR}")
add_custom_command(
OUTPUT "${SDL3_BINARY_DOC_WIKIDIR}/SDL_Init.md"
COMMAND "${PERL_EXECUTABLE}" "${SDL3_SOURCE_DIR}/build-scripts/wikiheaders.pl" "${SDL3_SOURCE_DIR}" "${SDL3_BINARY_DOC_WIKIDIR}" "--options=${SDL3_SOURCE_DIR}/.wikiheaders-options" --copy-to-wiki
DEPENDS ${SDL3_MAN_INCLUDE_FILES} "${SDL3_SOURCE_DIR}/build-scripts/wikiheaders.pl" "${SDL3_SOURCE_DIR}/.wikiheaders-options"
COMMENT "Generating SDL3 wiki markdown files"
SDL_generate_manpages(
SYMBOL "SDL_Init"
)
add_custom_command(
OUTPUT "${SDL3_BINARY_DOC_MANDIR}/man3/SDL_Init.3"
COMMAND "${PERL_EXECUTABLE}" "${SDL3_SOURCE_DIR}/build-scripts/wikiheaders.pl" "${SDL3_SOURCE_DIR}" "${SDL3_BINARY_DOC_WIKIDIR}" "--options=${SDL3_SOURCE_DIR}/.wikiheaders-options" --"manpath=${SDL3_BINARY_DOC_MANDIR}" --copy-to-manpages
DEPENDS "${SDL3_BINARY_DOC_WIKIDIR}/SDL_Init.md" "${SDL3_SOURCE_DIR}/build-scripts/wikiheaders.pl" "${SDL3_SOURCE_DIR}/.wikiheaders-options"
COMMENT "Generating SDL3 man pages"
)
add_custom_target(SDL3_docs ALL DEPENDS "${SDL3_BINARY_DOC_MANDIR}/man3/SDL_Init.3")
install(DIRECTORY "${SDL3_BINARY_DOCDIR}/man/" DESTINATION "${CMAKE_INSTALL_MANDIR}")
endif()
endif()
endif()

View File

@ -93,3 +93,8 @@ set(SDL3_STATIC_LIBRARIES SDL3::SDL3-static)
set(SDL3_STATIC_PRIVATE_LIBS)
set(SDL3TEST_LIBRARY SDL3::SDL3_test)
if(SDL3_FOUND)
set(WIKIHEADERS_PL_PATH "${CMAKE_CURRENT_LIST_DIR}/wikiheaders.pl")
include("${CMAKE_CURRENT_LIST_DIR}/sdlmanpages.cmake")
endif()

61
cmake/sdlmanpages.cmake Normal file
View File

@ -0,0 +1,61 @@
include(CMakeParseArguments)
include(GNUInstallDirs)
function(SDL_generate_manpages)
cmake_parse_arguments(ARG "" "RESULT_VARIABLE;NAME;BUILD_DOCDIR;HEADERS_DIR;SOURCE_DIR;SYMBOL;OPTION_FILE" "" ${ARGN})
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)
set(ARG_HEADERS_DIR "${PROJECT_SOURCE_DIR}/include/SDL3")
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()
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)
file(GLOB HEADER_FILES "${HEADERS_DIR}/*.h")
set(result FALSE)
if(PERL_FOUND AND EXISTS "${WIKIHEADERS_PL_PATH}")
add_custom_command(
OUTPUT "${BUILD_WIKIDIR}/${ARG_SYMBOL}.md"
COMMAND "${PERL_EXECUTABLE}" "${WIKIHEADERS_PL_PATH}" "${ARG_SOURCE_DIR}" "${BUILD_WIKIDIR}" "--options=${ARG_OPTION_FILE}" --copy-to-wiki
DEPENDS ${HEADER_FILES} "${WIKIHEADERS_PL_PATH}" "${ARG_OPTION_FILE}"
COMMENT "Generating ${ARG_NAME} wiki markdown files"
)
add_custom_command(
OUTPUT "${BUILD_MANDIR}/man3/${ARG_SYMBOL}.3"
COMMAND "${PERL_EXECUTABLE}" "${WIKIHEADERS_PL_PATH}" "${ARG_SOURCE_DIR}" "${BUILD_WIKIDIR}" "--options=${ARG_OPTION_FILE}" "--manpath=${BUILD_MANDIR}" --copy-to-manpages
DEPENDS "${BUILD_WIKIDIR}/${ARG_SYMBOL}.md" "${WIKIHEADERS_PL_PATH}" "${ARG_OPTION_FILE}"
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()