Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Examples (2) and package file info #170

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
915f65c
add examples directory
Cereal84 Jan 19, 2018
2347558
add Hello world example like RabbitMQ tutorial
Cereal84 Jan 20, 2018
d7b1f3d
add pkg file info
Jan 29, 2018
f27d50c
Merge https://github.com/CopernicaMarketingSoftware/AMQP-CPP
Jan 29, 2018
820dfba
Merge branch 'master' into add_pkg_infos
Jan 29, 2018
d8a8e19
update
Jan 29, 2018
cce7cc6
pc file template renamed
Jan 29, 2018
00cab31
update CMake file
Jan 29, 2018
5e1deda
pc file moved in src
Jan 29, 2018
feecb3b
pgk-config is required
Jan 29, 2018
d7be08c
retun to QUIET
Jan 29, 2018
74ee2bb
moved, again, to root dir
Jan 29, 2018
459ff25
moved, again, to root dir
Jan 29, 2018
1069ae3
removed '@ONLY' from substution variable
Jan 29, 2018
169fa0c
fix
Jan 29, 2018
22a27fc
fix
Jan 29, 2018
b871719
fix for pkg-configuration
Jan 29, 2018
069f3b4
fix
Jan 29, 2018
2ef3a4b
fix
Jan 29, 2018
afd2c5b
trying to fix pkg
Jan 29, 2018
1759496
return old version of libboost
Jan 29, 2018
76674af
fix package file
Cereal84 Jan 29, 2018
8602c5d
use PROJECT_NAME variable
Cereal84 Jan 29, 2018
4135322
add second example
Cereal84 Jan 29, 2018
403c17b
remove swap file
Cereal84 Jan 29, 2018
48bf5ef
use tag version
Jan 30, 2018
0e75349
use anothe variable
Jan 30, 2018
d6d2032
generate Makefile using variable
Jan 30, 2018
e578244
add utility
Jan 30, 2018
80d8dac
fix inclusion
Jan 30, 2018
42a4ad9
fixes
Jan 30, 2018
72691eb
fixes
Jan 30, 2018
e7da90b
fixes
Jan 30, 2018
3f16330
use version variables
Jan 30, 2018
c6a17f7
fix .pc
Jan 30, 2018
81f3020
use '@only'
Jan 30, 2018
7c0425b
fix
Jan 30, 2018
02c0fb9
fix
Jan 30, 2018
e33eaf9
VERSION variable changed in GIT_TAG_VERSION
Jan 30, 2018
130fc9c
revert previous commit
Jan 30, 2018
b9ecf4f
Merge branch 'master' of https://github.com/Cereal84/AMQP-CPP
Jan 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 37 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ project(amqpcpp)
include(set_cxx_norm.cmake)
set_cxx_norm (${CXX_NORM_CXX11})


# get version from TAG on git
include(GetGitRevisionDescription.cmake)
git_describe(VERSION --tags)

# parse the version information into pieces.
# http://ipenguin.ws/2012/11/cmake-automatically-use-git-tags-as.html
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" VERSION_SHA1 "${VERSION}")
set(VERSION_SHORT "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(VERSION_SONAME "${VERSION_MAJOR}.${VERSION_MINOR}")

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Makefile.in" "${CMAKE_CURRENT_SOURCE_DIR}/Makefile")


macro (add_sources)
file (RELATIVE_PATH _relPath "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
foreach (_src ${ARGN})
Expand All @@ -27,17 +44,32 @@ add_subdirectory(include)
option(BUILD_SHARED "build shared library" OFF)

if(BUILD_SHARED)
add_library(amqpcpp SHARED ${SRCS})
set_target_properties(amqpcpp PROPERTIES SOVERSION 2.7)
install(TARGETS amqpcpp
add_library(${PROJECT_NAME} SHARED ${SRCS})
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_SONAME})
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib
)
else()
add_library(amqpcpp STATIC ${SRCS})
install(TARGETS amqpcpp
add_library(${PROJECT_NAME} STATIC ${SRCS})
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
)
endif()

# if UNIX build package file
if(UNIX)
set(DEST_DIR "${CMAKE_INSTALL_PREFIX}")

include(FindPkgConfig QUIET)
if(PKG_CONFIG_FOUND)
# Produce a pkg-config file for linking against the shared lib
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/amqpcpp.pc.in" "${CMAKE_CURRENT_SOURCE_DIR}/amqpcpp.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/amqpcpp.pc"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
endif()
endif()


Include_directories(${PROJECT_SOURCE_DIR})
install(DIRECTORY include/ DESTINATION include/amqpcpp
FILES_MATCHING PATTERN "*.h")
Expand Down
168 changes: 168 additions & 0 deletions GetGitRevisionDescription.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# git_local_changes(<var>)
#
# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
# Uses the return code of "git diff-index --quiet HEAD --".
# Does not regard untracked files.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)

# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)

function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
endwhile()
# check if this is a submodule
if(NOT IS_DIRECTORY ${GIT_DIR})
file(READ ${GIT_DIR} submodule)
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()

if(NOT EXISTS "${GIT_DIR}/HEAD")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)

configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
@ONLY)
include("${GIT_DATA}/grabRef.cmake")

set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()

function(git_describe _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()

# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()

#message(STATUS "Arguments to execute_process: ${ARGN}")

execute_process(COMMAND
"${GIT_EXECUTABLE}"
describe
${hash}
${ARGN}
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()

set(${_var} "${out}" PARENT_SCOPE)
endfunction()

function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()

function(git_local_changes _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()

execute_process(COMMAND
"${GIT_EXECUTABLE}"
diff-index --quiet HEAD --
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(res EQUAL 0)
set(${_var} "CLEAN" PARENT_SCOPE)
else()
set(${_var} "DIRTY" PARENT_SCOPE)
endif()
endfunction()
41 changes: 41 additions & 0 deletions GetGitRevisionDescription.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

set(HEAD_HASH)

file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)

string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
else()
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
set(HEAD_HASH "${CMAKE_MATCH_1}")
endif()
endif()
else()
# detached HEAD
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()

if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()
6 changes: 3 additions & 3 deletions Makefile → Makefile.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PREFIX ?= /usr
INCLUDE_DIR = ${PREFIX}/include
LIBRARY_DIR = ${PREFIX}/lib
export LIBRARY_NAME = amqpcpp
export SONAME = 2.8
export VERSION = 2.8.0
export LIBRARY_NAME = ${PROJECT_NAME}
export SONAME = ${VERSION_SONAME}
export VERSION = ${VERSION_SHORT}

all:
$(MAKE) -C src all
Expand Down
10 changes: 10 additions & 0 deletions amqpcpp.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=@DEST_DIR@
libdir=@DEST_DIR@/lib
includedir=@DEST_DIR@/include

Name: @PROJECT_NAME@
Description: AMQP-CPP is a C++ library for communicating with a RabbitMQ message broker
Version: @VERSION_SHORT@

Libs: -l@PROJECT_NAME@
Cflags: -I${includedir}
23 changes: 23 additions & 0 deletions examples/boost/1_hello_world/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CPP = g++
CPPFLAGS = -Wall -c -I. -O2 -flto -std=c++11 -g
LD = g++
LDFLAGS = -lpthread -lboost_system -lamqpcpp
SOURCES = $(wildcard *.cpp)
OBJECTS = producer.o consumer.o

all: producer \
consumer


producer: ${OBJECTS}
${LD} -o $@ producer.o ${LDFLAGS}

consumer: ${OBJECTS}
${LD} -o $@ consumer.o ${LDFLAGS}


clean:
${RM} *.obj *~* ${OBJECTS} ${RESULT}

${OBJECTS}:
${CPP} ${CPPFLAGS} -o $@ ${@:%.o=%.cpp}
69 changes: 69 additions & 0 deletions examples/boost/1_hello_world/consumer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* consumer.cpp
*
* @author Alessandro Pischedda <alessandro.pischedda@gmail.com>
*
* Compile with g++ -std=c++11 consumer.cpp -o consumer -lpthread -lboost_system -lamqpcpp
*/

#include <unistd.h>

#include <boost/asio/io_service.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/deadline_timer.hpp>

#include <amqpcpp.h>
#include <amqpcpp/libboostasio.h>


// callback operation when a message was received
auto messageCb = [](const AMQP::Message &message, uint64_t deliveryTag, bool redelivered) {

std::string message_str(message.body(), message.bodySize());
std::cout << "[x] Received '" << message_str << "'" << std::endl;
};


int main(int argc, char* argv[])
{
struct Data {
std::string queue_name;
std::string message;
std::string routing_key;
std::string exchange_name;
};

Data data;

data.queue_name = "hello";
data.message = "Hello World!";
data.routing_key = "hello";
data.exchange_name = "";

boost::asio::io_service service;

// create a work object to process our events.
boost::asio::io_service::work work(service);

// handler for libboost
AMQP::LibBoostAsioHandler handler(service);

// make a connection
AMQP::TcpConnection connection(&handler, AMQP::Address("amqp://guest:guest@localhost/"));

AMQP::TcpChannel channel(&connection);

// create the queue
channel.declareQueue(data.queue_name).onSuccess(
[&channel, &data](const std::string &name, uint32_t messagecount, uint32_t consumercount)
{
channel.consume(data.queue_name).onReceived(messageCb);
});

std::cout << "[*] Waiting for messages. To exit press CTRL+C" << std::endl;
service.run();

return 0;
}