From 915f65cc739fb005bbb04302a5ed46949eb39698 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Sat, 20 Jan 2018 00:33:16 +0100 Subject: [PATCH 01/38] add examples directory --- examples/boost/Makefile | 23 +++++++ examples/boost/consumer.cpp | 114 ++++++++++++++++++++++++++++++++++ examples/boost/producer.cpp | 118 ++++++++++++++++++++++++++++++++++++ 3 files changed, 255 insertions(+) create mode 100644 examples/boost/Makefile create mode 100644 examples/boost/consumer.cpp create mode 100644 examples/boost/producer.cpp diff --git a/examples/boost/Makefile b/examples/boost/Makefile new file mode 100644 index 00000000..b3b28023 --- /dev/null +++ b/examples/boost/Makefile @@ -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} diff --git a/examples/boost/consumer.cpp b/examples/boost/consumer.cpp new file mode 100644 index 00000000..bb4c9743 --- /dev/null +++ b/examples/boost/consumer.cpp @@ -0,0 +1,114 @@ +/** + * LibBoostAsio.cpp + * + * Test program to check AMQP functionality based on Boost's asio io_service. + * + * @author Gavin Smith + * + * Compile with g++ -std=c++14 libboostasio.cpp -o boost_test -lpthread -lboost_system -lamqpcpp + */ + +/** + * Dependencies + */ + +#include // std::shared_ptr + +#include +#include +#include + + +#include +#include + + +// callback function that is called when the consume operation starts +auto startCb = [](const std::string &consumertag) { + + std::cout << "consume operation started" << std::endl; +}; + +// callback function that is called when the consume operation failed +auto errorCb = [](const char *message) { + + std::cout << "consume operation failed" << std::endl; +}; + + +void printRabbitMessage(const AMQP::Message &message) +{ + std::string message_str(message.body(), message.bodySize()); + std::cout << "[" << message.exchange() << "] : " << message_str << std::endl; + if (message.hasCorrelationID()) + std::cout << "Correlation ID: " << message.correlationID() << std::endl; + if (message.hasReplyTo()) + std::cout << "Replay to : " << message.replyTo() << std::endl; + + +} + +// callback operation when a message was received +auto messageCb = [](const AMQP::Message &message, uint64_t deliveryTag, bool redelivered) { + + printRabbitMessage(message); +}; + + +/** + * Main program + * @return int + */ +int dynamic_main() +{ + + // access to the boost asio handler + // note: we suggest use of 2 threads - normally one is fin (we are simply demonstrating thread safety). + boost::asio::io_service service(4); + + // create a work object to process our events. + boost::asio::io_service::work work(service); + + // handler for libev + AMQP::LibBoostAsioHandler handler(service); + + // make a connection + // + std::shared_ptr connection; + connection = std::make_shared(&handler, AMQP::Address("amqp://guest:guest@localhost/")); + std::cout << "Create connection to amqp://guest:guest@localhost/\n"; + + // we need a channel too + AMQP::TcpChannel channel(connection.get()); + std::cout << "Create channel\n"; + + channel.declareQueue("my_event_queue").onSuccess([&channel](const std::string& name, uint32_t messageCount, uint32_t consumerCount) { + + std::cout << "Queue '" << name << "' has been declared with " << messageCount << " messages and " << consumerCount << " consumers" << std::endl; + channel.bindQueue("EVENT_EXCHANGE", "my_event_queue", "event.am.*").onError([&name](const char* message){ + std::cout << "Binding " << name << " FAILED\n"; + std::cout << "Message: " << message << std::endl; + }).onSuccess([&channel](){ + + channel.consume("my_event_queue") + .onReceived(messageCb) + .onSuccess(startCb) + .onError(errorCb); + }); + + }); + + + // run the handler + // a t the moment, one will need SIGINT to stop. In time, should add signal handling through boost API. + std::cout << "Start example...\n"; + return service.run(); +} + + +int main() +{ + return dynamic_main(); + // return static_main(); + +} diff --git a/examples/boost/producer.cpp b/examples/boost/producer.cpp new file mode 100644 index 00000000..33f10868 --- /dev/null +++ b/examples/boost/producer.cpp @@ -0,0 +1,118 @@ +/** + * LibBoostAsio.cpp + * + * Test program to check AMQP functionality based on Boost's asio io_service. + * + * @author Alessandro Pischedda + * + * Compile with g++ -std=c++11 libboostasio.cpp -o boost_test -lpthread -lboost_system -lamqpcpp + */ + +#include +#include // std::shared_ptr + +#include +#include +#include +#include + +#include +#include + + +struct Options { + std::string exchange_name; + std::string exchange_type; + std::string queue_name; + std::string rabbit_server; +}; + + +void usage() +{ + std::cout << "Producer Help" ; +} + +bool handle_options(struct Options &opt, int argc, char* argv[]) +{ + char c; + + while((c=getopt(argc, argv, "n:t:q:s:h")) != -1) { + + switch(c) { + case 'n': + opt->exchange_name = std::string(optarg); + break; + + case 't': + opt->exchange_type = std::string(optarg); + break; + + case 's': + opt->rabbit_server = std::string(optarg); + break; + + case 'q': + opt->queue_name = std::string(optarg); + break; + + case 'h': usage(); + return false; + } // END SWITCH + } // END WHILE + + return true; +} + +void run(Options opt) +{ + + 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(opt.rabbit_server)); + + AMQP::TcpChannel channel(&connection); + + // create the queue + channel.declareQueue(queue_name).onSuccess([&connection](const std::string &name, uint32_t messagecount, uint32_t consumercount) { + + // report the name of the temporary queue + std::cout << "declared queue " << name << std::endl; + + channel.declareExchange(exchange_name).onError([](const char* message) + { + std::cout << "Error: " << message << std::endl; + }).onSuccess([&channel, &connection]() + { + std::string producer_message; + for(int i = 0; ; i++) + { + producer_message = "Message " + std::to_string(i); + channel.publish(exchange_name, "", producer_message); + } + }); + + }); + + // run the handler + // a t the moment, one will need SIGINT to stop. In time, should add signal handling through boost API. + std::cout << "Start producer...\n"; + service.run(); +} + + + +int main(int argc, char* argv[]) +{ + Options opt; + if (!handle_options(opt, argc, argv) + return -1; + run(opt); +} From 23475586c96369fa110e66b60b07816e1f2261a8 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Sat, 20 Jan 2018 10:02:27 +0100 Subject: [PATCH 02/38] add Hello world example like RabbitMQ tutorial --- examples/boost/1_hello_world/Makefile | 23 ++++++++ examples/boost/1_hello_world/consumer.cpp | 69 +++++++++++++++++++++++ examples/boost/1_hello_world/producer.cpp | 65 +++++++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 examples/boost/1_hello_world/Makefile create mode 100644 examples/boost/1_hello_world/consumer.cpp create mode 100644 examples/boost/1_hello_world/producer.cpp diff --git a/examples/boost/1_hello_world/Makefile b/examples/boost/1_hello_world/Makefile new file mode 100644 index 00000000..b3b28023 --- /dev/null +++ b/examples/boost/1_hello_world/Makefile @@ -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} diff --git a/examples/boost/1_hello_world/consumer.cpp b/examples/boost/1_hello_world/consumer.cpp new file mode 100644 index 00000000..01e056cf --- /dev/null +++ b/examples/boost/1_hello_world/consumer.cpp @@ -0,0 +1,69 @@ +/** + * consumer.cpp + * + * @author Alessandro Pischedda + * + * Compile with g++ -std=c++11 consumer.cpp -o consumer -lpthread -lboost_system -lamqpcpp + */ + +#include + +#include +#include +#include + +#include +#include + + +// 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; +} + + diff --git a/examples/boost/1_hello_world/producer.cpp b/examples/boost/1_hello_world/producer.cpp new file mode 100644 index 00000000..14e11668 --- /dev/null +++ b/examples/boost/1_hello_world/producer.cpp @@ -0,0 +1,65 @@ +/** + * producer.cpp + * + * @author Alessandro Pischedda + * + * Compile with g++ -std=c++11 producer.cpp -o producer -lpthread -lboost_system -lamqpcpp + */ + +#include + +#include +#include +#include + +#include +#include + +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( + [&connection, &service, &channel, &data](const std::string &name, uint32_t messagecount, uint32_t consumercount) + { + + channel.publish(data.exchange_name, data.routing_key, data.message); + std::cout << "[x] Sent " << data.message << std::endl; + + // close connection + connection.close(); + // stop io_service + service.stop(); + }); + std::cout << "Start producer...\n"; + service.run(); + + return 0; +} + From d7b1f3dd3a28de23c324977c0fea8d4ee95bef9e Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 11:50:58 +0100 Subject: [PATCH 03/38] add pkg file info --- amqp.pc.in | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 amqp.pc.in diff --git a/amqp.pc.in b/amqp.pc.in new file mode 100644 index 00000000..4d024f8a --- /dev/null +++ b/amqp.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: @PACKAGE_NAME@ +Description: AMQP-CPP is a C++ library for communicating with a RabbitMQ message broker +Version: @PACKAGE_VERSION@ +URL: @PACKAGE_URL@ + +Libs: -L${libdir} -lamqpcp +Cflags: -I${includedir} From d8a8e19ff37268446130d64cb873320a7039f031 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 12:18:49 +0100 Subject: [PATCH 04/38] update --- amqp.pc.in | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/amqp.pc.in b/amqp.pc.in index 4d024f8a..92604005 100644 --- a/amqp.pc.in +++ b/amqp.pc.in @@ -1,11 +1,10 @@ -prefix=@prefix@ -libdir=@libdir@ -includedir=@includedir@ +prefix=@DEST_DIR@ +libdir=${prefix}/lib +includedir=${prefix}/include -Name: @PACKAGE_NAME@ +Name: ${PROJECT_NAME} Description: AMQP-CPP is a C++ library for communicating with a RabbitMQ message broker Version: @PACKAGE_VERSION@ -URL: @PACKAGE_URL@ -Libs: -L${libdir} -lamqpcp +Libs: -L${libdir} @PRIVATE_LIBS@ Cflags: -I${includedir} From cce7cc6381470394236ed5ec2651a7fe9a381535 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 12:19:39 +0100 Subject: [PATCH 05/38] pc file template renamed --- amqp.pc.in => amqpcpp.pc.in | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename amqp.pc.in => amqpcpp.pc.in (100%) diff --git a/amqp.pc.in b/amqpcpp.pc.in similarity index 100% rename from amqp.pc.in rename to amqpcpp.pc.in From 00cab314944f5e66748ebf37cd0e1a129d3208d9 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 12:20:26 +0100 Subject: [PATCH 06/38] update CMake file --- CMakeLists.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c73267d..a3bbd9a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ project(amqpcpp) include(set_cxx_norm.cmake) set_cxx_norm (${CXX_NORM_CXX11}) + macro (add_sources) file (RELATIVE_PATH _relPath "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") foreach (_src ${ARGN}) @@ -38,6 +39,24 @@ else() ARCHIVE DESTINATION lib ) endif() + +# if UNIX build package file +if(UNIX) + set(DEST_DIR "${CMAKE_INSTALL_PREFIX}") + + include(FindPkgConfig QUIET) + if(PKG_CONFIG_FOUND) + foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS}) + set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}") + endforeach() + # Produce a pkg-config file for linking against the shared lib + configure_file("amqpcpp.pc.in" "amqpcpp.pc" @ONLY) + install(FILES "${CMAKE_CURRENT_BINARY_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") From 5e1deda33dcadcf65259fb305054174730db32f5 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 12:32:25 +0100 Subject: [PATCH 07/38] pc file moved in src --- amqpcpp.pc.in => src/amqpcpp.pc.in | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename amqpcpp.pc.in => src/amqpcpp.pc.in (100%) diff --git a/amqpcpp.pc.in b/src/amqpcpp.pc.in similarity index 100% rename from amqpcpp.pc.in rename to src/amqpcpp.pc.in From feecb3b8df227a0ecd0c36f9ff9752a2791e0507 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 12:32:41 +0100 Subject: [PATCH 08/38] pgk-config is required --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3bbd9a9..8796b5f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ endif() if(UNIX) set(DEST_DIR "${CMAKE_INSTALL_PREFIX}") - include(FindPkgConfig QUIET) + include(FindPkgConfig REQUIRED) if(PKG_CONFIG_FOUND) foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS}) set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}") From d7be08ca2f576587859071f4293ebb515ee3265a Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 12:35:08 +0100 Subject: [PATCH 09/38] retun to QUIET --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8796b5f3..a3bbd9a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ endif() if(UNIX) set(DEST_DIR "${CMAKE_INSTALL_PREFIX}") - include(FindPkgConfig REQUIRED) + include(FindPkgConfig QUIET) if(PKG_CONFIG_FOUND) foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS}) set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}") From 74ee2bb7d87c9ad2561dc37461a86644e180c31f Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 12:36:41 +0100 Subject: [PATCH 10/38] moved, again, to root dir --- amqpcpp.pc.in | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 amqpcpp.pc.in diff --git a/amqpcpp.pc.in b/amqpcpp.pc.in new file mode 100644 index 00000000..92604005 --- /dev/null +++ b/amqpcpp.pc.in @@ -0,0 +1,10 @@ +prefix=@DEST_DIR@ +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: ${PROJECT_NAME} +Description: AMQP-CPP is a C++ library for communicating with a RabbitMQ message broker +Version: @PACKAGE_VERSION@ + +Libs: -L${libdir} @PRIVATE_LIBS@ +Cflags: -I${includedir} From 459ff256998a99c623099110fb0132df01ea83b6 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 12:36:50 +0100 Subject: [PATCH 11/38] moved, again, to root dir --- src/amqpcpp.pc.in | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 src/amqpcpp.pc.in diff --git a/src/amqpcpp.pc.in b/src/amqpcpp.pc.in deleted file mode 100644 index 92604005..00000000 --- a/src/amqpcpp.pc.in +++ /dev/null @@ -1,10 +0,0 @@ -prefix=@DEST_DIR@ -libdir=${prefix}/lib -includedir=${prefix}/include - -Name: ${PROJECT_NAME} -Description: AMQP-CPP is a C++ library for communicating with a RabbitMQ message broker -Version: @PACKAGE_VERSION@ - -Libs: -L${libdir} @PRIVATE_LIBS@ -Cflags: -I${includedir} From 1069ae324d14346b2c4323f6fe3d572c57af2240 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 12:40:54 +0100 Subject: [PATCH 12/38] removed '@ONLY' from substution variable --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3bbd9a9..cc83180c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,7 @@ if(UNIX) set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}") endforeach() # Produce a pkg-config file for linking against the shared lib - configure_file("amqpcpp.pc.in" "amqpcpp.pc" @ONLY) + configure_file("amqpcpp.pc.in" "amqpcpp.pc") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/amqpcpp.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") endif() From 169fa0c1be3eae46791a5ebf27fbb63ff4209215 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 12:42:27 +0100 Subject: [PATCH 13/38] fix --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc83180c..4ed85698 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,7 @@ if(UNIX) endforeach() # Produce a pkg-config file for linking against the shared lib configure_file("amqpcpp.pc.in" "amqpcpp.pc") - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/amqpcpp.pc" + install(FILES "amqpcpp.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") endif() endif() From 22a27fc3f1a477f150265a930834bfb723771280 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 14:12:12 +0100 Subject: [PATCH 14/38] fix --- amqpcpp.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amqpcpp.pc.in b/amqpcpp.pc.in index 92604005..256ea22b 100644 --- a/amqpcpp.pc.in +++ b/amqpcpp.pc.in @@ -6,5 +6,5 @@ Name: ${PROJECT_NAME} Description: AMQP-CPP is a C++ library for communicating with a RabbitMQ message broker Version: @PACKAGE_VERSION@ -Libs: -L${libdir} @PRIVATE_LIBS@ +Libs: -L${libdir} -l${LIBRARY_NAME} Cflags: -I${includedir} From b871719a78aa341c666d44808f6bc7fd8c0ba234 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 14:13:02 +0100 Subject: [PATCH 15/38] fix for pkg-configuration --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ed85698..485ac5b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,9 +46,6 @@ if(UNIX) include(FindPkgConfig QUIET) if(PKG_CONFIG_FOUND) - foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS}) - set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}") - endforeach() # Produce a pkg-config file for linking against the shared lib configure_file("amqpcpp.pc.in" "amqpcpp.pc") install(FILES "amqpcpp.pc" From 069f3b4a5278fb5bf78c81789d3d167a855d8c79 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 14:55:15 +0100 Subject: [PATCH 16/38] fix --- amqpcpp.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amqpcpp.pc.in b/amqpcpp.pc.in index 256ea22b..c485782e 100644 --- a/amqpcpp.pc.in +++ b/amqpcpp.pc.in @@ -6,5 +6,5 @@ Name: ${PROJECT_NAME} Description: AMQP-CPP is a C++ library for communicating with a RabbitMQ message broker Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -l${LIBRARY_NAME} +Libs: -L${libdir} -l${PROJECT_NAME} Cflags: -I${includedir} From 2ef3a4b910f38adb5d25b09fd5c2fb6a5f8ff32a Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 15:22:01 +0100 Subject: [PATCH 17/38] fix --- amqpcpp.pc.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/amqpcpp.pc.in b/amqpcpp.pc.in index c485782e..a49f7842 100644 --- a/amqpcpp.pc.in +++ b/amqpcpp.pc.in @@ -1,10 +1,10 @@ prefix=@DEST_DIR@ -libdir=${prefix}/lib -includedir=${prefix}/include +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: @PACKAGE_VERSION@ -Libs: -L${libdir} -l${PROJECT_NAME} +Libs: -L${libdir} -l@PROJECT_NAME@ Cflags: -I${includedir} From afd2c5bc89fa2ef2ef45b99f6e22a88d88225bfc Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 16:42:31 +0100 Subject: [PATCH 18/38] trying to fix pkg --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 485ac5b9..5b6e9b8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,8 +47,8 @@ if(UNIX) include(FindPkgConfig QUIET) if(PKG_CONFIG_FOUND) # Produce a pkg-config file for linking against the shared lib - configure_file("amqpcpp.pc.in" "amqpcpp.pc") - install(FILES "amqpcpp.pc" + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/amqpcpp.pc.in" "${CMAKE_CURRENT_SOURCE_DIR}/amqpcpp.pc") + install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/amqpcpp.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") endif() endif() From 175949650eda44bc8086f4093e71fbd6969d484a Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 17:55:16 +0100 Subject: [PATCH 19/38] return old version of libboost --- include/libboostasio.h | 224 ++++++++++++++++++++--------------------- 1 file changed, 112 insertions(+), 112 deletions(-) diff --git a/include/libboostasio.h b/include/libboostasio.h index 3f80b89c..f0d4ed4e 100644 --- a/include/libboostasio.h +++ b/include/libboostasio.h @@ -26,12 +26,35 @@ #include #include -// C++17 has 'weak_from_this()' support. -#if __cplusplus >= 201701L -#define PTR_FROM_THIS weak_from_this -#else -#define PTR_FROM_THIS shared_from_this -#endif + +/////////////////////////////////////////////////////////////////// +#define STRAND_SOCKET_HANDLER(_fn) \ +[fn = _fn, strand = _strand](const boost::system::error_code &ec, \ + const std::size_t bytes_transferred) \ +{ \ + const std::shared_ptr apStrand = strand.lock(); \ + if (!apStrand) \ + { \ + fn(boost::system::errc::make_error_code(boost::system::errc::operation_canceled),std::size_t{0}); \ + return; \ + } \ + \ + apStrand->dispatch(boost::bind(fn,ec,bytes_transferred)); \ +} + +/////////////////////////////////////////////////////////////////// +#define STRAND_TIMER_HANDLER(_fn) \ +[fn = _fn, strand = _strand](const boost::system::error_code &ec) \ +{ \ + const std::shared_ptr apStrand = strand.lock(); \ + if (!apStrand) \ + { \ + fn(boost::system::errc::make_error_code(boost::system::errc::operation_canceled)); \ + return; \ + } \ + \ + apStrand->dispatch(boost::bind(fn,ec)); \ +} /** * Set up namespace @@ -97,64 +120,6 @@ class LibBoostAsioHandler : public virtual TcpHandler */ bool _write_pending{false}; - using handler_cb = boost::function; - using io_handler = boost::function; - - /** - * Builds a io handler callback that executes the io callback in a strand. - * @param io_handler The handler callback to dispatch - * @return handler_cb A function wrapping the execution of the handler function in a io_service::strand. - */ - handler_cb get_dispatch_wrapper(io_handler fn) - { - return [fn, strand = _strand](const boost::system::error_code &ec, const std::size_t bytes_transferred) - { - const std::shared_ptr apStrand = strand.lock(); - if (!apStrand) - { - fn(boost::system::errc::make_error_code(boost::system::errc::operation_canceled), std::size_t{0}); - return; - } - apStrand->dispatch(boost::bind(fn, ec, bytes_transferred)); - }; - } - - /** - * Binds and returns a read handler for the io operation. - * @param connection The connection being watched. - * @param fd The file descripter being watched. - * @return handler callback - */ - handler_cb get_read_handler(TcpConnection *const connection, const int fd) - { - auto fn = boost::bind(&Watcher::read_handler, - this, - _1, - _2, - PTR_FROM_THIS(), - connection, - fd); - return get_dispatch_wrapper(fn); - } - - /** - * Binds and returns a read handler for the io operation. - * @param connection The connection being watched. - * @param fd The file descripter being watched. - * @return handler callback - */ - handler_cb get_write_handler(TcpConnection *const connection, const int fd) - { - auto fn = boost::bind(&Watcher::write_handler, - this, - _1, - _2, - PTR_FROM_THIS(), - connection, - fd); - return get_dispatch_wrapper(fn); - } - /** * Handler method that is called by boost's io_service when the socket pumps a read event. * @param ec The status of the callback. @@ -182,10 +147,21 @@ class LibBoostAsioHandler : public virtual TcpHandler connection->process(fd, AMQP::readable); _read_pending = true; - - _socket.async_read_some( - boost::asio::null_buffers(), - get_read_handler(connection, fd)); + + _socket.async_read_some(boost::asio::null_buffers(), + STRAND_SOCKET_HANDLER( + boost::bind(&Watcher::read_handler, + this, + boost::arg<1>(), + boost::arg<2>(), +// C++17 has 'weak_from_this()' support. +#if __cplusplus >= 201701L + weak_from_this(), +#else + shared_from_this(), +#endif + connection, + fd))); } } @@ -217,9 +193,20 @@ class LibBoostAsioHandler : public virtual TcpHandler _write_pending = true; - _socket.async_write_some( - boost::asio::null_buffers(), - get_write_handler(connection, fd)); + _socket.async_write_some(boost::asio::null_buffers(), + STRAND_SOCKET_HANDLER( + boost::bind(&Watcher::write_handler, + this, + boost::arg<1>(), + boost::arg<2>(), +// C++17 has 'weak_from_this()' support. +#if __cplusplus >= 201701L + weak_from_this(), +#else + shared_from_this(), +#endif + connection, + fd))); } } @@ -275,9 +262,20 @@ class LibBoostAsioHandler : public virtual TcpHandler { _read_pending = true; - _socket.async_read_some( - boost::asio::null_buffers(), - get_read_handler(connection, fd)); + _socket.async_read_some(boost::asio::null_buffers(), + STRAND_SOCKET_HANDLER( + boost::bind(&Watcher::read_handler, + this, + boost::arg<1>(), + boost::arg<2>(), +// C++17 has 'weak_from_this()' support. +#if __cplusplus >= 201701L + weak_from_this(), +#else + shared_from_this(), +#endif + connection, + fd))); } // 2. Handle writes? @@ -288,9 +286,20 @@ class LibBoostAsioHandler : public virtual TcpHandler { _write_pending = true; - _socket.async_write_some( - boost::asio::null_buffers(), - get_write_handler(connection, fd)); + _socket.async_write_some(boost::asio::null_buffers(), + STRAND_SOCKET_HANDLER( + boost::bind(&Watcher::write_handler, + this, + boost::arg<1>(), + boost::arg<2>(), +// C++17 has 'weak_from_this()' support. +#if __cplusplus >= 201701L + weak_from_this(), +#else + shared_from_this(), +#endif + connection, + fd))); } } }; @@ -320,39 +329,11 @@ class LibBoostAsioHandler : public virtual TcpHandler */ boost::asio::deadline_timer _timer; - using handler_fn = boost::function; - /** - * Binds and returns a lamba function handler for the io operation. - * @param connection The connection being watched. - * @param timeout The file descripter being watched. - * @return handler callback - */ - handler_fn get_handler(TcpConnection *const connection, const uint16_t timeout) - { - auto fn = boost::bind(&Timer::timeout, - this, - _1, - PTR_FROM_THIS(), - connection, - timeout); - return [fn, strand = _strand](const boost::system::error_code &ec) - { - const std::shared_ptr apStrand = strand.lock(); - if (!apStrand) - { - fn(boost::system::errc::make_error_code(boost::system::errc::operation_canceled)); - return; - } - apStrand->dispatch(boost::bind(fn, ec)); - }; - } - /** * Callback method that is called by libev when the timer expires - * @param ec error code returned from loop * @param loop The loop in which the event was triggered - * @param connection - * @param timeout + * @param timer Internal timer object + * @param revents The events that triggered this call */ void timeout(const boost::system::error_code &ec, std::weak_ptr awpThis, @@ -376,7 +357,18 @@ class LibBoostAsioHandler : public virtual TcpHandler _timer.expires_at(_timer.expires_at() + boost::posix_time::seconds(timeout)); // Posts the timer event - _timer.async_wait(get_handler(connection, timeout)); + _timer.async_wait(STRAND_TIMER_HANDLER( + boost::bind(&Timer::timeout, + this, + boost::arg<1>(), +// C++17 has 'weak_from_this()' support. +#if __cplusplus >= 201701L + weak_from_this(), +#else + shared_from_this(), +#endif + connection, + timeout))); } } @@ -431,11 +423,19 @@ class LibBoostAsioHandler : public virtual TcpHandler // stop timer in case it was already set stop(); - // Reschedule the timer for the future: _timer.expires_from_now(boost::posix_time::seconds(timeout)); - - // Posts the timer event - _timer.async_wait(get_handler(connection, timeout)); + _timer.async_wait(STRAND_TIMER_HANDLER( + boost::bind(&Timer::timeout, + this, + boost::arg<1>(), +// C++17 has 'weak_from_this()' support. +#if __cplusplus >= 201701L + weak_from_this(), +#else + shared_from_this(), +#endif + connection, + timeout))); } }; From 76674aff43d9174256558bbbe9fac6757a1bcd45 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 21:55:02 +0100 Subject: [PATCH 20/38] fix package file --- amqpcpp.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amqpcpp.pc.in b/amqpcpp.pc.in index a49f7842..593fff95 100644 --- a/amqpcpp.pc.in +++ b/amqpcpp.pc.in @@ -6,5 +6,5 @@ Name: ${PROJECT_NAME} Description: AMQP-CPP is a C++ library for communicating with a RabbitMQ message broker Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -l@PROJECT_NAME@ +Libs: -l@PROJECT_NAME@ Cflags: -I${includedir} From 8602c5dc7a6dbe04e2779435585af0ec010c9567 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 22:28:02 +0100 Subject: [PATCH 21/38] use PROJECT_NAME variable --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b6e9b8a..9dbd514f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,14 +28,14 @@ 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 2.7) + 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() From 4135322fa15a74df9e2ce9abced450d63a924a43 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 22:29:40 +0100 Subject: [PATCH 22/38] add second example --- examples/boost/2_work_queues/.worker.cpp.swp | Bin 0 -> 12288 bytes examples/boost/2_work_queues/Makefile | 23 ++++++ examples/boost/2_work_queues/new_task.cpp | 68 ++++++++++++++++++ examples/boost/2_work_queues/worker.cpp | 71 +++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 examples/boost/2_work_queues/.worker.cpp.swp create mode 100644 examples/boost/2_work_queues/Makefile create mode 100644 examples/boost/2_work_queues/new_task.cpp create mode 100644 examples/boost/2_work_queues/worker.cpp diff --git a/examples/boost/2_work_queues/.worker.cpp.swp b/examples/boost/2_work_queues/.worker.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..335292c1b28a56bbac09b32005739d1ba9137d93 GIT binary patch literal 12288 zcmeI2O>Epm6vwArXo2!k5D2)uZl&Pe?AlF&C~VUz=_0jA4N99pDOI$1?djUY>v8RI zK8Qjk3LLl~4sZd)fe&$kTe%fc?%X+XLIQ~+969ixv7L1($&CYOEdAE@%$qlF{(fUC z${QSg@wo*$X3sDj_cIoc{Fj#&0yg^)V;)br8>x=HkNJpanH&45$T|zIcS?v=I}+Y) zLtif(Iw?;?=FBggTkP}}7ahLgjuN z0(&Ts%gddo53-r*siVs3NaHX)c<6;a2AD3RfKk9GU=%P47zK<1MggOMQQ-fkfK2wW zt60<><-$&v=Y4-Wm$&9*6fg=H1&jhl0i%FXz$jo8FbWt2i~>dhqriVq0oTX>`R`=x z!~F;z|NpQ4{{Qnn#(o38f-k_Q;56ugQ@{otupj(#FJs?=8{kXuHh2rX39f+wcm+HU zTHpZq`5^4UH{d$>9DD}e02jeA@ECX${BaLszk~0n1Rel4p~u(YEAR>U7<>ejPVWJ87zK<1 zMggOMQNSqhFDbCi2uI3gp2l?aIKK2aGM=u59=FpxwwlL_Ch2#(p2#K5&Qjx2YlSYj zp$y|8T^1>gRCVHzXErSh;v1o)Bt;YTmd~G^>^0PwOgZ4OAC+@#H;q2dMkaU}(7Q7V2fFTe>`>o!yDmI+yP@cp!@FHo3ryS2Rr0?!($6H8ig#nGsRm6TdcpzH=z_d z10F@9Zc*kBdes4oGs=Q4h&1vK*A2&SmC~?s#nkivR!s literal 0 HcmV?d00001 diff --git a/examples/boost/2_work_queues/Makefile b/examples/boost/2_work_queues/Makefile new file mode 100644 index 00000000..7b78996a --- /dev/null +++ b/examples/boost/2_work_queues/Makefile @@ -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 *.cpOBJECTS +OBJECTS = new_task.o worker.o +all: \ + new_task \ + worker + + +new_task: ${OBJECTS} + ${LD} -o $@ new_task.o ${LDFLAGS} + +worker: ${OBJECTS} + ${LD} -o $@ worker.o ${LDFLAGS} + + +clean: + ${RM} *.obj *~* ${OBJECTS} ${RESULT} + +${OBJECTS}: + ${CPP} ${CPPFLAGS} -o $@ ${@:%.o=%.cpp} diff --git a/examples/boost/2_work_queues/new_task.cpp b/examples/boost/2_work_queues/new_task.cpp new file mode 100644 index 00000000..0405261e --- /dev/null +++ b/examples/boost/2_work_queues/new_task.cpp @@ -0,0 +1,68 @@ +/** + * producer.cpp + * + * @author Alessandro Pischedda + * + * Compile with g++ -std=c++11 new_task.cpp -o new_task -lpthread -lboost_system -lamqpcpp + */ + +#include + +#include +#include +#include + +#include +#include + +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 = "task_queue"; + data.message = "Hello World!"; + data.routing_key = "hello"; + data.exchange_name = ""; + + if (argc == 2) + data.message = argv[1]; + + 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, AMQP::durable).onSuccess( + [&connection, &service, &channel, &data](const std::string &name, uint32_t messagecount, uint32_t consumercount) + { + + channel.publish(data.exchange_name, data.routing_key, data.message); + std::cout << "[x] Sent " << data.message << std::endl; + + // close connection + connection.close(); + // stop io_service + service.stop(); + }); + std::cout << "Start producer...\n"; + service.run(); + + return 0; +} + diff --git a/examples/boost/2_work_queues/worker.cpp b/examples/boost/2_work_queues/worker.cpp new file mode 100644 index 00000000..fa0b7285 --- /dev/null +++ b/examples/boost/2_work_queues/worker.cpp @@ -0,0 +1,71 @@ +/** + * consumer.cpp + * + * @author Alessandro Pischedda + * + * Compile with g++ -std=c++11 consumer.cpp -o consumer -lpthread -lboost_system -lamqpcpp + */ + +#include + +#include +#include +#include + +#include +#include + + + +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.setQos(1); + // callback operation when a message was received + auto messageCb = [&channel](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; + channel.ack(); + }; + + channel.consume(data.queue_name).onReceived(messageCb); + }); + + std::cout << "[*] Waiting for messages. To exit press CTRL+C" << std::endl; + service.run(); + + return 0; +} + + From 403c17b5907e4bda77373d95e2472244df28f296 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Mon, 29 Jan 2018 22:29:53 +0100 Subject: [PATCH 23/38] remove swap file --- examples/boost/2_work_queues/.worker.cpp.swp | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 examples/boost/2_work_queues/.worker.cpp.swp diff --git a/examples/boost/2_work_queues/.worker.cpp.swp b/examples/boost/2_work_queues/.worker.cpp.swp deleted file mode 100644 index 335292c1b28a56bbac09b32005739d1ba9137d93..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2O>Epm6vwArXo2!k5D2)uZl&Pe?AlF&C~VUz=_0jA4N99pDOI$1?djUY>v8RI zK8Qjk3LLl~4sZd)fe&$kTe%fc?%X+XLIQ~+969ixv7L1($&CYOEdAE@%$qlF{(fUC z${QSg@wo*$X3sDj_cIoc{Fj#&0yg^)V;)br8>x=HkNJpanH&45$T|zIcS?v=I}+Y) zLtif(Iw?;?=FBggTkP}}7ahLgjuN z0(&Ts%gddo53-r*siVs3NaHX)c<6;a2AD3RfKk9GU=%P47zK<1MggOMQQ-fkfK2wW zt60<><-$&v=Y4-Wm$&9*6fg=H1&jhl0i%FXz$jo8FbWt2i~>dhqriVq0oTX>`R`=x z!~F;z|NpQ4{{Qnn#(o38f-k_Q;56ugQ@{otupj(#FJs?=8{kXuHh2rX39f+wcm+HU zTHpZq`5^4UH{d$>9DD}e02jeA@ECX${BaLszk~0n1Rel4p~u(YEAR>U7<>ejPVWJ87zK<1 zMggOMQNSqhFDbCi2uI3gp2l?aIKK2aGM=u59=FpxwwlL_Ch2#(p2#K5&Qjx2YlSYj zp$y|8T^1>gRCVHzXErSh;v1o)Bt;YTmd~G^>^0PwOgZ4OAC+@#H;q2dMkaU}(7Q7V2fFTe>`>o!yDmI+yP@cp!@FHo3ryS2Rr0?!($6H8ig#nGsRm6TdcpzH=z_d z10F@9Zc*kBdes4oGs=Q4h&1vK*A2&SmC~?s#nkivR!s From 48bf5ef3da59bb4152eaa043589798add89e1f64 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 10:48:35 +0100 Subject: [PATCH 24/38] use tag version --- CMakeLists.txt | 12 ++++++++++++ Makefile => Makefile.in | 4 ++-- amqpcpp.pc.in | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) rename Makefile => Makefile.in (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b6e9b8a..69036d10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,17 @@ cmake_minimum_required(VERSION 2.8) +# get version automatically using last tag +include(GetGitRevisionDescription) +git_describe(VERSION --tags --dirty=-d) + +#parse the version information into pieces. +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}") + project(amqpcpp) # ensure c++11 on all compilers diff --git a/Makefile b/Makefile.in similarity index 92% rename from Makefile rename to Makefile.in index 9f1fe759..85035da7 100644 --- a/Makefile +++ b/Makefile.in @@ -2,8 +2,8 @@ PREFIX ?= /usr INCLUDE_DIR = ${PREFIX}/include LIBRARY_DIR = ${PREFIX}/lib export LIBRARY_NAME = amqpcpp -export SONAME = 2.8 -export VERSION = 2.8.0 +export SONAME = ${VERSION_SONAME} +export VERSION = ${VERSION_SHORT} all: $(MAKE) -C src all diff --git a/amqpcpp.pc.in b/amqpcpp.pc.in index a49f7842..4425a270 100644 --- a/amqpcpp.pc.in +++ b/amqpcpp.pc.in @@ -4,7 +4,7 @@ includedir=@DEST_DIR@/include Name: ${PROJECT_NAME} Description: AMQP-CPP is a C++ library for communicating with a RabbitMQ message broker -Version: @PACKAGE_VERSION@ +Version: @VERSION_SHORT@ -Libs: -L${libdir} -l@PROJECT_NAME@ +Libs: -l${PROJECT_NAME} Cflags: -I${includedir} From 0e7534947c70e77d69c77746b1f2348cebe86809 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 10:49:42 +0100 Subject: [PATCH 25/38] use anothe variable --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 85035da7..7739317a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,7 +1,7 @@ PREFIX ?= /usr INCLUDE_DIR = ${PREFIX}/include LIBRARY_DIR = ${PREFIX}/lib -export LIBRARY_NAME = amqpcpp +export LIBRARY_NAME = ${PROJECT_NAME} export SONAME = ${VERSION_SONAME} export VERSION = ${VERSION_SHORT} From d6d203255f31ec07a619e7a817c6dc0d1e22e37f Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 10:53:35 +0100 Subject: [PATCH 26/38] generate Makefile using variable --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69036d10..548e651f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,9 @@ include(set_cxx_norm.cmake) set_cxx_norm (${CXX_NORM_CXX11}) +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}) @@ -41,7 +44,7 @@ option(BUILD_SHARED "build shared library" OFF) if(BUILD_SHARED) add_library(amqpcpp SHARED ${SRCS}) - set_target_properties(amqpcpp PROPERTIES SOVERSION 2.7) + set_target_properties(amqpcpp PROPERTIES SOVERSION ${VERSION_SONAME}) install(TARGETS amqpcpp LIBRARY DESTINATION lib ) From e5782442c2cec993ba716ba0354deb001df53169 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 10:57:16 +0100 Subject: [PATCH 27/38] add utility --- GetGitRevisionDescription.cmake | 168 ++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 GetGitRevisionDescription.cmake diff --git a/GetGitRevisionDescription.cmake b/GetGitRevisionDescription.cmake new file mode 100644 index 00000000..8ab03bc5 --- /dev/null +++ b/GetGitRevisionDescription.cmake @@ -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( [ ...]) +# +# Returns the refspec and sha hash of the current head revision +# +# 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( [ ...]) +# +# 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() +# +# 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 +# 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() From 80d8dac1cb9b5ac037ec7cb7f1616ae3ad21f6df Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 11:01:03 +0100 Subject: [PATCH 28/38] fix inclusion --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 548e651f..addbb7e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.8) # get version automatically using last tag -include(GetGitRevisionDescription) +include(GetGitRevisionDescription.cmake) git_describe(VERSION --tags --dirty=-d) #parse the version information into pieces. @@ -19,6 +19,8 @@ include(set_cxx_norm.cmake) set_cxx_norm (${CXX_NORM_CXX11}) + + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Makefile.in" "${CMAKE_CURRENT_SOURCE_DIR}/Makefile") From 42a4ad9614d1fccd92adf10e43d0f7da65f6ef0f Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 11:15:20 +0100 Subject: [PATCH 29/38] fixes --- CMakeLists.txt | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index addbb7e1..0bf5e449 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,28 +1,22 @@ cmake_minimum_required(VERSION 2.8) -# get version automatically using last tag -include(GetGitRevisionDescription.cmake) -git_describe(VERSION --tags --dirty=-d) - -#parse the version information into pieces. -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}") - project(amqpcpp) # ensure c++11 on all compilers include(set_cxx_norm.cmake) set_cxx_norm (${CXX_NORM_CXX11}) - - - -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Makefile.in" "${CMAKE_CURRENT_SOURCE_DIR}/Makefile") - +include(GetGitRevisionDescription.cmake) +git_describe(GIT_REVISION_DESCRIPTION --tags --match v*) +if(GIT_REVISION_DESCRIPTION) + string(REPLACE "v" "" + GIT_REVISION_DESCRIPTION + "${GIT_REVISION_DESCRIPTION}") + #set(CPACK_PACKAGE_VERSION "${GIT_REVISION_DESCRIPTION}") + message(STATUS "Git reports version ${GIT_REVISION_DESCRIPTION}") +else() + message(STATUS "Could not get revision information from Git! Calling this just version ${CPACK_PACKAGE_VERSION}!") +endif() macro (add_sources) file (RELATIVE_PATH _relPath "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") @@ -46,7 +40,7 @@ option(BUILD_SHARED "build shared library" OFF) if(BUILD_SHARED) add_library(amqpcpp SHARED ${SRCS}) - set_target_properties(amqpcpp PROPERTIES SOVERSION ${VERSION_SONAME}) + set_target_properties(amqpcpp PROPERTIES SOVERSION 2.7) install(TARGETS amqpcpp LIBRARY DESTINATION lib ) From 72691ebd6f0870bfa684463fc89e0fbe9512b4c5 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 11:17:27 +0100 Subject: [PATCH 30/38] fixes --- GetGitRevisionDescription.cmake.in | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 GetGitRevisionDescription.cmake.in diff --git a/GetGitRevisionDescription.cmake.in b/GetGitRevisionDescription.cmake.in new file mode 100644 index 00000000..6d8b708e --- /dev/null +++ b/GetGitRevisionDescription.cmake.in @@ -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 +# 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() From e7da90b90b30181d7b889e2a617e241c3138a0d1 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 11:22:12 +0100 Subject: [PATCH 31/38] fixes --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bf5e449..8d34e4eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,12 +12,15 @@ if(GIT_REVISION_DESCRIPTION) string(REPLACE "v" "" GIT_REVISION_DESCRIPTION "${GIT_REVISION_DESCRIPTION}") - #set(CPACK_PACKAGE_VERSION "${GIT_REVISION_DESCRIPTION}") + set(VERSION_SHORT "${GIT_REVISION_DESCRIPTION}") message(STATUS "Git reports version ${GIT_REVISION_DESCRIPTION}") else() message(STATUS "Could not get revision information from Git! Calling this just version ${CPACK_PACKAGE_VERSION}!") endif() +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}) From 3f163308083afac2f99dcc57ec1a0d8b4c7326e1 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 11:27:33 +0100 Subject: [PATCH 32/38] use version variables --- CMakeLists.txt | 19 +++++++++---------- Makefile.in | 6 +++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d34e4eb..bfdc8737 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,16 +7,15 @@ include(set_cxx_norm.cmake) set_cxx_norm (${CXX_NORM_CXX11}) include(GetGitRevisionDescription.cmake) -git_describe(GIT_REVISION_DESCRIPTION --tags --match v*) -if(GIT_REVISION_DESCRIPTION) - string(REPLACE "v" "" - GIT_REVISION_DESCRIPTION - "${GIT_REVISION_DESCRIPTION}") - set(VERSION_SHORT "${GIT_REVISION_DESCRIPTION}") - message(STATUS "Git reports version ${GIT_REVISION_DESCRIPTION}") -else() - message(STATUS "Could not get revision information from Git! Calling this just version ${CPACK_PACKAGE_VERSION}!") -endif() +git_describe(VERSION --tags --dirty=-dirty) + +#parse the version information into pieces. +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") diff --git a/Makefile.in b/Makefile.in index 7739317a..c11a7181 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,9 +1,9 @@ PREFIX ?= /usr INCLUDE_DIR = ${PREFIX}/include LIBRARY_DIR = ${PREFIX}/lib -export LIBRARY_NAME = ${PROJECT_NAME} -export SONAME = ${VERSION_SONAME} -export VERSION = ${VERSION_SHORT} +export LIBRARY_NAME = ${PROJECT_NAME} +export SONAME = ${VERSION_SONAME} +export VERSION = ${VERSION_SHORT} all: $(MAKE) -C src all From c6a17f7e1607068267f0d65b766ab93047446bf1 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 12:42:28 +0100 Subject: [PATCH 33/38] fix .pc --- amqpcpp.pc.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/amqpcpp.pc.in b/amqpcpp.pc.in index 4425a270..91e9d34a 100644 --- a/amqpcpp.pc.in +++ b/amqpcpp.pc.in @@ -2,9 +2,9 @@ prefix=@DEST_DIR@ libdir=@DEST_DIR@/lib includedir=@DEST_DIR@/include -Name: ${PROJECT_NAME} +Name: @PROJECT_NAME@ Description: AMQP-CPP is a C++ library for communicating with a RabbitMQ message broker Version: @VERSION_SHORT@ -Libs: -l${PROJECT_NAME} +Libs: -L${libdir} -l@PROJECT_NAME@ Cflags: -I${includedir} From 81f3020e65a1b9933dcb4260dcfc86c6ddf60314 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 12:52:43 +0100 Subject: [PATCH 34/38] use '@only' --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bfdc8737..1a1eb503 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ option(BUILD_SHARED "build shared library" OFF) if(BUILD_SHARED) add_library(amqpcpp SHARED ${SRCS}) - set_target_properties(amqpcpp PROPERTIES SOVERSION 2.7) + set_target_properties(amqpcpp PROPERTIES SOVERSION ${VERSION_SONAME}) install(TARGETS amqpcpp LIBRARY DESTINATION lib ) @@ -60,7 +60,7 @@ if(UNIX) 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") + 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() From 7c0425b2f69758278b0070ea4d0a2e7d68a0acd7 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 13:01:25 +0100 Subject: [PATCH 35/38] fix --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a1eb503..2d7e40c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,10 +6,13 @@ 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 --dirty=-dirty) +git_describe(VERSION --tags --dirty=-d) -#parse the version information into pieces. +# 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}") From 02c0fb91d9c24dab25a4519a4cd3847498117fd9 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 14:09:24 +0100 Subject: [PATCH 36/38] fix --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d7e40c2..60f8931d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ set_cxx_norm (${CXX_NORM_CXX11}) # get version from TAG on git include(GetGitRevisionDescription.cmake) -git_describe(VERSION --tags --dirty=-d) +git_describe(VERSION --tags) # parse the version information into pieces. # http://ipenguin.ws/2012/11/cmake-automatically-use-git-tags-as.html From e33eaf94fe94ed0e3f6bc1dba9027deb11529d35 Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 14:12:57 +0100 Subject: [PATCH 37/38] VERSION variable changed in GIT_TAG_VERSION --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 60f8931d..b6866131 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,14 +9,14 @@ set_cxx_norm (${CXX_NORM_CXX11}) # get version from TAG on git include(GetGitRevisionDescription.cmake) -git_describe(VERSION --tags) +git_describe(GIT_TAG_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}") +string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_TAG_VERSION}") +string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_TAG_VERSION}") +string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_TAG_VERSION}") +string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" VERSION_SHA1 "${GIT_TAG_VERSION}") set(VERSION_SHORT "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") set(VERSION_SONAME "${VERSION_MAJOR}.${VERSION_MINOR}") From 130fc9cc8a5f86219988984e58cd06997fb4f89e Mon Sep 17 00:00:00 2001 From: Alessandro Pischedda Date: Tue, 30 Jan 2018 14:14:08 +0100 Subject: [PATCH 38/38] revert previous commit --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b6866131..60f8931d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,14 +9,14 @@ set_cxx_norm (${CXX_NORM_CXX11}) # get version from TAG on git include(GetGitRevisionDescription.cmake) -git_describe(GIT_TAG_VERSION --tags) +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 "${GIT_TAG_VERSION}") -string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_TAG_VERSION}") -string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_TAG_VERSION}") -string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" VERSION_SHA1 "${GIT_TAG_VERSION}") +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}")