FindXMLTO.cmake 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # - Convert XML docBook files to various formats
  2. # This will convert XML docBook files to various formats like:
  3. # man html txt dvi ps pdf
  4. # macro XMLTO(outfiles infiles... MODES modes...)
  5. find_program ( XMLTO_EXECUTABLE
  6. NAMES xmlto
  7. DOC "path to the xmlto docbook xslt frontend"
  8. )
  9. include(FindPackageHandleStandardArgs)
  10. FIND_PACKAGE_HANDLE_STANDARD_ARGS(XMLTO
  11. REQUIRED_VARS XMLTO_EXECUTABLE)
  12. mark_as_advanced( XMLTO_EXECUTABLE )
  13. macro ( _XMLTO_FILE outfiles mode)
  14. #special settings
  15. set ( XMLTO_FILEEXT_man 1 )
  16. set ( XMLTO_MODE_html xhtml-nochunks )
  17. if ( NOT XMLTO_MODE_${mode})
  18. set ( XMLTO_MODE_${mode} ${mode} )
  19. endif ( NOT XMLTO_MODE_${mode} )
  20. if ( NOT XMLTO_FILEEXT_${mode} )
  21. set ( XMLTO_FILEEXT_${mode} ${mode} )
  22. endif ( NOT XMLTO_FILEEXT_${mode} )
  23. foreach ( dbFile ${ARGN} )
  24. #TODO: set XMLTO_FILEEXT_man to value from <manvolnum>
  25. if ( "${mode}" STREQUAL "man" )
  26. file ( READ "${dbFile}" _DB_FILE_CONTENTS )
  27. string ( REGEX MATCH "<manvolnum>[^<]*" XMLTO_FILEEXT_${mode} "${_DB_FILE_CONTENTS}" )
  28. string ( REGEX REPLACE "^<manvolnum>" "" XMLTO_FILEEXT_${mode} "${XMLTO_FILEEXT_${mode}}" )
  29. string ( REGEX REPLACE "[[:space:]]" "" XMLTO_FILEEXT_${mode} "${XMLTO_FILEEXT_${mode}}" )
  30. endif ( "${mode}" STREQUAL "man" )
  31. get_filename_component ( dbFilePath ${CMAKE_CURRENT_BINARY_DIR}/${dbFile} PATH )
  32. get_filename_component ( dbFileWE ${dbFile} NAME_WE )
  33. get_filename_component ( dbFileAbsWE ${dbFilePath}/${dbFileWE} ABSOLUTE )
  34. add_custom_command (
  35. OUTPUT ${dbFileAbsWE}.${XMLTO_FILEEXT_${mode}}
  36. COMMAND ${XMLTO_EXECUTABLE} ${XMLTO_COMMAND_ARGS} -o ${dbFilePath}
  37. ${XMLTO_MODE_${mode}} "${CMAKE_CURRENT_SOURCE_DIR}/${dbFile}"
  38. MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${dbFile}
  39. DEPENDS ${XMLTO_DEPENDS}
  40. VERBATIM
  41. )
  42. set ( ${outfiles}
  43. ${${outfiles}}
  44. ${dbFileAbsWE}.${XMLTO_FILEEXT_${mode}}
  45. )
  46. endforeach ( dbFile )
  47. endmacro ( _XMLTO_FILE outfiles )
  48. macro ( XMLTO )
  49. set ( XMLTO_MODES )
  50. set ( XMLTO_FILES )
  51. set ( XMLTO_HAS_MODES false )
  52. set ( XMLTO_ADD_DEFAULT false )
  53. foreach ( arg ${ARGN} )
  54. if ( ${arg} STREQUAL "MODES" )
  55. set ( XMLTO_HAS_MODES true )
  56. elseif ( ${arg} STREQUAL "ALL" )
  57. set ( XMLTO_ADD_DEFAULT true )
  58. else ( ${arg} STREQUAL "MODES" )
  59. if ( XMLTO_HAS_MODES )
  60. set ( XMLTO_MODES ${XMLTO_MODES} ${arg} )
  61. else ( XMLTO_HAS_MODES )
  62. set ( XMLTO_FILES ${XMLTO_FILES} ${arg} )
  63. endif ( XMLTO_HAS_MODES )
  64. endif ( ${arg} STREQUAL "MODES" )
  65. endforeach ( arg ${ARGN} )
  66. if ( NOT XMLTO_MODES )
  67. set ( XMLTO_MODES html )
  68. endif ( NOT XMLTO_MODES )
  69. foreach ( mode ${XMLTO_MODES} )
  70. _xmlto_file ( XMLTO_FILES_${mode} ${mode} ${XMLTO_FILES} )
  71. if ( XMLTO_ADD_DEFAULT )
  72. add_custom_target ( ${mode} ALL
  73. DEPENDS ${XMLTO_FILES_${mode}}
  74. VERBATIM
  75. )
  76. else ( XMLTO_ADD_DEFAULT )
  77. add_custom_target ( ${mode}
  78. DEPENDS ${XMLTO_FILES_${mode}}
  79. VERBATIM
  80. )
  81. endif ( XMLTO_ADD_DEFAULT )
  82. endforeach ( mode )
  83. set ( XMLTO_MODES )
  84. set ( XMLTO_FILES )
  85. endmacro ( XMLTO )