summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Antonuk <aega@med.umich.edu>2012-05-22 14:13:00 -0400
committerAlan Antonuk <aega@med.umich.edu>2012-05-24 15:47:11 -0400
commitff4e6a2bdf390e0bd6472b7b14baa4d941dff4a2 (patch)
treee11f33510ddc3089d45eaa3937b40ce318081707
parentbc3f8532e46fb9e5fde0b51ae7c936d4d9542410 (diff)
downloadrabbitmq-c-ff4e6a2bdf390e0bd6472b7b14baa4d941dff4a2.tar.gz
Adding CMake procedure to build/install tools manpages
-rw-r--r--CMakeLists.txt8
-rw-r--r--cmake/FindXmlTo.cmake103
-rw-r--r--tools/CMakeLists.txt39
3 files changed, 149 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3246624..168416c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -54,10 +54,16 @@ set(AMQP_CODEGEN_DIR ${RABBITMQ_CODEGEN_DIR} CACHE PATH "Path to rabbitmq-codege
mark_as_advanced(AMQP_CODEGEN_DIR)
find_package(POPT)
+find_package(XmlTo)
+
+if (POPT_FOUND AND XmlTo_FOUND)
+ set(DO_DOCS ON)
+endif()
option(BUILD_SHARED_LIBS "Build rabbitmq-c as a shared library" ON)
-option(BUILD_TOOLS "Build Tools (requires POPT Library)" ${POPT_FOUND})
option(BUILD_EXAMPLES "Build Examples" ON)
+option(BUILD_TOOLS "Build Tools (requires POPT Library)" ${POPT_FOUND})
+option(BUILD_TOOLS_DOCS "Build man pages for Tools (requires xmlto)" ${DO_DOCS})
if (WIN32 AND NOT BUILD_SHARED_LIBS)
message(FATAL_ERROR "The rabbitmq-c library cannot be built as a static library on Win32. Set BUILD_SHARED_LIBS=ON to get around this.")
diff --git a/cmake/FindXmlTo.cmake b/cmake/FindXmlTo.cmake
new file mode 100644
index 0000000..713e0e8
--- /dev/null
+++ b/cmake/FindXmlTo.cmake
@@ -0,0 +1,103 @@
+# - Convert XML docBook files to various formats
+# This will convert XML docBook files to various formats like:
+# man html txt dvi ps pdf
+# macro XMLTO(outfiles infiles... MODES modes...)
+
+set ( XmlTo_FOUND false )
+
+find_program ( XMLTO_EXECUTABLE
+ NAMES xmlto
+ DOC "path to the xmlto docbook xslt frontend"
+)
+
+if ( XMLTO_EXECUTABLE )
+ set ( XmlTo_FOUND true )
+endif ( XMLTO_EXECUTABLE )
+
+if ( NOT XmlTo_FIND_QUIETLY )
+ if ( XmlTo_FIND_REQUIRED )
+ FATAL_ERROR ( "xmlto not found" )
+ endif ( XmlTo_FIND_REQUIRED )
+endif ( NOT XmlTo_FIND_QUIETLY )
+
+macro ( _XMLTO_FILE outfiles mode)
+ #special settings
+ set ( XMLTO_FILEEXT_man 1 )
+ set ( XMLTO_MODE_html xhtml-nochunks )
+
+ if ( NOT XMLTO_MODE_${mode})
+ set ( XMLTO_MODE_${mode} ${mode} )
+ endif ( NOT XMLTO_MODE_${mode} )
+ if ( NOT XMLTO_FILEEXT_${mode} )
+ set ( XMLTO_FILEEXT_${mode} ${mode} )
+ endif ( NOT XMLTO_FILEEXT_${mode} )
+
+ foreach ( dbFile ${ARGN} )
+ #TODO: set XMLTO_FILEEXT_man to value from <manvolnum>
+ if ( "${mode}" STREQUAL "man" )
+ file ( READ "${dbFile}" _DB_FILE_CONTENTS )
+ string ( REGEX MATCH "<manvolnum>[^<]*" XMLTO_FILEEXT_${mode} "${_DB_FILE_CONTENTS}" )
+ string ( REGEX REPLACE "^<manvolnum>" "" XMLTO_FILEEXT_${mode} "${XMLTO_FILEEXT_${mode}}" )
+ string ( REGEX REPLACE "[[:space:]]" "" XMLTO_FILEEXT_${mode} "${XMLTO_FILEEXT_${mode}}" )
+ endif ( "${mode}" STREQUAL "man" )
+
+ get_filename_component ( dbFilePath ${CMAKE_CURRENT_BINARY_DIR}/${dbFile} PATH )
+ get_filename_component ( dbFileWE ${dbFile} NAME_WE )
+ get_filename_component ( dbFileAbsWE ${dbFilePath}/${dbFileWE} ABSOLUTE )
+
+ add_custom_command (
+ OUTPUT ${dbFileAbsWE}.${XMLTO_FILEEXT_${mode}}
+ COMMAND ${XMLTO_EXECUTABLE} ${XMLTO_COMMAND_ARGS} -o ${dbFilePath}
+ ${XMLTO_MODE_${mode}} "${CMAKE_CURRENT_SOURCE_DIR}/${dbFile}"
+ MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${dbFile}
+ DEPENDS ${XMLTO_DEPENDS}
+ VERBATIM
+ )
+
+ set ( ${outfiles}
+ ${${outfiles}}
+ ${dbFileAbsWE}.${XMLTO_FILEEXT_${mode}}
+ )
+ endforeach ( dbFile )
+endmacro ( _XMLTO_FILE outfiles )
+
+macro ( XMLTO )
+ set ( XMLTO_MODES )
+ set ( XMLTO_FILES )
+ set ( XMLTO_HAS_MODES false )
+ set ( XMLTO_ADD_DEFAULT false )
+ foreach ( arg ${ARGN} )
+ if ( ${arg} STREQUAL "MODES" )
+ set ( XMLTO_HAS_MODES true )
+ elseif ( ${arg} STREQUAL "ALL" )
+ set ( XMLTO_ADD_DEFAULT true )
+ else ( ${arg} STREQUAL "MODES" )
+ if ( XMLTO_HAS_MODES )
+ set ( XMLTO_MODES ${XMLTO_MODES} ${arg} )
+ else ( XMLTO_HAS_MODES )
+ set ( XMLTO_FILES ${XMLTO_FILES} ${arg} )
+ endif ( XMLTO_HAS_MODES )
+ endif ( ${arg} STREQUAL "MODES" )
+ endforeach ( arg ${ARGN} )
+ if ( NOT XMLTO_MODES )
+ set ( XMLTO_MODES html )
+ endif ( NOT XMLTO_MODES )
+
+ foreach ( mode ${XMLTO_MODES} )
+ _xmlto_file ( XMLTO_FILES_${mode} ${mode} ${XMLTO_FILES} )
+ if ( XMLTO_ADD_DEFAULT )
+ add_custom_target ( ${mode} ALL
+ DEPENDS ${XMLTO_FILES_${mode}}
+ VERBATIM
+ )
+ else ( XMLTO_ADD_DEFAULT )
+ add_custom_target ( ${mode}
+ DEPENDS ${XMLTO_FILES_${mode}}
+ VERBATIM
+ )
+ endif ( XMLTO_ADD_DEFAULT )
+ endforeach ( mode )
+
+ set ( XMLTO_MODES )
+ set ( XMLTO_FILES )
+endmacro ( XMLTO )
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 52397ae..cf7f4e2 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -32,6 +32,45 @@ target_link_libraries(amqp-declare-queue rabbitmq ${POPT_LIBRARY})
add_executable(amqp-delete-queue delete_queue.c ${COMMON_SRCS})
target_link_libraries(amqp-delete-queue rabbitmq ${POPT_LIBRARY})
+if (BUILD_TOOLS_DOCS)
+ if (XmlTo_FOUND)
+ set(DOCS_SRCS
+ doc/amqp-consume.xml
+ doc/amqp-declare-queue.xml
+ doc/amqp-delete-queue.xml
+ doc/amqp-get.xml
+ doc/amqp-publish.xml
+ doc/librabbitmq-tools.xml
+ )
+
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doc)
+ set(XMLTO_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doc/man-date.ent)
+ add_custom_command(
+ OUTPUT ${XMLTO_DEPENDS}
+ COMMAND date +'%Y-%m-%d' > ${XMLTO_DEPENDS}
+ VERBATIM
+ )
+
+ set(XMLTO_COMMAND_ARGS --skip-validation --searchpath "${CMAKE_CURRENT_BINARY_DIR}/doc")
+
+ XMLTO(${DOCS_SRCS}
+ MODES man
+ ALL)
+
+ foreach(file ${XMLTO_FILES_man})
+ get_filename_component(fileExt ${file} EXT)
+ string( REGEX REPLACE "^[.]" "" fileExt ${fileExt} )
+ install(
+ FILES ${file}
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man${fileExt}
+ )
+ endforeach()
+
+ else(XmlTo_FOUND)
+ message(WARNING "xmlto not found, will not build tools documentation")
+ endif(XmlTo_FOUND)
+endif()
+
install(TARGETS amqp-publish amqp-get amqp-consume amqp-declare-queue amqp-delete-queue
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib