Merge "Merge release-4-5-patches into release-4-6" into release-4-6
[gromacs.git] / cmake / BuildManPages.cmake
blob5762a19be7249b11c999a9da8561b1dd504a4ebf
1 MACRO(TODAY RESULT)
2     IF(UNIX)
3         EXECUTE_PROCESS(COMMAND "date" "+%F" OUTPUT_VARIABLE ${RESULT} OUTPUT_STRIP_TRAILING_WHITESPACE)
4     ELSE()
5         set(${RESULT} "????-??-??")
6     ENDIF()
7 ENDMACRO(TODAY)
9 if(GMX_BUILD_MANPAGES)
10     set(MAN1_PATH ${CMAKE_BINARY_DIR}/man/man1)
11     file(MAKE_DIRECTORY ${MAN1_PATH})
13     #create gromacs.7
14     FILE(READ "${CMAKE_SOURCE_DIR}/admin/programs.txt" contents)
16     # Convert file contents into a CMake list. First escape ;
17     STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
18     STRING(REGEX REPLACE "\n" ";" contents "${contents}")
20     set(PROGMANPAGES "")
21     foreach(line ${contents})
22         if (${line} MATCHES "^HEAD\\|")
23             string(REGEX REPLACE "^HEAD\\|" "" DESC ${line})
24             set(PROGMANPAGES "${PROGMANPAGES}.Sh \"${DESC}\"\n.IX Subsection \"${DESC}\"\n.Vb\n.ta 16n\n")
25         elseif(${line} MATCHES "^END$")
26             set(PROGMANPAGES "${PROGMANPAGES}.Ve\n")
27         elseif(${line} MATCHES "\\|")
28             string(REGEX REPLACE "\\|" "\t" line ${line})
29             set(PROGMANPAGES "${PROGMANPAGES}\\&  ${line}\n")
30         else()
31             message(WARNING "Incorrectly formated line \"${line}\" in programs.txt")
32         endif()
33     endforeach()
34     TODAY(TODAYS_DATE)
35     configure_file(${CMAKE_SOURCE_DIR}/man/man7/gromacs.7.cmakein ${CMAKE_BINARY_DIR}/man/man7/gromacs.7)
36     install(FILES ${CMAKE_BINARY_DIR}/man/man7/gromacs.7 DESTINATION
37         ${MAN_INSTALL_DIR}/man7)
38 #man-pages are only avalaible if they are either build or this is a source archive
39 elseif(NOT EXISTS "${CMAKE_SOURCE_DIR}/admin/.isreposource")
40     install(FILES ${CMAKE_SOURCE_DIR}/man/man7/gromacs.7 DESTINATION
41         ${MAN_INSTALL_DIR}/man7)
42 endif()
44 function (gmx_add_man_page EXENAME)
45     if(GMX_BUILD_MANPAGES)
46         file(STRINGS ${CMAKE_SOURCE_DIR}/admin/programs.txt DESC 
47             REGEX "^${EXENAME}\\|" LIMIT_COUNT 1)
48         #Regex breaks with a "|" in description. Cmake doesn't support 
49         #non-greedy regex.
50         string(REGEX REPLACE "^.*\\|" "" DESC "${DESC}")
51         if(DESC STREQUAL "")
52             message(WARNING "Missing description for ${EXENAME}")
53         endif()
54         add_custom_command(TARGET ${EXENAME} POST_BUILD 
55             #The redirect is a hack to avoid showing copyright. 
56             #Ideally -quiet would also cause programs to not print copyright.
57             COMMAND ${CMAKE_COMMAND} -DINFILE=${EXENAME}${GMX_BINARY_SUFFIX}.nroff 
58                 -DOUTFILE=${MAN1_PATH}/${EXENAME}.1 -DDESC=" - ${DESC}"
59                 -DEXENAME=${EXENAME}${GMX_BINARY_SUFFIX}
60                 -P ${CMAKE_SOURCE_DIR}/cmake/CreateManPage.cmake)
61         install(FILES ${MAN1_PATH}/${EXENAME}.1 DESTINATION 
62             ${MAN_INSTALL_DIR}/man1 OPTIONAL)
63     elseif(NOT EXISTS "${CMAKE_SOURCE_DIR}/admin/.isreposource")
64         install(FILES ${CMAKE_SOURCE_DIR}/man/man1/${EXENAME}.1 DESTINATION 
65             ${MAN_INSTALL_DIR}/man1)
66     endif()
67 endfunction ()