diff options
-rw-r--r-- | CMakeLists.txt | 98 | ||||
-rw-r--r-- | README.md | 19 | ||||
-rw-r--r-- | cmake/FindXmlTo.cmake | 103 | ||||
-rw-r--r-- | examples/utils.c | 2 | ||||
-rw-r--r-- | librabbitmq/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 15 | ||||
-rw-r--r-- | tests/test_tables.c | 2 | ||||
-rw-r--r-- | tools/CMakeLists.txt | 44 | ||||
-rw-r--r-- | tools/common.c | 5 |
9 files changed, 236 insertions, 56 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b4f95e2..194c25a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,20 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.6) project(rabbitmq-c "C") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) +set(VERSION "0.2") + +if (MSVC) + set(CMAKE_C_FLAGS "/W4 /nologo ${CMAKE_C_FLAGS}") +else () + set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wstrict-prototypes -Wcast-align -Wno-unused-function -fno-common -fvisibility=hidden ${CMAKE_C_FLAGS}") +endif () + +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) +endif() + #find python find_package(PythonInterp REQUIRED) @@ -23,58 +35,68 @@ endif (CHECK_PYTHON_JSON_FAILED) include(TestCInline) -option(FETCH_CODEGEN_FROM_GIT "Fetch codegen directly from the git repository" OFF) - -set(CODEGEN_GIT_TAG rabbitmq_v2_5_1 CACHE STRING "Git tag in rabbitmq-codegen to fetch with FETCH_CODEGEN_FROM_GIT") -if (FETCH_CODEGEN_FROM_GIT) - include(ExternalProject) - ExternalProject_Add( - amqp_codegen - GIT_REPOSITORY https://github.com/rabbitmq/rabbitmq-codegen.git - GIT_TAG ${CODEGEN_GIT_TAG} - CONFIGURE_COMMAND "" - UPDATE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "") - - ExternalProject_Get_Property(amqp_codegen SOURCE_DIR) - set(AMQP_CODEGEN_DIR ${SOURCE_DIR} CACHE PATH "Path to rabbitmq-codegen" FORCE) - SET(AMQP_CODEGEN_TARGET amqp_codegen) - message(STATUS "Using amqp_codegen.py in ${AMQP_CODEGEN_DIR}") -else (FETCH_CODEGEN_FROM_GIT) - find_path(RABBITMQ_CODEGEN_DIR - amqp_codegen.py - PATHS ${CMAKE_SOURCE_DIR}/rabbitmq-codegen - ${CMAKE_SOURCE_DIR}/../rabbitmq-codegen - ${CMAKE_SOURCE_DIR}/codegen +find_path(RABBITMQ_CODEGEN_DIR + amqp_codegen.py + PATHS ${CMAKE_SOURCE_DIR}/codegen + ${CMAKE_SOURCE_DIR}/rabbitmq-codegen + ${CMAKE_SOURCE_DIR}/../rabbitmq-codegen DOC "Path to directory containing amqp_codegen.py (rabbitmq-codegen)" NO_DEFAULT_PATH ) - if (RABBITMQ_CODEGEN_DIR STREQUAL "RABBITMQ_CODEGEN_DIR-NOTFOUND") - message(SEND_ERROR "Cannot find rabbitmq-codegen, set RABBITMQ_CODEGEN_DIR to a rabbitmq-codegen checkout, or set FETCH_CODEGEN_FROM_GIT to download it from git automatically") - else () - message(STATUS "Using amqp_codegen.py in ${RABBITMQ_CODEGEN_DIR}") - endif() - - set(AMQP_CODEGEN_DIR ${RABBITMQ_CODEGEN_DIR} CACHE PATH "Path to rabbitmq-codegen" FORCE) -endif (FETCH_CODEGEN_FROM_GIT) +if (RABBITMQ_CODEGEN_DIR STREQUAL "RABBITMQ_CODEGEN_DIR-NOTFOUND") + message(SEND_ERROR "Cannot find amqp_codegen.py, did you forget to:\n\ngit submodule init\ngit submodule update\n?") +else () + message(STATUS "Using amqp_codegen.py in ${RABBITMQ_CODEGEN_DIR}") +endif() +set(AMQP_CODEGEN_DIR ${RABBITMQ_CODEGEN_DIR} CACHE PATH "Path to rabbitmq-codegen" FORCE) 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_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}) +option(BUILD_TESTS "Build tests (run tests with make test)" ON) 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.") endif() add_subdirectory(librabbitmq) -add_subdirectory(examples) -if (POPT_FOUND) - add_subdirectory(tools) -endif (POPT_FOUND) +if (BUILD_EXAMPLES) + add_subdirectory(examples) +endif () +if (BUILD_TOOLS) + if (POPT_FOUND) + add_subdirectory(tools) + else () + message(WARNING "POpt library was not found. Tools will not be built") + endif () +endif () + +if (BUILD_TESTS) + enable_testing() + add_subdirectory(tests) +endif (BUILD_TESTS) + +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin) +set(libdir ${CMAKE_INSTALL_PREFIX}/lib) +set(includedir ${CMAKE_INSTALL_PREFIX}/include) + +configure_file(librabbitmq.pc.in ${CMAKE_CURRENT_BINARY_DIR}/librabbitmq.pc @ONLY) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/librabbitmq.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig + ) @@ -49,14 +49,14 @@ to build the `librabbitmq` library and the example programs. ### Using cmake -You will need CMake: http://cmake.org/ +You will need CMake (v2.6 or better): http://cmake.org/ -You will need a working python install in your path. +You will need a working python install (2.6+) with the json or simplejson +modules installed. -If you would like the build system to fetch the rabbitmq-codegen -automatically you will need to have a working git install in your -path. Otherwise you will need to checkout the rabbitmq-codegen as -stated above. +You will need to do the git submodule init/update as above. +Alternatively you can clone the rabbitmq-codegen repository and point +cmake to it using the RABBITMQ_CODEGEN_DIR cmake variable Create a binary directory in a sibling directory from the directory you cloned the rabbitmq-c repository @@ -78,13 +78,6 @@ Things you can pass to cmake to change the build: * `-DRABBITMQ_CODEGEN_DIR=/path/to/rabbitmq-codegen/checkout` - if you have your codegen directory in a different place [Default is sibiling directory to source] -* `-DFETCH_CODEGEN_FROM_GIT=ON` - if you want cmake to fetch the - rabbitmq-codegen from https://github.com/rabbitmq/rabbitmq-codegen - at build time. If this option is selected `-DRABBITMQ_CODEGEN_DIR` - will be ignored [Default is off] -* `-DCODEGEN_GIT_TAG=rabbitmq_v2_5_1` - specifies the tag to check out - if using the `-DFETCH_CODEGEN_FROM_GIT` option above. [Default is - `rabbitmq_v2_5_1`] * `-DBUILD_TOOLS=OFF` build the programs in the tools directory [Default is ON if the POPT library can be found] 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/examples/utils.c b/examples/utils.c index 871fc2a..b047c8d 100644 --- a/examples/utils.c +++ b/examples/utils.c @@ -133,7 +133,7 @@ void amqp_dump(void const *buffer, size_t len) { long count = 0; int numinrow = 0; int chs[16]; - int oldchs[16]; + int oldchs[16] = {0}; int showed_dots = 0; size_t i; diff --git a/librabbitmq/CMakeLists.txt b/librabbitmq/CMakeLists.txt index a369c0b..140c4b9 100644 --- a/librabbitmq/CMakeLists.txt +++ b/librabbitmq/CMakeLists.txt @@ -33,10 +33,10 @@ add_custom_command( VERBATIM) -SET(CONFIG_CONTENTS "#define VERSION \"0.2\" +SET(CONFIG_CONTENTS "#define VERSION \"${VERSION}\" #ifndef __cplusplus # define inline ${C_INLINE} -#endif // __cplusplus +#endif /* __cplusplus */ ") #prepare config.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..d3d683a --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,15 @@ +include_directories(${LIBRABBITMQ_INCLUDE_DIRS}) + +# Needed because no version of MSVC has inttypes.h +if (MSVC) + include_directories(${CMAKE_SOURCE_DIR}/librabbitmq/win32/msinttypes) +endif() + +add_executable(test_parse_url test_parse_url.c) +target_link_libraries(test_parse_url rabbitmq) +add_test(parse_url test_parse_url) + +add_executable(test_tables test_tables.c) +target_link_libraries(test_tables rabbitmq) +add_test(tables test_tables) +configure_file(test_tables.expected ${CMAKE_CURRENT_BINARY_DIR}/tests/test_tables.expected COPY_ONLY) diff --git a/tests/test_tables.c b/tests/test_tables.c index e4b0f43..659db53 100644 --- a/tests/test_tables.c +++ b/tests/test_tables.c @@ -446,7 +446,7 @@ int main(void) test_dump_value(out); if (srcdir == NULL) - srcdir = "tests"; + srcdir = "."; expected_path = malloc(strlen(srcdir) + strlen(expected_file_name) + 2); sprintf(expected_path, "%s/%s", srcdir, expected_file_name); diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index bdeddaf..cf7f4e2 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -32,3 +32,47 @@ 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 + ARCHIVE DESTINATION lib + PUBLIC_HEADER DESTINATION include) diff --git a/tools/common.c b/tools/common.c index 2c248b9..70f3bca 100644 --- a/tools/common.c +++ b/tools/common.c @@ -34,6 +34,8 @@ #include "config.h" #endif +/* needed for asnprintf */ +#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <stdarg.h> @@ -200,12 +202,13 @@ static void init_connection_info(struct amqp_connection_info *ci) "Parsing URL '%s'", amqp_url); if (amqp_server) { + char *colon; if (ci->host) die("both --server and --url options specify" " server host"); /* parse the server string into a hostname and a port */ - char *colon = strchr(amqp_server, ':'); + colon = strchr(amqp_server, ':'); if (colon) { char *port_end; size_t host_len; |